def msg_pong(self, msg: PongMessage): nonce = msg.nonce() if nonce in self.ping_message_timestamps.contents: request_msg_timestamp = self.ping_message_timestamps.contents[nonce] request_response_time = time.time() - request_msg_timestamp self.log_trace("Pong for nonce {} had response time: {}", msg.nonce(), request_response_time) hooks.add_measurement(self.peer_desc, MeasurementType.PING, request_response_time) elif nonce is not None: self.log_debug("Pong message had no matching ping request. Nonce: {}", nonce)
def test_pong_message_timestamp(self): t0 = nonce_generator.get_nonce() time.sleep(0) t1 = nonce_generator.get_nonce() msg = PongMessage(t0, t1) self.assertEqual(msg.nonce(), t0) self.assertEqual(msg.timestamp(), t1) new_msg = PongMessage(buf=msg.buf) self.assertEqual(msg.nonce(), new_msg.nonce())
def msg_pong(self, msg: PongMessage): super(InternalNodeConnection, self).msg_pong(msg) nonce = msg.nonce() timestamp = msg.timestamp() if timestamp: self.inbound_peer_latency = time.time( ) - nonce_generator.get_timestamp_from_nonce(timestamp) if nonce in self.ping_message_timestamps.contents: request_msg_timestamp = self.ping_message_timestamps.contents[ nonce] request_response_time = time.time() - request_msg_timestamp if nonce in self._nonce_to_network_num: self.sync_ping_latencies[ self._nonce_to_network_num[nonce]] = request_response_time if request_response_time > constants.PING_PONG_TRESHOLD: self.log_debug( "Ping/pong exchange nonce {} took {:.2f} seconds to complete.", msg.nonce(), request_response_time) else: self.log_trace( "Ping/pong exchange nonce {} took {:.2f} seconds to complete.", msg.nonce(), request_response_time) hooks.add_measurement(self.peer_desc, MeasurementType.PING, request_response_time, self.peer_id) if timestamp: assumed_peer_response_time = nonce_generator.get_timestamp_from_nonce( timestamp) - request_msg_timestamp hooks.add_measurement(self.peer_desc, MeasurementType.PING_OUTGOING, assumed_peer_response_time, self.peer_id) elif nonce is not None: self.log_debug( "Pong message had no matching ping request. Nonce: {}", nonce)
def old_pong_message(self, original_message: PongMessage) -> PongMessageV13: return PongMessageV13(original_message.nonce())
def test_pong_response_msg(self): pong = PongMessage(nonce=50) self.assertEqual(50, pong.nonce()) msg = bloxroute_message_factory.create_message_from_buffer(pong.buf)