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