Commit bf2c5aee authored by Julien Muchembled's avatar Julien Muchembled

Do not notify about malformed packet in order to avoid bounces

parent 4f1b6c28
...@@ -499,16 +499,15 @@ class Connection(BaseConnection): ...@@ -499,16 +499,15 @@ class Connection(BaseConnection):
def analyse(self): def analyse(self):
"""Analyse received data.""" """Analyse received data."""
while True: try:
# parse a packet while True:
try:
packet = Packets.parse(self.read_buf, self._parser_state) packet = Packets.parse(self.read_buf, self._parser_state)
if packet is None: if packet is None:
break break
except PacketMalformedError, msg: self._queue.append(packet)
self.getHandler()._packetMalformed(self, msg) except PacketMalformedError, e:
return logging.error('malformed packet from %r: %s', self, e)
self._queue.append(packet) self._closure()
def hasPendingMessages(self): def hasPendingMessages(self):
""" """
......
...@@ -56,12 +56,10 @@ class EventHandler(object): ...@@ -56,12 +56,10 @@ class EventHandler(object):
except UnexpectedPacketError, e: except UnexpectedPacketError, e:
if not conn.isClosed(): if not conn.isClosed():
self.__unexpectedPacket(conn, packet, *e.args) self.__unexpectedPacket(conn, packet, *e.args)
except PacketMalformedError: except PacketMalformedError, e:
if not conn.isClosed(): logging.error('malformed packet from %r: %s', conn, e)
logging.error('malformed packet from %r', conn) conn.close()
conn.notify(Packets.Notify('Malformed packet: %r' % (packet, ))) # self.peerBroken(conn)
conn.abort()
# self.peerBroken(conn)
except BrokenNodeDisallowedError: except BrokenNodeDisallowedError:
if not conn.isClosed(): if not conn.isClosed():
conn.answer(Errors.BrokenNode('go away')) conn.answer(Errors.BrokenNode('go away'))
......
...@@ -477,12 +477,12 @@ class ConnectionTests(NeoUnitTestBase): ...@@ -477,12 +477,12 @@ class ConnectionTests(NeoUnitTestBase):
def test_Connection_analyse3(self): def test_Connection_analyse3(self):
# give a bad packet, won't be decoded # give a bad packet, won't be decoded
bc = self._makeConnection() bc = self._makeConnection()
bc._queue = Mock() p = Packets.Ping()
self._appendToReadBuf(bc, 'datadatadatadata') p.setId(1)
self._appendToReadBuf(bc, '%s%sdatadatadatadata' % p.encode())
bc.analyse() bc.analyse()
self.assertEqual(len(bc._queue.mockGetNamedCalls("append")), 0) self._checkPacketReceived(1) # ping packet
self.assertEqual( self._checkClose(1) # malformed packet
len(self.handler.mockGetNamedCalls("_packetMalformed")), 1)
def test_Connection_analyse4(self): def test_Connection_analyse4(self):
# give an expected packet # give an expected packet
......
...@@ -59,8 +59,7 @@ class HandlerTests(NeoUnitTestBase): ...@@ -59,8 +59,7 @@ class HandlerTests(NeoUnitTestBase):
raise PacketMalformedError('message') raise PacketMalformedError('message')
self.setFakeMethod(fake) self.setFakeMethod(fake)
self.handler.dispatch(conn, packet) self.handler.dispatch(conn, packet)
self.checkNotify(conn) self.checkClosed(conn)
self.checkAborted(conn)
# raise BrokenNodeDisallowedError # raise BrokenNodeDisallowedError
conn.mockCalledMethods = {} conn.mockCalledMethods = {}
def fake(c): def fake(c):
......
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