def _new_version(self): self.start_height = 888 caps = [ capabilities.FullNodeCapability(start_height=self.start_height), capabilities.ServerCapability( capabilities.NodeCapabilityType.TCPSERVER, 10333) ] return payloads.VersionPayload(nonce=123, user_agent="NEO3-MOCK-CLIENT", capabilities=caps)
def _recv_data(self): caps = [capabilities.FullNodeCapability(0)] m_send_version = message.Message(msg_type=message.MessageType.VERSION, payload=payloads.VersionPayload( nonce=123, user_agent="NEO3-MOCK-CLIENT", capabilities=caps)) m_verack = message.Message(msg_type=message.MessageType.VERACK) yield m_send_version.to_array() yield m_verack.to_array()
async def test_sending_addresses(self): n = await node.NeoNode.connect_to('127.0.0.1', 40333) await n.send_address_list([ payloads.NetworkAddress( host='127.0.0.1', timestamp=0, capabilities=[ capabilities.FullNodeCapability(start_height=123) ]) ]) await asyncio.sleep(100)
def __init__(self, loop, hostaddr: str, port: int): super(NeoNodeSocketMock, self).__init__() self.type = socket.SOCK_STREAM self.recv_buffer = bytearray() self.loop = loop self.hostaddr = hostaddr self.port = port self.recv_data = self._recv_data() caps = [capabilities.FullNodeCapability(0), capabilities.ServerCapability(n_type=capabilities.NodeCapabilityType.TCPSERVER, port=10333)] self.m_send_version = message.Message(msg_type=message.MessageType.VERSION, payload=payloads.VersionPayload(nonce=123, user_agent="NEO3-MOCK-CLIENT", capabilities=caps)) self.m_verack = message.Message(msg_type=message.MessageType.VERACK)
async def _do_handshake( self) -> Tuple[bool, Optional[payloads.DisconnectReason]]: caps: List[capabilities.NodeCapability] = [ capabilities.FullNodeCapability(0) ] # TODO: fix nonce and port if a service is running send_version = message.Message(msg_type=message.MessageType.VERSION, payload=payloads.VersionPayload.create( nonce=123, user_agent="NEO3-PYTHON", capabilities=caps)) await self.send_message(send_version) m = await self.read_message(timeout=3) if not m or m.type != message.MessageType.VERSION: await self.disconnect( payloads.DisconnectReason.HANDSHAKE_VERSION_ERROR) return (False, payloads.DisconnectReason.HANDSHAKE_VERSION_ERROR) if not self._validate_version(m.payload): await self.disconnect( payloads.DisconnectReason.HANDSHAKE_VERSION_ERROR) return (False, payloads.DisconnectReason.HANDSHAKE_VERSION_ERROR) m_verack = message.Message(msg_type=message.MessageType.VERACK) await self.send_message(m_verack) m = await self.read_message(timeout=3) if not m or m.type != message.MessageType.VERACK: await self.disconnect( payloads.DisconnectReason.HANDSHAKE_VERACK_ERROR) return (False, payloads.DisconnectReason.HANDSHAKE_VERACK_ERROR) logger.debug( f"Connected to {self.version.user_agent} @ {self.address.address}: {self.best_height}." ) msgrouter.on_node_connected(self) return (True, None)