Commit bd014457 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Send a notification when a malformed packet is received.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1899 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent f0aa363c
......@@ -32,15 +32,6 @@ class EventHandler(object):
def __repr__(self):
return self.__class__.__name__
def _packetMalformed(self, conn, message='', *args):
"""Called when a packet is malformed."""
args = (conn.getAddress()[0], conn.getAddress()[1], message)
logging.error('malformed packet from %s:%d: %s', *args)
response = Errors.ProtocolError(message)
conn.notify(response)
conn.abort()
self.peerBroken(conn)
def __unexpectedPacket(self, conn, packet, message=None):
"""Handle an unexpected packet."""
if message is None:
......@@ -66,8 +57,11 @@ class EventHandler(object):
method(conn, *args)
except UnexpectedPacketError, e:
self.__unexpectedPacket(conn, packet, *e.args)
except PacketMalformedError, e:
self._packetMalformed(conn, *e.args)
except PacketMalformedError:
logging.error('malformed packet from %s:%d', *(conn.getAddress()))
conn.notify(Packets.Notify('Malformed packet: %r' % (packet, )))
conn.abort()
self.peerBroken(conn)
except BrokenNodeDisallowedError:
conn.answer(Errors.Broken('go away'))
conn.abort()
......
......@@ -33,7 +33,11 @@ class HandlerTests(NeoTestBase):
self.handler.packet_dispatch_table[self.fake_type] = method
def getFakePacket(self):
return Mock({'getType': self.fake_type, 'decode': ()})
return Mock({
'getType': self.fake_type,
'decode': (),
'__repr__': 'Fake Packet',
})
def checkFakeCalled(self):
method = self.handler.packet_dispatch_table[self.fake_type]
......@@ -60,7 +64,7 @@ class HandlerTests(NeoTestBase):
raise PacketMalformedError('message')
self.setFakeMethod(fake)
self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn)
self.checkNotify(conn)
self.checkAborted(conn)
# raise BrokenNodeDisallowedError
conn.mockCalledMethods = {}
......
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