Example #1
0
        // scan and check if given NodeIdent was found
        public ServerDesc FindInScanned(NodeIdent ni)
        {
            // try to find our node indent among scan result
            var sd = (from x in ScanResults where ni.Match(x) select x).FirstOrDefault();

            return(sd);
        }
Example #2
0
File: Node.cs Project: pjanec/DID
 public Node(NodeRegistry nreg, NodeIdent ni)
 {
     this.rdClient  = new Client();
     this.nreg      = nreg;
     this.nodeIdent = ni;
     // FIXME!
 }
Example #3
0
        // Adds new (not yet connected) nodes, removes the no longer reported ones (if disconnected)
        void ProcessScanResults(List <ServerDesc> serversFound)
        {
            // remember last scan result
            lastScanResult = serversFound;

            //// create not yet registered ones
            var serverDict = new Dictionary <NodeIdent, int>();

            foreach (var sd in serversFound)
            {
                var ni = NodeIdent.FromServerDesc(sd);
                serverDict[ni] = 1;                     // remember server existence

                //	if( !_nodes.ContainsKey( ni ) )
                //	{
                //		_nodes[ni] = new Node( sd );
                //	}
            }

            // remove no longer wanted and no longer found by scan
            foreach (var node in _nodes.Values.ToList())               // iterate a copy so that we can remove from orig dict
            {
                var ni = node.nodeIdent;

                if (!serverDict.ContainsKey(ni))                         // not found by scan
                {
                    if (!node.Wanted)
                    {
                        // forget the node
                        _nodes.Remove(ni);
                        node.Dispose();
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Finds node by its identifier
        /// </summary>
        /// <param name="ni"></param>
        /// <returns></returns>
        public Node Find(NodeIdent ni)
        {
            Node res;

            if (_nodes.TryGetValue(ni, out res))
            {
                return(res);
            }
            return(null);
        }
Example #5
0
        // creates node or just increment its refcount
        public Node Alloc(NodeIdent ni)
        {
            Node node;

            if (!_nodes.TryGetValue(ni, out node))
            {
                node       = new Node(this, ni);
                _nodes[ni] = node;
            }

            node.AddRef();

            return(node);
        }
Example #6
0
        // unref node and dispose if no references left
        public void Dealloc(NodeIdent ni)
        {
            Node node;

            if (!_nodes.TryGetValue(ni, out node))
            {
                return;
            }

            if (node.Unref() <= 0)
            {
                _nodes.Remove(ni);

                node.Dispose();
            }
        }
Example #7
0
 public NodeHunter(NodeRegistry nreg, NodeIdent ni)
 {
     this.nreg = nreg;
     // tell the node we need it (this should connect if not yet connected)
     node = nreg.Alloc(ni);
 }