Example #1
0
        public void Receive_StoreReq(G2ReceivedPacket packet)
        {
            StoreReq store = StoreReq.Decode(packet);

            if (Core.ServiceBandwidth.ContainsKey(store.Service))
            {
                Core.ServiceBandwidth[store.Service].InPerSec += packet.Root.Data.Length;
            }

            if (store.Source.Firewall == FirewallType.Open)
            {
                // dont need to add to routing if nat/blocked because eventual routing ping by server will auto add
                Network.Routing.Add(new DhtContact(store.Source, packet.Source.IP));
            }


            // forward to proxied nodes - only replicate data to blocked nodes on operation network
            if (!Network.IsLookup)
            {
                // when we go offline it will be these nodes that update their next proxy with stored info
                foreach (TcpConnect socket in Network.TcpControl.ProxyClients)
                {
                    if (packet.Tcp != socket)
                    {
                        if (packet.ReceivedUdp)
                        {
                            store.FromAddress = packet.Source;
                        }

                        socket.SendPacket(store);
                    }
                }
            }

            // pass to components
            DataReq data = new DataReq(packet.Source, store.Key, store.Service, store.DataType, store.Data);

            if (packet.ReceivedTcp && packet.Tcp.Proxy == ProxyType.Server)
            {
                data.LocalProxy = new DhtClient(packet.Tcp);
            }

            if (data.Service == 0)
            {
                Receive_Patch(packet.Source, store.Data);
            }

            else if (StoreEvent.Contains(store.Service, store.DataType))
            {
                StoreEvent[store.Service, store.DataType].Invoke(data);
            }
        }
Example #2
0
        public void Send_StoreReq(DhtAddress address, DhtClient localProxy, DataReq publish)
        {
            if (address == null)
            {
                return;
            }

            StoreReq store = new StoreReq();

            store.Source   = Network.GetLocalSource();
            store.Key      = publish.Target;
            store.Service  = publish.Service;
            store.DataType = publish.DataType;
            store.Data     = publish.Data;

            int sentBytes = 0;

            TcpConnect direct = Network.TcpControl.GetProxy(address);

            if (direct != null)
            {
                sentBytes = direct.SendPacket(store);
            }

            else if (address.TunnelClient != null)
            {
                sentBytes = Network.SendTunnelPacket(address, store);
            }

            // if blocked send tcp with to tag
            else if (Core.Firewall == FirewallType.Blocked)
            {
                store.ToAddress = address;

                TcpConnect proxy = Network.TcpControl.GetProxy(localProxy);

                if (proxy != null)
                {
                    sentBytes = proxy.SendPacket(store);
                }
                else
                {
                    sentBytes = Network.TcpControl.SendRandomProxy(store);
                }
            }
            else
            {
                sentBytes = Network.UdpControl.SendTo(address, store);
            }

            Core.ServiceBandwidth[store.Service].OutPerSec += sentBytes;
        }
