]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p_Khashmir/krpc.py
Use python-debian's new debian package instead of debian_bundle
[quix0rs-apt-p2p.git] / apt_p2p_Khashmir / krpc.py
index b151a5527f15b6f210f14e83b565a790cfe750b7..9290cac60822ab44b5ce0663a3629ffee879d14c 100644 (file)
@@ -100,6 +100,8 @@ def verifyMessage(msg):
             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")
@@ -117,6 +119,8 @@ def verifyMessage(msg):
         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.
@@ -349,7 +353,7 @@ class KRPC:
             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
 
@@ -357,8 +361,7 @@ class KRPC:
         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):
@@ -379,6 +382,8 @@ class KRPC:
                     log.msg('Got a Krpc error while running: krpc_%s' % msg[REQ])
                     if e[0] != KRPC_ERROR_INVALID_TOKEN:
                         log.err(e)
+                    else:
+                        log.msg('Node sent us an invalid token, not storing')
                     self.stats.errorAction(msg[REQ])
                     olen = self._sendResponse(msg[REQ], addr, msg[TID], ERR,
                                               [e[0], e[1]])
@@ -427,7 +432,7 @@ class KRPC:
             else:
                 # no tid, this transaction was finished already...
                 log.msg('received an error %r from %r for completed request: %r' %
-                        (msg[ERR], msg[RSP]['id'], msg[TID]))
+                        (msg[ERR], addr, msg[TID]))
         else:
             # Received an unknown message type
             if self.config.get('SPEW', False):