示例#1
0
        /// <summary>
        /// Manually refresh all buckets and draw the new connections in purple.
        /// </summary>
        private void btnBucketRefresh_Click(object sender, EventArgs e)
        {
            dhts.AsParallel().ForEach(d => d.PerformBucketRefresh());
            System.Threading.Thread.Sleep(500);

            dhts.ForEachWithIndex((d, i) =>
            {
                d.Node.BucketList.Buckets.SelectMany(b => b.Contacts).ForEach(c =>
                {
                    int idx = dhts.FindIndex(target => target.ID == c.ID);
                    var current = new Peer2Peer() { idx1 = i, idx2 = idx };
                    var otherDir = new Peer2Peer() { idx1 = idx, idx2 = i };

                    // Don't draw connector going back (idx -> i) because this is a redundant draw.  Speeds things up a little.
                    if (!connections.Contains(otherDir) && !connections.Contains(current))
                    {
                        // bucketRefreshPeers.Add(d);
                        Point c1 = dhtPos[i].Center();
                        Point c2 = dhtPos[idx].Center();
                        WebSocketHelpers.DropConnector("DiagonalConnector", "c" + i, c1.X, c1.Y, c2.X, c2.Y, Color.Purple);
                        connections.Add(new Peer2Peer() { idx1 = i, idx2 = idx });
                    }
                });
            });
        }
示例#2
0
        protected void DrawDhts()
        {
            WebSocketHelpers.ClearCanvas();
            Application.DoEvents();
            connections = new List<Peer2Peer>();

            if (!ckNodesTopmost.Checked)
            {
                dhtPos.ForEachWithIndex((p, i) => WebSocketHelpers.DropShape("Ellipse", i.ToString(), p, peerColor[dhts[i].ID.Value], ""));
            }

            Application.DoEvents();


            if (ckShowConnections.Checked)
            {
                // First the original connections...
                // dhts.Where(d=>!bucketRefreshPeers.Contains(d)).ForEachWithIndex((d, i) =>
                dhts.ForEachWithIndex((d, i) =>
                {
                    d.Node.BucketList.Buckets.SelectMany(b => b.Contacts).ForEach(c =>
                      {
                          int idx = dhts.FindIndex(target => target.ID == c.ID);
                          var otherDir = new Peer2Peer() { idx1 = idx, idx2 = i };

                      // Don't draw connector going back (idx -> i) because this is a redundant draw.  Speeds things up a little.
                      if (!connections.Contains(otherDir))
                          {
                              Point c1 = dhtPos[i].Center();
                              Point c2 = dhtPos[idx].Center();
                              WebSocketHelpers.DropConnector("DiagonalConnector", "c" + i, c1.X, c1.Y, c2.X, c2.Y, Color.Gray);
                              connections.Add(new Peer2Peer() { idx1 = i, idx2 = idx });
                              Application.DoEvents();
                          }
                      });
                });
            }

            if (ckNodesTopmost.Checked)
            {
                dhtPos.ForEachWithIndex((p, i) => WebSocketHelpers.DropShape("Ellipse", i.ToString(), p, peerColor[dhts[i].ID.Value], ""));
            }

            Application.DoEvents();

            /*
            // Then the bucket refresh connections:
            dhts.Where(d => bucketRefreshPeers.Contains(d)).ForEachWithIndex((d, i) =>
            {
                d.Node.BucketList.Buckets.SelectMany(b => b.Contacts).ForEach(c =>
                {
                    int idx = dhts.FindIndex(target => target.ID == c.ID);
                    var otherDir = new Peer2Peer() { idx1 = idx, idx2 = i };

                    // Don't draw connector going back (idx -> i) because this is a redundant draw.  Speeds things up a little.
                    if (!connections.Contains(otherDir))
                    {
                        Point c1 = dhtPos[i].Center();
                        Point c2 = dhtPos[idx].Center();
                        WebSocketHelpers.DropConnector("DiagonalConnector", "c" + i, c1.X, c1.Y, c2.X, c2.Y, Color.Purple);
                        connections.Add(new Peer2Peer() { idx1 = i, idx2 = idx });
                    }
                });
            });
            */
        }