示例#1
0
 // Collapses a group of packets.  This involves incrementing the group
 // counter and clearing the savedPackets stack by moving top back to 0.
 // If this is the first group to be collapsed, the collapse time needs
 // to be set, which marks when this collapsing began.
 static void collapse(PacketGroup group,
                      CollapseInfo collapseInfo,
                      PacketQueue pktQ)
 {
     collapseInfo.count[(byte)group]++;
     if (collapseInfo.timeSop == 0)
     {
         if (!pktQ.isEmpty())
         {
             collapseInfo.timeSop = pktQ.headSop();
         }
         else
         {
             collapseInfo.timeSop = pktQ.tailSop();
         }
     }
     pktQ.clear();
 }
示例#2
0
        private void DrawNetwork(Graphics buffer, DhtNetwork network, Point center, int radius, int innerRad)
        {
            // draw dhts
            float sweepAngle = 360;
            Pen   orangePen  = new Pen(Color.Orange, 1);
            int   arcs       = 0;

            int  maxLevels = 5;
            uint localID   = (uint)(network.Local.UserID >> 32);

            int drawBuckets = network.Routing.BucketList.Count - 1;  // -1 last is drawn by previous

            if (network.Routing.BucketList.Count > maxLevels)
            {
                drawBuckets = maxLevels;
            }

            for (int i = 0; i < drawBuckets; i++, sweepAngle /= 2)
            {
                if (sweepAngle < 0.1)
                {
                    break;
                }

                int outterRad = innerRad + ((radius - innerRad) * i / drawBuckets);

                uint lowpos = localID >> (32 - i);
                lowpos = lowpos << (32 - i);
                uint highpos = lowpos | ((uint)1 << 31 - i);

                float startAngle = 360 * ((float)lowpos / (float)uint.MaxValue);

                if (i != 0)
                {
                    arcs++;
                    buffer.DrawArc(orangePen, GetBoundingBox(center, outterRad), startAngle, sweepAngle);

                    buffer.DrawLine(orangePen, GetCircumPoint(center, outterRad, lowpos), GetCircumPoint(center, radius, lowpos));
                    buffer.DrawLine(orangePen, GetCircumPoint(center, outterRad, highpos), GetCircumPoint(center, radius, highpos));
                }
                else
                {
                    buffer.DrawLine(orangePen, GetCircumPoint(center, innerRad, 0), GetCircumPoint(center, radius, 0));
                    buffer.DrawLine(orangePen, GetCircumPoint(center, innerRad, uint.MaxValue / 2), GetCircumPoint(center, radius, uint.MaxValue / 2));
                }
            }


            // load packets to draw
            Dictionary <ulong, PacketGroup> targets = new Dictionary <ulong, PacketGroup>();


            lock (network.LoggedPackets)
                foreach (PacketLogEntry packet in network.LoggedPackets)
                {
                    if (packet.Address == null)
                    {
                        continue;
                    }

                    if (packet.Time < Core.TimeNow.AddSeconds(-1))
                    {
                        continue;
                    }

                    PacketGroup group;
                    if (!targets.TryGetValue(packet.Address.UserID, out group))
                    {
                        group = new PacketGroup(network.Local.UserID, packet.Address.UserID);
                        targets[packet.Address.UserID] = group;
                    }

                    group.TotalSize += packet.Data.Length;
                    group.Packets.Add(packet.Data);
                }



            // draw packets, each group is a different target
            foreach (PacketGroup group in targets.Values)
            {
                group.SetPoints(GetCircumPoint(center, radius, group.SourceID), GetCircumPoint(center, radius, group.DestID));

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

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

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

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


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

                foreach (byte[] packet in group.Packets)
                {
                    buffer.DrawLine(PacketPen, group.GetPoint(pos), group.GetPoint(pos + packet.Length));
                    pos += packet.Length;

                    buffer.DrawLine(TrafficPen, group.GetPoint(pos), group.GetPoint(pos + breakSize));
                    pos += breakSize;
                }
            }

            // draw network ring
            Rectangle box = GetBoundingBox(center, radius);

            Pen ringPen = network.Responsive ? ConnectedPen : DisconnectedPen;

            buffer.DrawEllipse(ringPen, box);

            // get nodes
            List <ulong> peers = new List <ulong>();

            peers.Add(network.Local.UserID);

            lock (network.Routing.BucketList)
                foreach (DhtBucket bucket in network.Routing.BucketList)
                {
                    foreach (DhtContact contact in bucket.ContactList)
                    {
                        peers.Add(contact.UserID);
                    }
                }

            // draw nodes
            foreach (ulong id in peers)
            {
                box = GetBoundingBox(GetCircumPoint(center, radius, id), 3);
                buffer.FillEllipse(NodeBrush, box);
            }

            // draw ring around self
            box = GetBoundingBox(GetCircumPoint(center, radius, network.Local.UserID), 5);
            buffer.DrawEllipse(GetSelfPen(network.Core.Firewall), box);
        }