Example #3
0
        private void DrawGroup(Graphics buffer, Dictionary <ulong, Dictionary <ulong, PacketGroup> > TrafficGroup, bool tcp)
        {
            foreach (Dictionary <ulong, PacketGroup> destination in TrafficGroup.Values)
            {
                foreach (PacketGroup group in destination.Values)
                {
                    if (!NodePoints.ContainsKey(group.SourceID) || !NodePoints.ContainsKey(group.DestID))
                    {
                        continue;
                    }

                    group.SetPoints(NodePoints[group.SourceID], NodePoints[group.DestID]);

                    TrafficPen.Width = 1;
                    group.LineSize   = 200 + 20;

                    if (group.TotalSize > 200)
                    {
                        TrafficPen.Width = 2;
                        group.LineSize   = 1000 + 100;
                    }

                    if (group.TotalSize > 1000)
                    {
                        TrafficPen.Width = 3;
                        group.LineSize   = group.TotalSize + 500;
                    }

                    // calc break size
                    double breakSize = (group.LineSize - group.TotalSize) / (group.Packets.Count + 1);
                    double pos       = breakSize;

                    Color bgColor = Color.WhiteSmoke;

                    //if (SelectedID != 0)
                    //    bgColor = group.SourceID == SelectedID ? Color.LightCoral : Color.LightBlue;
                    //else
                    //    bgColor = tcp ? Color.LightBlue : Color.WhiteSmoke;

                    TrafficPen.Color = bgColor;
                    buffer.DrawLine(TrafficPen, group.GetPoint(0), group.GetPoint(pos));

                    foreach (byte[] packet in group.Packets)
                    {
                        if (Sim.TestEncryption || Sim.TestTcpFullBuffer)
                        {
                            TrafficPen.Color = Legend.PicUnk.BackColor;
                            buffer.DrawLine(TrafficPen, group.GetPoint(pos), group.GetPoint(pos + packet.Length));
                        }

                        else
                        {
                            G2Header root = new G2Header(packet);
                            G2Protocol.ReadPacket(root);

                            double controlLen = (root.InternalPos > 0) ? root.InternalPos - root.PacketPos : packet.Length;

                            // net packet
                            if (root.Name == RootPacket.Network)
                            {
                                TrafficPen.Color = Legend.PicNet.BackColor;
                                buffer.DrawLine(TrafficPen, group.GetPoint(pos), group.GetPoint(pos + controlLen));

                                NetworkPacket netPacket    = NetworkPacket.Decode(root);
                                G2Header      internalRoot = new G2Header(netPacket.InternalData);
                                G2Protocol.ReadPacket(internalRoot);

                                G2ReceivedPacket recvedPacket = new G2ReceivedPacket();
                                recvedPacket.Root = internalRoot;

                                // draw internal
                                TrafficPen.Color = Legend.PicUnk.BackColor;

                                if (internalRoot.Name == NetworkPacket.SearchRequest)
                                {
                                    SearchReq req = SearchReq.Decode(recvedPacket);

                                    int paramLen = req.Parameters == null ? 10 : req.Parameters.Length;

                                    TrafficPen.Color = Legend.PicSrchReq.BackColor;
                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen), group.GetPoint(pos + controlLen + internalRoot.PacketSize - paramLen));

                                    TrafficPen.Color = GetComponentColor(req.Service);
                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen + internalRoot.PacketSize - paramLen), group.GetPoint(pos + controlLen + internalRoot.PacketSize));
                                }

                                else if (internalRoot.Name == NetworkPacket.SearchAck)
                                {
                                    SearchAck ack = SearchAck.Decode(recvedPacket);

                                    int valLen = 10;

                                    if (ack.ValueList.Count > 0)
                                    {
                                        valLen = 0;
                                        foreach (byte[] val in ack.ValueList)
                                        {
                                            valLen += val.Length;
                                        }
                                    }

                                    TrafficPen.Color = Legend.PicSrchAck.BackColor;
                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen), group.GetPoint(pos + controlLen + internalRoot.PacketSize - valLen));

                                    TrafficPen.Color = GetComponentColor(ack.Service);
                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen + internalRoot.PacketSize - valLen), group.GetPoint(pos + controlLen + internalRoot.PacketSize));
                                }

                                else if (internalRoot.Name == NetworkPacket.StoreRequest)
                                {
                                    StoreReq req = StoreReq.Decode(recvedPacket);

                                    int dataLen = req.Data == null ? 10 : req.Data.Length;

                                    TrafficPen.Color = Legend.PicStore.BackColor;
                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen), group.GetPoint(pos + controlLen + internalRoot.PacketSize - dataLen));

                                    TrafficPen.Color = GetComponentColor(req.Service);
                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen + internalRoot.PacketSize - dataLen), group.GetPoint(pos + controlLen + internalRoot.PacketSize));
                                }

                                else
                                {
                                    if (internalRoot.Name == NetworkPacket.Ping)
                                    {
                                        TrafficPen.Color = Legend.PicPing.BackColor;
                                    }

                                    else if (internalRoot.Name == NetworkPacket.Pong)
                                    {
                                        TrafficPen.Color = Legend.PicPong.BackColor;
                                    }

                                    else if (internalRoot.Name == NetworkPacket.ProxyRequest)
                                    {
                                        TrafficPen.Color = Legend.PicPxyReq.BackColor;
                                    }

                                    else if (internalRoot.Name == NetworkPacket.ProxyAck)
                                    {
                                        TrafficPen.Color = Legend.PicPxyAck.BackColor;
                                    }

                                    buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen), group.GetPoint(pos + packet.Length));
                                }
                            }

                            // comm packet
                            if (root.Name == RootPacket.Comm)
                            {
                                TrafficPen.Color = Legend.PicComm.BackColor;
                                buffer.DrawLine(TrafficPen, group.GetPoint(pos), group.GetPoint(pos + controlLen));

                                TrafficPen.Color = Legend.PicUnk.BackColor;
                                buffer.DrawLine(TrafficPen, group.GetPoint(pos + controlLen), group.GetPoint(pos + packet.Length));
                            }
                        }

                        if (SelectedID != 0)
                        {
                            buffer.DrawString(group.TotalSize.ToString(), TahomaFont, BlackBrush, group.GetPoint(group.LineSize / 4));
                        }

                        pos += packet.Length;

                        TrafficPen.Color = bgColor;
                        buffer.DrawLine(TrafficPen, group.GetPoint(pos), group.GetPoint(pos + breakSize));
                        pos += breakSize;
                    }
                }
            }
        }
