add peer_ping

This commit is contained in:
Jack Robison 2018-03-29 10:46:29 -04:00
parent eae97a8133
commit 2903ccaeb4
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 28 additions and 0 deletions

View file

@ -47,6 +47,7 @@ at anytime.
* virtual kademlia network and mock udp transport for dht integration tests
* integration tests for bootstrapping the dht
* configurable `concurrent_announcers` setting
* `peer_ping` command
### Removed
* `announce_all` argument from `blob_announce`

View file

@ -48,6 +48,7 @@ from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.core.Error import InsufficientFundsError, UnknownNameError
from lbrynet.core.Error import DownloadDataTimeout, DownloadSDTimeout
from lbrynet.core.Error import NullFundsError, NegativeFundsError
from lbrynet.dht.error import TimeoutError
from lbrynet.core.Peer import Peer
from lbrynet.core.SinglePeerDownloader import SinglePeerDownloader
from lbrynet.core.client.StandaloneBlobDownloader import StandaloneBlobDownloader
@ -3040,6 +3041,32 @@ class Daemon(AuthJSONRPCServer):
d.addCallback(lambda r: self._render_response(r))
return d
@defer.inlineCallbacks
def jsonrpc_peer_ping(self, node_id):
"""
Find and ping a peer by node id
Usage:
peer_ping (<node_id> | --node_id=<node_id>)
Returns:
(str) pong, or {'error': <error message>} if an error is encountered
"""
contact = None
try:
contact = yield self.session.dht_node.findContact(node_id.decode('hex'))
except TimeoutError:
result = {'error': 'timeout finding peer'}
defer.returnValue(result)
if not contact:
defer.returnValue({'error': 'peer not found'})
try:
result = yield contact.ping()
except TimeoutError:
result = {'error': 'ping timeout'}
defer.returnValue(result)
def jsonrpc_routing_table_get(self):
"""
Get DHT routing information