diff --git a/neo/handler.py b/neo/handler.py index f6f39b128b90c312283d506c17e23f9505faf224..00f33aeb54e7cf9b6c8c4735d8d38b4dad499339 100644 --- a/neo/handler.py +++ b/neo/handler.py @@ -133,6 +133,9 @@ class EventHandler(object): # Packet handlers. + def notify(self, conn, message): + logging.info('notification from %s:%d: %s', *(conn.getAddress(), message)) + def requestIdentification(self, conn, node_type, uuid, address, name): raise UnexpectedPacketError diff --git a/neo/protocol.py b/neo/protocol.py index eadf8a2fd4d4b1b85dd57516a52e5e42fb7eaa3e..f2e49bdbb7b81bf67d51d7ad9c4af88c24d3823c 100644 --- a/neo/protocol.py +++ b/neo/protocol.py @@ -303,6 +303,15 @@ class Packet(object): def getAnswerClass(self): return self._answer +class Notify(Packet): + """ + General purpose notification (remote logging) + """ + def _encode(self, message): + return message + + def _decode(self, body): + return (body, ) class Ping(Packet): """ @@ -310,7 +319,6 @@ class Ping(Packet): """ pass - class Pong(Packet): """ Notify being alive. Any -> Any. @@ -1536,6 +1544,7 @@ class PacketRegistry(dict): # packets registration Error = register(0x8000, Error) + Notify = register(0x0032, Notify) Ping, Pong = register( 0x0001, Ping, diff --git a/neo/tests/__init__.py b/neo/tests/__init__.py index a25be6c9610f6b7f6b763c937dfc0e82aafa5011..f583ae43f5308cd69674b76be5785153033d80fe 100644 --- a/neo/tests/__init__.py +++ b/neo/tests/__init__.py @@ -250,6 +250,9 @@ class NeoTestBase(unittest.TestCase): return packet.decode() return packet + def checkNotify(self, conn, **kw): + return self.checkNotifyPacket(conn, Packets.Notify, **kw) + def checkNotifyNodeInformation(self, conn, **kw): return self.checkNotifyPacket(conn, Packets.NotifyNodeInformation, **kw)