Example #4
0
        public ListViewItem PackettoItem(PacketLogEntry logEntry)
        {
            // hash, protocol, direction, address, type, size
            string hash     = Utilities.BytestoHex(sha.ComputeHash(logEntry.Data), 0, 2, false);
            string protocol = logEntry.Protocol.ToString();

            // Network - Search / Search Req / Store ... - Component

            // Comm - Data / Ack / Syn

            // Rudp - Type - Component

            string name = "?";

            G2Header root = new G2Header(logEntry.Data);

            if (G2Protocol.ReadPacket(root))
            {
                if (logEntry.Protocol == TransportProtocol.Rudp)
                {
                    name = TransportProtocol.Rudp.ToString() + " - ";

                    name += GetVariableName(typeof(CommPacket), root.Name);

                    if (root.Name == CommPacket.Data)
                    {
                        CommData data = CommData.Decode(root);

                        name += " - " + Network.Core.GetServiceName(data.Service);
                    }
                }
                else
                {
                    name = GetVariableName(typeof(RootPacket), root.Name) + " - ";

                    if (root.Name == RootPacket.Comm)
                    {
                        RudpPacket commPacket = RudpPacket.Decode(root);

                        name += GetVariableName(typeof(RudpPacketType), commPacket.PacketType);
                    }

                    if (root.Name == RootPacket.Network)
                    {
                        NetworkPacket netPacket = NetworkPacket.Decode(root);

                        G2Header internalRoot = new G2Header(netPacket.InternalData);
                        if (G2Protocol.ReadPacket(internalRoot))
                        {
                            name += GetVariableName(typeof(NetworkPacket), internalRoot.Name);

                            uint             id   = 0;
                            G2ReceivedPacket wrap = new G2ReceivedPacket();
                            wrap.Root = internalRoot;

                            // search request / search acks / stores have component types
                            if (internalRoot.Name == NetworkPacket.SearchRequest)
                            {
                                SearchReq req = SearchReq.Decode(wrap);
                                id = req.Service;
                            }

                            if (internalRoot.Name == NetworkPacket.SearchAck)
                            {
                                SearchAck ack = SearchAck.Decode(wrap);
                                id = ack.Service;
                            }

                            if (internalRoot.Name == NetworkPacket.StoreRequest)
                            {
                                StoreReq store = StoreReq.Decode(wrap);
                                id = store.Service;
                            }

                            if (id != 0)
                            {
                                name += " - " + Network.Core.GetServiceName(id); // GetVariableName(typeof(ServiceID), id);
                            }
                        }
                    }
                }
            }

            string time = logEntry.Time.ToString("HH:mm:ss:ff");

            string address = (logEntry.Address == null) ? "Broadcast" : logEntry.Address.ToString();

            return(new PacketListViewItem(logEntry, new string[] { time, protocol, address, name, logEntry.Data.Length.ToString(), hash }, logEntry.Direction == DirectionType.In));
        }
Example #5
0
        public void Send_StoreReq(DhtAddress address, DhtClient localProxy, DataReq publish)
        {
            if (address == null)
                return;

            StoreReq store = new StoreReq();
            store.Source    = Network.GetLocalSource();
            store.Key       = publish.Target;
            store.Service   = publish.Service;
            store.DataType  = publish.DataType;
            store.Data      = publish.Data;

            int sentBytes = 0;

            TcpConnect direct = Network.TcpControl.GetProxy(address);

            if (direct != null)
                sentBytes = direct.SendPacket(store);

            else if (address.TunnelClient != null)
                sentBytes = Network.SendTunnelPacket(address, store);

            // if blocked send tcp with to tag
            else if (Core.Firewall == FirewallType.Blocked)
            {
                store.ToAddress = address;

                TcpConnect proxy = Network.TcpControl.GetProxy(localProxy);

                if (proxy != null)
                    sentBytes = proxy.SendPacket(store);
                else
                    sentBytes = Network.TcpControl.SendRandomProxy(store);
            }
            else
                sentBytes = Network.UdpControl.SendTo(address, store);

            Core.ServiceBandwidth[store.Service].OutPerSec += sentBytes;
        }