class FindNode(ActionBase):
""" find node action merits it's own class as it is a long running stateful process """
def handleGotNodes(self, args):
- args, conn = args
l, sender = args
- if conn['host']:
- sender['host'] = conn['host']
sender = Node().initWithDict(sender)
self.table.table.insertNode(sender)
if self.finished or self.answered.has_key(sender.id):
class GetValue(FindNode):
""" get value task """
def handleGotNodes(self, args):
- args, conn = args
l, sender = args
- if conn['host']:
- sender['host'] = conn['host']
sender = Node().initWithDict(sender)
self.table.table.insertNode(sender)
if self.finished or self.answered.has_key(sender.id):
def _notStaleNodeHandler(sender, old=old):
""" called when we get a pong from the old node """
- sender, conn = sender
- if conn['host']:
- sender['host'] = conn['host']
sender = Node().initWithDict(sender)
if sender.id == old.id:
self.table.justSeenNode(old)
self.transport.write('\r\n')
def handleResponse(self, buf):
- try:
- self.thehost = self.transport.getHost()[1]
- except:
- self.thehost = None
try:
args, name = loads(buf)
except Exception, e:
print "response decode error: " + `e`
self.d.errback()
else:
- l = []
- for i in args:
- l.append(i)
- l.append({'host' : self.thehost})
- apply(self.d.callback, (l,))
+ apply(self.d.callback, args)
class XMLRPCClientFactory(ClientFactory):
def __init__(self, method, args, callback=None, errback=None):