/// <summary> /// A k-bucket is full! /// </summary> /// <remarks> /// Currently this just removes the oldest contact from the list, /// without acutally pinging the individual peers. /// /// This is the same as go does, but should probably /// be upgraded to actually ping the individual peers. /// </remarks> private void Peers_Ping(object sender, PingEventArgs <RoutingPeer> e) { if (_peers.Remove(e.Oldest.First())) { _peers.Add(e.Newest); } }
async Task QueryLoop() { while (!_node.HasQuit) { await Task.Delay(Time.Seconds(5), _node.QuitToken); if (_node.HasQuit) { return; } List <NodeInfo> nodes = null; lock (_queryNodes) { if (_queryNodes.Count > 0) { nodes = new List <NodeInfo>(_queryNodes); } _queryNodes.Clear(); } if (nodes != null) { foreach (var node in nodes) { if (node.IsPublicEndPoint) { if (!await QueryEndPoint(node.PublicEndPoint, true)) { _bucket.Remove(node.NodeId); } } } } } }
public void Remove() { var bucket = new KBucket <Contact>(); Assert.AreEqual(0, bucket.Count); bucket.Add(new Contact("a")); bucket.Add(new Contact("b")); bucket.Add(new Contact("c")); Assert.AreEqual(3, bucket.Count); bucket.Remove(new Contact("b")); Assert.AreEqual(2, bucket.Count); Assert.IsTrue(bucket.Contains(new Contact("a"))); Assert.IsFalse(bucket.Contains(new Contact("b"))); Assert.IsTrue(bucket.Contains(new Contact("c"))); }