-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrpc.py
30 lines (22 loc) · 908 Bytes
/
rpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from request import RemoteRequest, LocalRequest
from utils import log
class Ping(RemoteRequest):
def __init__(self, nodeid):
super().__init__(nodeid)
def onreceive(self, peer, reqaddr, reqport):
# respond with a Pong with the same communication's identifier
pong = Pong(peer.node._id)
pong.setidentifier(self.getidentifier())
pong.send(peer, reqaddr, reqport)
class Pong(RemoteRequest):
def __init__(self, nodeid):
super().__init__(nodeid)
class LocalFindNode(LocalRequest):
def __init__(self):
super().__init__()
def onreceive(self, peer, reqaddr, reqport):
log('Searched nodeid: {}, result:'.format(self.getparam('searchedid')))
for contact in peer.node.find_node(self.getparam('searchedid')):
print(contact)
def setnodeid(self, searchedid):
self.addparam("searchedid", searchedid)