示例#1
0
        void ProcessFindValueRequest(IMessage message)
        {
            string  key     = message.key;
            Storage storage = null;

            lock (storages)
            {
                storages.TryGetValue(key, out storage);
            }
            // se conosco il valore per quella determinata chiave allora rispondo con il valore
            if (storage != null)
            {
                Message response = new Message(message.SourceEndPoint);
                response.CreateFindValueResponse(key, storage.Val);
                Send(response, response.DestPeer);
            }
            // se non ho la chiave cercata allora mando i nodi più vicini
            else
            {
                List <PeerInfo> peers    = GetCloserPeers((PeerId)message.key, K);
                var             response = new Message(message.SourceEndPoint);
                response.CreateFindNodeResponse(peers);
                Send(response, response.DestPeer);
            }
        }
示例#2
0
        void ProcessFindNodeRequest(IMessage message)
        {
            List <PeerInfo> peers    = GetCloserPeers(message.peerID, K);
            var             response = new Message(message.SourceEndPoint);

            response.CreateFindNodeResponse(peers);
            Send(response, response.DestPeer);
        }