Example #1
0
 def send_data_packet(self, route_address, data_dict):
     encrypt_data = utils.json_encrypt(secret_key, json.dumps(data_dict))
     data_packet = packet.Packet.gen_packet('DATA', encrypt_data)
     if DEBUG:
         print '[LOG][%s]: create a DATA packet which uuid is %s' % (time.ctime(), data_packet.uuid.encode('hex'))
     self.__caching_dict[data_packet.uuid.encode('hex')] = data_packet
     self.__send_post_packet(route_address, data_packet.uuid.encode('hex'))
Example #2
0
 def send_data_packet(self, route_address, data_dict):
     encrypt_data = utils.json_encrypt(secret_key, json.dumps(data_dict))
     data_packet = packet.Packet.gen_packet('DATA', encrypt_data)
     if DEBUG:
         print '[LOG][%s]: create a DATA packet which uuid is %s' % (
             time.ctime(), data_packet.uuid.encode('hex'))
     self.__caching_dict[data_packet.uuid.encode('hex')] = data_packet
     self.__send_post_packet(route_address, data_packet.uuid.encode('hex'))
Example #3
0
 def __send_ack_packet(self, route_address, packet_uuid_hex):
     payload = {'uuid': packet_uuid_hex, 'timestamp': time.time() * 100}
     encrypt_data = utils.json_encrypt(secret_key, json.dumps(payload))
     ack_packet = packet.Packet.gen_packet('ACK', encrypt_data)
     self.__sending_queue.put((route_address, ack_packet))
Example #4
0
 def test_encrypt_and_decrypt(self):
     key_hex = utils.gen_aes_key_hex()
     content = json.dumps({'command': 'test'})
     cipher_string = utils.json_encrypt(key_hex, content)
     after = utils.json_decrypt(key_hex, cipher_string)
     self.assertEqual(after, content, 'test encrypt and decrypt fail')
Example #5
0
 def __send_ack_packet(self, route_address, packet_uuid_hex):
     payload = {'uuid': packet_uuid_hex, 'timestamp': time.time() * 100}
     encrypt_data = utils.json_encrypt(secret_key, json.dumps(payload))
     ack_packet = packet.Packet.gen_packet('ACK', encrypt_data)
     self.__sending_queue.put((route_address, ack_packet))
Example #6
0
 def test_encrypt_and_decrypt(self):
     key_hex = utils.gen_aes_key_hex()
     content = json.dumps({'command': 'test'})
     cipher_string = utils.json_encrypt(key_hex, content)
     after = utils.json_decrypt(key_hex, cipher_string)
     self.assertEqual(after, content, 'test encrypt and decrypt fail')