public void DropNode(Node n) { NodeEntry entry = new NodeEntry(node.Id, n); this.buckets[GetBucketId(entry)].DropNode(entry); this.nodes.Remove(entry); }
public Node AddNode(Node n) { NodeEntry entry = new NodeEntry(this.node.Id, n); if (this.nodes.Contains(entry)) { this.nodes.ForEach(item => { if (item.Equals(entry)) { item.Touch(); } }); return(null); } NodeEntry last_seen = this.buckets[GetBucketId(entry)].AddNode(entry); if (last_seen != null) { return(last_seen.Node); } if (!this.nodes.Contains(entry)) { this.nodes.Add(entry); } return(null); }
public void DropNode(NodeEntry entry) { foreach (NodeEntry node in this.nodes) { if (node.Id.Equals(entry.Id)) { this.nodes.Remove(node); break; } } }
public override bool Equals(object obj) { bool ret = false; if (obj != null && this.GetType() == obj.GetType()) { NodeEntry e = (NodeEntry)obj; ret = this.entry_id.Equals(e.entry_id); } return(ret); }
public void TouchNode(Node n) { NodeEntry entry = new NodeEntry(node.Id, n); foreach (NodeBucket b in this.buckets) { if (b.Nodes.Contains(entry)) { b.Nodes[b.Nodes.IndexOf(entry)].Touch(); break; } } }
public bool Contains(Node n) { NodeEntry entry = new NodeEntry(node.Id, n); foreach (NodeBucket b in this.buckets) { if (b.Nodes.Contains(entry)) { return(true); } } return(false); }
public NodeEntry AddNode(NodeEntry entry) { if (!this.nodes.Contains(entry)) { if (this.nodes.Count >= KademliaOptions.BUCKET_SIZE) { return(GetLastSeen()); } else { this.nodes.Add(entry); } } return(null); }
public int GetBucketId(NodeEntry entry) { int id = entry.Distance - 1; return(id < 0 ? 0 : id); }