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): ...@@ -32,15 +32,6 @@ class EventHandler(object):
def __repr__(self): def __repr__(self):
return self.__class__.__name__ 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): def __unexpectedPacket(self, conn, packet, message=None):
"""Handle an unexpected packet.""" """Handle an unexpected packet."""
if message is None: if message is None:
...@@ -66,8 +57,11 @@ class EventHandler(object): ...@@ -66,8 +57,11 @@ class EventHandler(object):
method(conn, *args) method(conn, *args)
except UnexpectedPacketError, e: except UnexpectedPacketError, e:
self.__unexpectedPacket(conn, packet, *e.args) self.__unexpectedPacket(conn, packet, *e.args)
except PacketMalformedError, e: except PacketMalformedError:
self._packetMalformed(conn, *e.args) logging.error('malformed packet from %s:%d', *(conn.getAddress()))
conn.notify(Packets.Notify('Malformed packet: %r' % (packet, )))
conn.abort()
self.peerBroken(conn)
except BrokenNodeDisallowedError: except BrokenNodeDisallowedError:
conn.answer(Errors.Broken('go away')) conn.answer(Errors.Broken('go away'))
conn.abort() conn.abort()
......
...@@ -33,7 +33,11 @@ class HandlerTests(NeoTestBase): ...@@ -33,7 +33,11 @@ class HandlerTests(NeoTestBase):
self.handler.packet_dispatch_table[self.fake_type] = method self.handler.packet_dispatch_table[self.fake_type] = method
def getFakePacket(self): def getFakePacket(self):
return Mock({'getType': self.fake_type, 'decode': ()}) return Mock({
'getType': self.fake_type,
'decode': (),
'__repr__': 'Fake Packet',
})
def checkFakeCalled(self): def checkFakeCalled(self):
method = self.handler.packet_dispatch_table[self.fake_type] method = self.handler.packet_dispatch_table[self.fake_type]
...@@ -60,7 +64,7 @@ class HandlerTests(NeoTestBase): ...@@ -60,7 +64,7 @@ class HandlerTests(NeoTestBase):
raise PacketMalformedError('message') raise PacketMalformedError('message')
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
self.checkErrorPacket(conn) self.checkNotify(conn)
self.checkAborted(conn) self.checkAborted(conn)
# raise BrokenNodeDisallowedError # raise BrokenNodeDisallowedError
conn.mockCalledMethods = {} 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