Exemplo n.º 1
0
        public void DropNode(Node n)
        {
            NodeEntry entry = new NodeEntry(node.Id, n);

            this.buckets[GetBucketId(entry)].DropNode(entry);
            this.nodes.Remove(entry);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public void DropNode(NodeEntry entry)
 {
     foreach (NodeEntry node in this.nodes)
     {
         if (node.Id.Equals(entry.Id))
         {
             this.nodes.Remove(node);
             break;
         }
     }
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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;
                }
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public int GetBucketId(NodeEntry entry)
        {
            int id = entry.Distance - 1;

            return(id < 0 ? 0 : id);
        }