Esempio n. 1
0
    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_ping(self, msg: PingMessage):
        nonce = msg.nonce()
        assumed_request_time = time.time(
        ) - nonce_generator.get_timestamp_from_nonce(nonce)
        self.inbound_peer_latency = assumed_request_time
        hooks.add_measurement(self.peer_desc, MeasurementType.PING_INCOMING,
                              assumed_request_time, self.peer_id)

        self.enqueue_msg(
            PongMessage(nonce=nonce, timestamp=nonce_generator.get_nonce()))
Esempio n. 3
0
 def send_ping(self):
     """
     Send a ping (and reschedule if called from alarm queue)
     """
     if self.can_send_pings and not self.state & ConnectionState.MARK_FOR_CLOSE:
         nonce = nonce_generator.get_nonce()
         msg = PingMessage(nonce=nonce)
         self.enqueue_msg(msg)
         self.ping_message_timestamps.add(nonce, time.time())
         return self.ping_interval_s
     return constants.CANCEL_ALARMS
 def pong_message(self) -> PongMessage:
     return PongMessage(nonce_generator.get_nonce())
 def ping_message(self) -> AbstractMessage:
     nonce = nonce_generator.get_nonce()
     self.ping_message_timestamps.add(nonce, time.time())
     return PingMessage(nonce)