log packet encoding errors and warn if the transport is not connected

This commit is contained in:
Jack Robison 2018-02-20 13:43:36 -05:00
parent b4bc5e2110
commit 87c69742cd
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -214,8 +214,9 @@ class KademliaProtocol(protocol.DatagramProtocol):
try:
msgPrimitive = self._encoder.decode(datagram)
message = self._translator.fromPrimitive(msgPrimitive)
except (encoding.DecodeError, ValueError):
except (encoding.DecodeError, ValueError) as err:
# We received some rubbish here
log.exception("Decode error: %s", err)
return
except (IndexError, KeyError):
log.warning("Couldn't decode dht datagram from %s", address)
@ -359,6 +360,8 @@ class KademliaProtocol(protocol.DatagramProtocol):
else:
log.error("DHT socket error: %s (%i)", err.message, err.errno)
raise err
else:
log.warning("transport not connected!")
def _sendResponse(self, contact, rpcID, response):
""" Send a RPC response to the specified contact