public void Test_ctor() { var table = new DHTRoutingTable(10); Assert.IsNotNull(table); Assert.AreEqual(0, table.Count); table.Clear(); var randId = DHTId.CreateRandom(); var nodes = table.GetClosest(randId.Data); }
public void Test_ctor() { var table = new DHTRoutingTable(10); Assert.IsNotNull(table); Assert.AreEqual(0, table.Count); Assert.AreEqual(false, table.IsFull); table.Clear(); var randId = DHTHelper.GetRandomID(); var nodes = table.FindNodes(randId); }
public void SearchNodes(byte[] searchInfoHash) { fLogger.WriteDebug("Search for: {0}", searchInfoHash.ToHexString()); fSearchInfoHash = searchInfoHash; fSearchRunned = true; new Thread(() => { while (fSearchRunned) { int count = 0; lock (fRoutingTable) { // if the routing table has not been updated for more // than a minute - reset routing table long nowTicks = DateTime.Now.Ticks; if (nowTicks - fLastNodesUpdateTime > NodesUpdateRange.Ticks) { fRoutingTable.Clear(); fLogger.WriteDebug("DHT reset routing table"); } count = fRoutingTable.Count; } if (count == 0) { // reboot if empty foreach (var t in fRouters) { SendFindNodeQuery(new IPEndPoint(t, PublicDHTPort), null); } } else { // search var nodes = fRoutingTable.FindNodes(fSearchInfoHash); foreach (var node in nodes) { SendGetPeersQuery(node.EndPoint, fSearchInfoHash); } } Thread.Sleep(1000); } }).Start(); }
public void Stop() { Close(); fTransactions.Clear(); fRoutingTable.Clear(); }