def PING(self, timestamp_str):
     self.send_signed("PONG\t%s" % utils.utcstamp().strftime('%Y-%m-%d %H:%M:%S.%f'))
     if timestamp_str:
         # We cannot adjust for latency since we don't ping the client
         parsed_time = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S.%f')
         self.client_timedelta = utils.utcstamp() - parsed_time
     return
 def keepalive_callback(self):
     # Immediately register another callback for a later time
     self.keepalive_timer = reactor.callLater(self.keepalive_timeout.seconds, self.keepalive_callback)
     if (utils.utcstamp() - self.last_activity < self.keepalive_timeout):
         # We're good
         return
     self.send_signed("KEEPALIVE\t%s" % utils.utcstamp().strftime('%Y-%m-%d %H:%M:%S.%f'))
Beispiel #3
0
    def PONG(self, timestamp_str):
        # Safety, make sure we adjust latency only if we called the ping method
        if self.pinged:
            self.latency = utils.utcstamp() - self.pinged
        self.pinged = None

        # Calculate delta to server time
        if self.latency:
            parsed_time = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S.%f')
            self.server_timedelta = utils.utcstamp() - parsed_time - self.latency
    def lineReceived(self, data):
        print "got data: %s" % data
        message = self.verify_data(data)
        if message == False:
            self.send_signed("ERROR\tHash mismatch")
            self.transport.loseConnection()
            return

        self.last_activity = utils.utcstamp()
        self.parse_message(message)
 def send_signed(self, message):
     raw = self.hmac_wrapper.sign(message) + "\n";
     print "Sending: %s" % raw
     self.transport.write(raw)
     self.last_activity = utils.utcstamp()
Beispiel #6
0
 def ping(self):
     self.send_signed("PING\t%s" % utils.utcstamp().strftime('%Y-%m-%d %H:%M:%S.%f'))
     self.pinged = utils.utcstamp()