added stun rpc method
This commit is contained in:
parent
abf5fe19ad
commit
10925520c4
@ -172,7 +172,7 @@ class Server(object):
|
|||||||
are acceptable - hostnames will cause an error.
|
are acceptable - hostnames will cause an error.
|
||||||
"""
|
"""
|
||||||
# if the transport hasn't been initialized yet, wait a second
|
# if the transport hasn't been initialized yet, wait a second
|
||||||
if self.protocol.transport == None:
|
if self.protocol.transport is None:
|
||||||
reactor.callLater(1, self.bootstrap, addrs)
|
reactor.callLater(1, self.bootstrap, addrs)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -189,6 +189,22 @@ class Server(object):
|
|||||||
ds[addr] = self.protocol.ping(addr, self.node.id)
|
ds[addr] = self.protocol.ping(addr, self.node.id)
|
||||||
return deferredDict(ds).addCallback(initTable)
|
return deferredDict(ds).addCallback(initTable)
|
||||||
|
|
||||||
|
def inetVisibleIP(self):
|
||||||
|
"""
|
||||||
|
Get the internet visible IP's of this node as other nodes see it.
|
||||||
|
|
||||||
|
@return: An C{list} of IP's. If no one can be contacted, then the
|
||||||
|
C{list} will be empty.
|
||||||
|
"""
|
||||||
|
def handle(results):
|
||||||
|
ips = [ result[0] for result in results if result is not None ]
|
||||||
|
self.log.debug("other nodes think our ip is %s" % str(ips))
|
||||||
|
return ips
|
||||||
|
ds = []
|
||||||
|
for neighbor in self.bootstrappableNeighbors():
|
||||||
|
ds.append(self.protocol.router.stun(neighbor))
|
||||||
|
return defer.gatherResults(ds).addCallback(handle)
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
"""
|
"""
|
||||||
Get a key if the network has it.
|
Get a key if the network has it.
|
||||||
|
@ -23,6 +23,9 @@ class KademliaProtocol(RPCProtocol):
|
|||||||
ids.append(random.randint(*bucket.range))
|
ids.append(random.randint(*bucket.range))
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
|
def rpc_stun(self, sender):
|
||||||
|
return sender
|
||||||
|
|
||||||
def rpc_ping(self, sender, nodeid):
|
def rpc_ping(self, sender, nodeid):
|
||||||
source = Node(nodeid, sender[0], sender[1])
|
source = Node(nodeid, sender[0], sender[1])
|
||||||
self.router.addContact(source)
|
self.router.addContact(source)
|
||||||
|
Loading…
Reference in New Issue
Block a user