mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-08-28 07:51:33 +00:00
add address and port arguments to peer_ping
allows directly pinging the peer without first doing an iterative find
This commit is contained in:
parent
1dd1bad9c2
commit
c1b05402ef
1 changed files with 19 additions and 9 deletions
|
@ -2820,26 +2820,36 @@ class Daemon(AuthJSONRPCServer):
|
||||||
|
|
||||||
@requires(DHT_COMPONENT)
|
@requires(DHT_COMPONENT)
|
||||||
@defer.inlineCallbacks
|
@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:
|
Usage:
|
||||||
peer_ping (<node_id> | --node_id=<node_id>)
|
peer_ping (<node_id> | --node_id=<node_id>) [<address> | --address=<address>] [<port> | --port=<port>]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
None
|
--address=<address> : (str) ip address of the peer
|
||||||
|
--port=<port> : (int) udp port of the peer
|
||||||
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(str) pong, or {'error': <error message>} if an error is encountered
|
(str) pong, or {'error': <error message>} if an error is encountered
|
||||||
"""
|
"""
|
||||||
|
|
||||||
contact = None
|
contact = None
|
||||||
try:
|
if node_id and address and port:
|
||||||
contact = yield self.dht_node.findContact(node_id.decode('hex'))
|
contact = self.dht_node.contact_manager.get_contact(node_id.decode('hex'), address, int(port))
|
||||||
except TimeoutError:
|
if not contact:
|
||||||
result = {'error': 'timeout finding peer'}
|
contact = self.dht_node.contact_manager.make_contact(
|
||||||
defer.returnValue(result)
|
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:
|
if not contact:
|
||||||
defer.returnValue({'error': 'peer not found'})
|
defer.returnValue({'error': 'peer not found'})
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue