def handleGotNodes(self, args):
args, conn = args
l, sender = args
- sender['host'] = conn['host']
+ 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):
l = self.found.values()
l.sort(self.sort)
- for node in l:
+ for node in l[:K]:
if node.id == self.target:
self.finished=1
return self.callback([node])
- if not self.queried.has_key(node.id) and node.id != self.table.node.id:
+ if (not self.queried.has_key(node.id)) and node.id != self.table.node.id:
#xxxx t.timeout = time.time() + FIND_NODE_TIMEOUT
df = node.findNode(self.target, self.table.node.senderDict())
df.addCallbacks(self.handleGotNodes, self.makeMsgFailed(node))
def makeMsgFailed(self, node):
def defaultGotNodes(err, self=self, node=node):
self.table.table.nodeFailed(node)
- if self.finished:
- return
self.outstanding = self.outstanding - 1
self.schedule()
return defaultGotNodes
def handleGotNodes(self, args):
args, conn = args
l, sender = args
- sender['host'] = conn['host']
+ 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):
l = self.found.values()
l.sort(self.sort)
- for node in l:
- if not self.queried.has_key(node.id) and node.id != self.table.node.id:
+ for node in l[:K]:
+ if (not self.queried.has_key(node.id)) and node.id != self.table.node.id:
#xxx t.timeout = time.time() + GET_VALUE_TIMEOUT
df = node.findValue(self.target, self.table.node.senderDict())
df.addCallback(self.handleGotNodes)