Example #1
0
        public static void HandleOutgoing(byte[] data)
        {
            var packet = new PacketUDP(new MemoryStream(data));

            var ip = new IPAddress(packet.ADDR);
            var port = BitConverter.ToUInt16(packet.PORT, 0);

            // THIS IS WHERE ALL THE MAGIC HAPPENS, BABY
            // Loopback detection: If we're making a request to our external IP, route it!
            // Note that we're rerouting regardless
            if (ip.Equals(ExternalIP) && TargetPorts.Contains(port))
                ip = (IPAddress)UDProxy.gConfiguration.Config["TargetIP"];

            IPEndPoint destination = new IPEndPoint(ip, port);
            TotalUp += MyUDP.Send(packet.DATA, packet.DATA.Length, destination);
        }
Example #2
0
        public static void HandleIncoming(byte[] data, IPEndPoint sender)
        {
            // THIS IS WHERE ALL THE MAGIC UNHAPPENS, BABY
            // Loopback detection: If we're receiving from a server we're routing to,
            // make it look like it's coming from our external IP.
            if (sender.Address.Equals(TargetIP) && TargetPorts.Contains((ushort)sender.Port))
                sender.Address = ExternalIP;

            var packet = new PacketUDP(
                SOCKS5Protocol.ATYP.IPV4,
                sender.Address,
                (ushort)sender.Port,
                data
            );

            var packetBytes = packet.GetBytes();
            TotalDown += MyUDP.Send(packetBytes, packetBytes.Length, MyClient);
        }
Example #3
0
        public static void HandleOutgoing(byte[] data)
        {
            var packet = new PacketUDP(new MemoryStream(data));

            var ip   = new IPAddress(packet.ADDR);
            var port = BitConverter.ToUInt16(packet.PORT, 0);

            // THIS IS WHERE ALL THE MAGIC HAPPENS, BABY
            // Loopback detection: If we're making a request to our external IP, route it!
            // Note that we're rerouting regardless
            if (ip.Equals(ExternalIP) && TargetPorts.Contains(port))
            {
                ip = (IPAddress)UDProxy.gConfiguration.Config["TargetIP"];
            }

            IPEndPoint destination = new IPEndPoint(ip, port);

            TotalUp += MyUDP.Send(packet.DATA, packet.DATA.Length, destination);
        }
Example #4
0
        public static void HandleIncoming(byte[] data, IPEndPoint sender)
        {
            // THIS IS WHERE ALL THE MAGIC UNHAPPENS, BABY
            // Loopback detection: If we're receiving from a server we're routing to,
            // make it look like it's coming from our external IP.
            if (sender.Address.Equals(TargetIP) && TargetPorts.Contains((ushort)sender.Port))
            {
                sender.Address = ExternalIP;
            }

            var packet = new PacketUDP(
                SOCKS5Protocol.ATYP.IPV4,
                sender.Address,
                (ushort)sender.Port,
                data
                );

            var packetBytes = packet.GetBytes();

            TotalDown += MyUDP.Send(packetBytes, packetBytes.Length, MyClient);
        }
Example #5
0
 public PeerDataMessage(PacketUDP pk, Hashtable hd, bool ir)
 {
     this.packet     = pk;
     this.hData      = hd;
     this.isResponse = ir;
 }
Example #6
0
        //--------------------------------------- Private Method
        private static void _OnPacketUdpAttrival(PacketUDP packet)
        {
            if (P2P.IsTerminate)
            {
                return;
            }
            that.DebugAndLog("PacketUDP Arrvial from: " + packet.IpAddress + ":" + packet.Port.ToString());

            /* PreCheck if packet is JsonRPC or NOT? */
            Hashtable hData      = null;
            bool      isResponse = false;

            try
            {
                JsonSerializerSettings jsetting = new JsonSerializerSettings();
                jsetting.MaxDepth = 1;
                hData             = JsonConvert.DeserializeObject <Hashtable>(
                    Encoding.Default.GetString(packet.DataByteArray),
                    jsetting);

                // Check Protocol Version
                if (!hData.Contains(KW.JsonRpc))
                {
                    return;
                }
                if (!hData[KW.JsonRpc].ToString().Trim().Equals(KW.RpcVersion20))
                {
                    return;
                }

                // Check ID
                if (!hData.Contains(KW.ID))
                {
                    return;
                }
                int id = int.Parse((string)hData[KW.ID]); if (id < 0)
                {
                    return;
                }

                // Check Param or Result
                if (!hData.Contains(KW.Method))
                {
                    if (!hData.Contains(KW.Result))
                    {
                        return;
                    }
                    else
                    {
                        isResponse = true;
                    }                                                                       // Response Must have Result
                }
                else
                if (!hData.Contains(KW.Params))
                {
                    return;
                }
                else
                {
                    isResponse = false;
                }                                                                            // Method Must have Param
            }
            catch (Exception ex) {
                that.DebugAndLog("Cannot decode packet to HashingTable");
                that.DebugAndLog(ex.Message);
                return;
            }

            // Evertything OK, Can Push This Data/Packet to process
            that.DebugAndLog("Push PeerDataMessage to ProcessQueue");
            lock (queDataMessage.SyncRoot)
            {
                queDataMessage.Enqueue(new PeerDataMessage(packet, hData, isResponse));
                trickDataMessage.Set();
            }
        }