Exemplo n.º 1
0
 public bool SendUDPPacket(Mule.Network.Packet packet, Mule.ED2K.ED2KServer host, bool delpacket, ushort nSpecialPort, byte[] pRawPacket, uint nLen)
 {
     if (MuleApplication.Instance.IsConnected)
     {
         if (udpsocket_ != null)
         {
             udpsocket_.SendPacket(packet, host, nSpecialPort, pRawPacket, nLen);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        public void ConnectToServer(Mule.ED2K.ED2KServer toconnect, bool multiconnect, bool bNoCrypt)
        {
            if (!multiconnect)
            {
                StopConnectionTry();
                Disconnect();
            }
            IsConnecting    = true;
            IsSingleConnect = !multiconnect;

            ServerSocket newsocket =
                MuleApplication.Instance.NetworkObjectManager.CreateServerSocket(this, !multiconnect);

            openSockets_.Add(newsocket);
            newsocket.ConnectTo(toconnect, bNoCrypt);
            connectionAttemps_[MpdUtilities.GetTickCount()] = newsocket;
        }
Exemplo n.º 3
0
        public void SendPacket(Packet packet,
                               Mule.ED2K.ED2KServer pServer,
                               ushort nSpecialPort, byte[] pInRawPacket, uint nRawLen)
        {
            // Create raw UDP packet
            byte[] pRawPacket;
            uint   uRawPacketSize;
            ushort nPort = 0;

            if (packet != null)
            {
                pRawPacket = new byte[packet.Size + 2];
                Array.Copy(packet.UDPHeader, pRawPacket, 2);
                Array.Copy(packet.Buffer, 0, pRawPacket, 2, packet.Size);
                uRawPacketSize = packet.Size + 2;
                if (MuleApplication.Instance.Preference.IsServerCryptLayerUDPEnabled &&
                    pServer.ServerKeyUDP != 0 &&
                    pServer.DoesSupportsObfuscationUDP)
                {
                    uRawPacketSize = (uint)EncryptSendServer(ref pRawPacket, (int)uRawPacketSize, pServer.ServerKeyUDP);
                    nPort          = pServer.ObfuscationPortUDP;
                }
                else
                {
                    nPort = (ushort)(pServer.Port + 4);
                }
            }
            else if (pInRawPacket != null)
            {
                // we don't encrypt rawpackets (!)
                pRawPacket = new byte[nRawLen];
                Array.Copy(pInRawPacket, pRawPacket, nRawLen);
                uRawPacketSize = nRawLen;
                nPort          = (ushort)(pServer.Port + 4);
            }
            else
            {
                Debug.Assert(false);
                return;
            }
            nPort = (nSpecialPort == 0) ? nPort : nSpecialPort;
            Debug.Assert(nPort != 0);

            // Do we need to resolve the DN of this server?
            IPAddress ipAddr = IPAddress.None;

            IPAddress.TryParse(pServer.Address, out ipAddr);
            if (ipAddr == IPAddress.None)
            {
                IPHostEntry hostEntry = Dns.GetHostEntry(pServer.Address);
                // Get the IP value
                uint nIP = 0;
                if (hostEntry != null && hostEntry.AddressList.Length > 0)
                {
                    nIP = BitConverter.ToUInt32(hostEntry.AddressList[0].GetAddressBytes(), 0);
                }

                if (nIP != 0)
                {
                    bool bRemoveServer = false;
                    if (!MpdUtilities.IsGoodIP(nIP))
                    {
                        // However, if we are currently connected to a "not-good-ip", that IP can't
                        // be that bad -- may only happen when debugging in a LAN.
                        ED2KServer pConnectedServer = MuleApplication.Instance.ServerConnect.CurrentServer;
                        if (pConnectedServer != null || pConnectedServer.IP != nIP)
                        {
                            bRemoveServer = true;
                        }
                    }
                    if (!bRemoveServer && MuleApplication.Instance.Preference.IsFilterServerByIP &&
                        MuleApplication.Instance.IPFilter.IsFiltered(nIP))
                    {
                        bRemoveServer = true;
                    }

                    ED2KServer pTempServer =
                        MuleApplication.Instance.ServerList.GetServerByAddress(pServer.Address, pServer.Port);
                    if (pTempServer != null)
                    {
                        pServer.IP = nIP;
                        // If we already have entries in the server list (dynIP-servers without a DN)
                        // with the same IP as this dynIP-server, remove the duplicates.
                        MuleApplication.Instance.ServerList.RemoveDuplicatesByIP(pServer);
                    }

                    if (bRemoveServer)
                    {
                        return;
                    }

                    // Send all of the queued packets for this server.
                    SendBuffer(nIP, nPort, pRawPacket, uRawPacketSize);
                }
            }
            else
            {
                // No DNS query needed for this server. Just send the packet.
                SendBuffer(BitConverter.ToUInt32(ipAddr.GetAddressBytes(), 0),
                           nPort, pRawPacket, uRawPacketSize);
            }
        }
Exemplo n.º 4
0
 public void SendPacket(Packet packet, Mule.ED2K.ED2KServer host, ushort nSpecialPort, byte[] pRawPacket)
 {
     SendPacket(packet, host, nSpecialPort, pRawPacket, 0);
 }
Exemplo n.º 5
0
 public void SendPacket(Packet packet, Mule.ED2K.ED2KServer host, ushort nSpecialPort)
 {
     SendPacket(packet, host, nSpecialPort, null, 0);
 }
Exemplo n.º 6
0
 public void SendPacket(Packet packet, Mule.ED2K.ED2KServer host)
 {
     SendPacket(packet, host, 0, null, 0);
 }
Exemplo n.º 7
0
 public bool SendUDPPacket(Mule.Network.Packet packet, Mule.ED2K.ED2KServer host,
                           bool delpacket, ushort nSpecialPort, byte[] pRawPacket)
 {
     return(SendUDPPacket(packet, host, delpacket, nSpecialPort, pRawPacket, 0));
 }
Exemplo n.º 8
0
 public bool SendUDPPacket(Mule.Network.Packet packet, Mule.ED2K.ED2KServer host, bool delpacket)
 {
     return(SendUDPPacket(packet, host, delpacket, 0, null, 0));
 }