public void FindPeers() { Node node = new Node(new System.Net.IPEndPoint(IPAddress.Any, 8881)); ContactNode qbitContact = new ContactNode(Id.GenerateRandom(), new IPEndPoint(IPAddress.Loopback, 8999)); MnlMessage pingResp = node.Ping(qbitContact); qbitContact = new ContactNode(new Id((byte[])pingResp.Payload["id"]), qbitContact.EndPoint); node.BucketList.Put(qbitContact); HashTable hashTable = new HashTable(node, new IPEndPoint[] { new IPEndPoint(IPAddress.Loopback, 8999) }, 8881); Id infoHash = new Id(ParseTest.ConvertHexStringToByteArray("139f69de76a07790ec3ad31cbc3bd5d905871600")); var foundPeers = hashTable.FindPeers(infoHash); Assert.IsTrue(foundPeers.Count() > 0); node.Shutdown(); }
protected bool CheckPossibleMaliciousMessage(IPEndPoint originator, Id originatorId, MnlMessage maliciousMsg) { var malciousNodes = BucketList.GetClosestNodes(originatorId, 8); foreach (var maliciousNode in malciousNodes) { if (Ping(maliciousNode) == null) { if (BucketList.GetBucket(maliciousNode.Id).Remove(maliciousNode)) { Debug.WriteLine($"Removed malicious node {maliciousNode} from bucket list"); } else { Debug.WriteLine($"Can't remove malicious node {maliciousNode} from bucket list"); } } } return(true); }