internal static void ManyNodes(out RoutingTable routingTable, out List<NodeId> nodes) { // Generate our local id byte[] id = new byte[20]; id[19] = 7; nodes = new List<NodeId>(); RoutingTable table = new RoutingTable(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0))); for (int i = 0; i <= 30; i++) { if (i == 7) continue; id = new byte[20]; id[19] = (byte)i; nodes.Add(new NodeId(id)); table.Add(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0))); } nodes.Sort(delegate(NodeId left, NodeId right) { NodeId dLeft = left.Xor(table.LocalNode.Id); NodeId dRight = right.Xor(table.LocalNode.Id); return dLeft.CompareTo(dRight); }); nodes.RemoveAll(delegate(NodeId n) { return table.FindNode(n) == null; }); routingTable = table; }
public void Setup() { id = new byte[20]; id[1] = 128; n = new Node(new NodeId(id), new System.Net.IPEndPoint(IPAddress.Any, 0)); table = new RoutingTable(n); table.NodeAdded += delegate { addedCount++; }; table.Add(n); //the local node is no more in routing table so add it to show test is still ok addedCount = 0; }
public RoutingTableTests() { id = new byte[20]; id[1] = 128; n = new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0)); table = new RoutingTable(n); table.NodeAdded += delegate { addedCount++; }; table.Add(n); //the local node is no more in routing table so add it to show test is still ok addedCount = 0; }
public DhtEngine() { var monitor = new TransferMonitor(); BucketRefreshTimeout = TimeSpan.FromMinutes(15); MessageLoop = new MessageLoop(this, monitor); Monitor = monitor; RoutingTable = new RoutingTable(); State = DhtState.NotReady; TokenManager = new TokenManager(); Torrents = new Dictionary <NodeId, List <Node> > (); MainLoop.QueueTimeout(TimeSpan.FromMinutes(5), () => { if (!Disposed) { TokenManager.RefreshTokens(); } return(!Disposed); }); }
/// <summary> /// 构造DHT引擎 /// </summary> /// <param name="listener">监听对象</param> public DhtEngine(IDhtListener listener) { if (listener == null) { throw new ArgumentNullException(nameof(listener)); } BucketRefreshTimeout = TimeSpan.FromMinutes(15); MessageLoop = new MessageLoop(this, listener); RoutingTable = new RoutingTable(); State = DhtState.NotReady; TokenManager = new TokenManager(); Torrents = new Dictionary <NodeId, List <Node> > (); MainLoop.QueueTimeout(TimeSpan.FromMinutes(5), () => { if (!Disposed) { TokenManager.RefreshTokens(); } return(!Disposed); }); }