Commit b42e2a56 authored by Vincent Pelletier's avatar Vincent Pelletier

Set connection's peer id before looking up handler method.

Otherwise, in the case of an unexpected packet, an incorrect message id
would be used.
Also, refuse setting a None peer_id on connection.
parent 8e2007e6
...@@ -464,6 +464,7 @@ class Connection(BaseConnection): ...@@ -464,6 +464,7 @@ class Connection(BaseConnection):
self.uuid = uuid self.uuid = uuid
def setPeerId(self, peer_id): def setPeerId(self, peer_id):
assert peer_id is not None
self.peer_id = peer_id self.peer_id = peer_id
def getPeerId(self): def getPeerId(self):
......
...@@ -46,12 +46,12 @@ class EventHandler(object): ...@@ -46,12 +46,12 @@ class EventHandler(object):
def dispatch(self, conn, packet, kw={}): def dispatch(self, conn, packet, kw={}):
"""This is a helper method to handle various packet types.""" """This is a helper method to handle various packet types."""
try: try:
conn.setPeerId(packet.getId())
try: try:
method = getattr(self, packet.handler_method_name) method = getattr(self, packet.handler_method_name)
except AttributeError: except AttributeError:
raise UnexpectedPacketError('no handler found') raise UnexpectedPacketError('no handler found')
args = packet.decode() or () args = packet.decode() or ()
conn.setPeerId(packet.getId())
method(conn, *args, **kw) method(conn, *args, **kw)
except UnexpectedPacketError, e: except UnexpectedPacketError, e:
self.__unexpectedPacket(conn, packet, *e.args) self.__unexpectedPacket(conn, packet, *e.args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment