]> git.mxchange.org Git - quix0rs-apt-p2p.git/blob - knode.py
52abbed41f81d217b029e578579868274faade69
[quix0rs-apt-p2p.git] / knode.py
1 from node import Node
2 from twisted.internet.defer import Deferred
3 from xmlrpcclient import XMLRPCClientFactory as factory
4 from const import reactor
5 from base64 import encodestring as encode
6
7 class KNode(Node):
8     def ping(self, sender):
9         df = Deferred()
10         f = factory('ping', (sender,), df.callback, df.errback)
11         reactor.connectTCP(self.host, self.port, f)
12         return df
13     def findNode(self, target, sender):
14         df = Deferred()
15         f = factory('find_node', (target, sender), df.callback, df.errback)
16         reactor.connectTCP(self.host, self.port, f)
17         return df
18     def storeValue(self, key, value, sender):
19         df = Deferred()
20         f = factory('store_value', (encode(key), encode(value), sender), df.callback, df.errback)
21         reactor.connectTCP(self.host, self.port, f)
22         return df
23     def findValue(self, key, sender):
24         df = Deferred()
25         f = factory('find_value', (encode(key), sender), df.callback, df.errback)
26         reactor.connectTCP(self.host, self.port, f)
27         return df