예제 #1
0
        /// <summary>
        /// PingBack is called in response to a ping for a few reasons:
        /// 1. This registers the node we're pinging in the sender's list of peers
        /// 2. It minimally verifies that the sender is a peer.
        /// 3. We can't simply ping the sender of the ping we received, as this would create an infinite loop of ping - reping.
        /// NOTE: THIS IS NOT IN THE KADEMLIA SPEC EXCEPT FOR DISCUSSION OF "piggyback" PING RESPONSE.
        public RpcError PingBack(Contact sender)
        {
            ErrorResponse error;
            ID            id = ID.RandomID;
            bool          timeoutError;

            var ret = RestCall.Post <FindValueResponse, ErrorResponse>(url + ":" + port + "//PingBack",
                                                                       new PingSubnetRequest()
            {
                Protocol     = sender.Protocol,
                ProtocolName = sender.Protocol.GetType().Name,
                Sender       = sender.ID.Value,
                RandomID     = id.Value
            },
                                                                       out error, out timeoutError);

            return(GetRpcError(id, ret, timeoutError, error));
        }
예제 #2
0
        public RpcError Store(Contact sender, ID key, string val, bool isCached = false, int expirationTimeSec = 0)
        {
            ErrorResponse error;
            ID            id = ID.RandomID;
            bool          timeoutError;

            var ret = RestCall.Post <FindValueResponse, ErrorResponse>(url + ":" + port + "//Store",
                                                                       new StoreSubnetRequest()
            {
                Protocol          = sender.Protocol,
                ProtocolName      = sender.Protocol.GetType().Name,
                Sender            = sender.ID.Value,
                Key               = key.Value,
                Value             = val,
                IsCached          = isCached,
                ExpirationTimeSec = expirationTimeSec,
                RandomID          = id.Value
            },
                                                                       out error, out timeoutError);

            return(GetRpcError(id, ret, timeoutError, error));
        }