Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | class P2PConnection(asyncio.Protocol): | ||||
def data_received(self, t): | def data_received(self, t): | ||||
"""asyncio callback when data is read from the socket.""" | """asyncio callback when data is read from the socket.""" | ||||
with mininode_lock: | with mininode_lock: | ||||
if len(t) > 0: | if len(t) > 0: | ||||
self.recvbuf += t | self.recvbuf += t | ||||
while True: | while True: | ||||
msg = self._on_data() | msg = self._on_data() | ||||
if msg == None: | if msg is None: | ||||
break | break | ||||
self.on_message(msg) | self.on_message(msg) | ||||
def _on_data(self): | def _on_data(self): | ||||
"""Try to read P2P messages from the recv buffer. | """Try to read P2P messages from the recv buffer. | ||||
This method reads data from the buffer in a loop. It deserializes, | This method reads data from the buffer in a loop. It deserializes, | ||||
parses and verifies the P2P header, then passes the P2P payload to | parses and verifies the P2P header, then passes the P2P payload to | ||||
▲ Show 20 Lines • Show All 455 Lines • Show Last 20 Lines |