if self.finished or self.answered.has_key(node.id):
# a day late and a dollar short
return
- self.answered[node.id] = 1
- self.processResponse(dict)
+ try:
+ # Process the response
+ self.processResponse(dict)
+ self.answered[node.id] = 1
+ except Exception, e:
+ # Unexpected error with the response
+ log.msg("action %s failed on %s/%s: %r" % (self.action, node.host, node.port, e))
+ if node.id != self.caller.node.id:
+ self.caller.nodeFailed(node)
+ self.failed[node.id] = 1
if self.outstanding.has_key(node.id):
self.outstanding_results -= self.outstanding[node.id]
del self.outstanding[node.id]
Not called by default, but suitable for being called by
L{processResponse} in a recursive node search.
"""
+ if nodes and type(nodes) != list:
+ raise ValueError, "got a malformed response, from bittorrent perhaps"
for compact_node in nodes:
node_contact = uncompact(compact_node)
node = self.caller.Node(node_contact)
raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "response not specified")
if type(msg[RSP]) != dict:
raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "response is not a dictionary")
+# if 'nodes' in msg[RSP] and type(msg[RSP]['nodes']) != list:
+# raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "wrong type of node, this is not bittorrent")
elif msg[TYP] == ERR:
if ERR not in msg:
raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "error not specified")
raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "no transaction ID specified")
if type(msg[TID]) != str:
raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "transaction id is not a string")
+ if len(msg[TID]) != 20:
+ raise KrpcError, (KRPC_ERROR_MALFORMED_PACKET, "wrong type of node, this is not bittorrent")
class hostbroker(protocol.DatagramProtocol):
"""The factory for the KRPC protocol.
msg = bdecode(data)
except Exception, e:
if self.config.get('SPEW', False):
- log.msg("krpc bdecode error: ")
+ log.msg("krpc bdecode error from %r: " % (addr, ))
log.err(e)
return
try:
verifyMessage(msg)
except Exception, e:
- log.msg("krpc message verification error: ")
- log.err(e)
+ log.msg("krpc message verification error from %r: %r" % (addr, e))
return
if self.config.get('SPEW', False):
@raise ValueError: if the compact representation doesn't exist
"""
if (len(s) != HASH_LENGTH+6):
- raise ValueError
+ raise ValueError, "not compact node info: %r" % (s, )
id = s[:HASH_LENGTH]
host = '.'.join([str(ord(i)) for i in s[HASH_LENGTH:(HASH_LENGTH+4)]])
port = (ord(s[HASH_LENGTH+4]) << 8) | ord(s[HASH_LENGTH+5])