From c1b05402ef0f436b3f2d1e91be01daeae05e7323 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 11 Jul 2018 15:16:01 -0400 Subject: [PATCH 1/2] add address and port arguments to peer_ping allows directly pinging the peer without first doing an iterative find --- lbrynet/daemon/Daemon.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index b80ba3581..e551ab6cc 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2820,26 +2820,36 @@ class Daemon(AuthJSONRPCServer): @requires(DHT_COMPONENT) @defer.inlineCallbacks - def jsonrpc_peer_ping(self, node_id): + def jsonrpc_peer_ping(self, node_id, address=None, port=None): """ - Find and ping a peer by node id + Send a kademlia ping to the specified peer. If address and port are provided the peer is directly pinged, + if not provided the peer is located first. Usage: - peer_ping ( | --node_id=) + peer_ping ( | --node_id=) [
| --address=
] [ | --port=] Options: - None + --address=
: (str) ip address of the peer + --port= : (int) udp port of the peer + Returns: (str) pong, or {'error': } if an error is encountered """ contact = None - try: - contact = yield self.dht_node.findContact(node_id.decode('hex')) - except TimeoutError: - result = {'error': 'timeout finding peer'} - defer.returnValue(result) + if node_id and address and port: + contact = self.dht_node.contact_manager.get_contact(node_id.decode('hex'), address, int(port)) + if not contact: + contact = self.dht_node.contact_manager.make_contact( + node_id.decode('hex'), address, int(port), self.dht_node._protocol + ) + if not contact: + try: + contact = yield self.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: From 96e73f34762d9e43d3d614486ddb906a1a4634ce Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 11 Jul 2018 15:40:52 -0400 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca2f70285..2431e2067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ at anytime. * unittests for `ComponentManager` * script to generate docs/api.json file (https://github.com/lbryio/lbry.tech/issues/42) * additional information to the balance error message when editing a claim (https://github.com/lbryio/lbry/pull/1309) + * `address` and `port` arguments to `peer_ping` (https://github.com/lbryio/lbry/issues/1313) ### Removed * most of the internal attributes from `Daemon`