Пример #1
0
 def __handle_packet(self, route_address, now_packet):
     command = now_packet.get_command_string()
     decrypt_data = json.loads(utils.json_decrypt(secret_key, now_packet.payload))
     if command == 'POST':
         self.__send_get_data_packet(route_address, decrypt_data.get('uuid', '\0' * 16))
     elif command == 'ACK':
         if DEBUG:
             print '[LOG][%s]: the data packet %s has been received by %s!' % (
                 time.ctime(), decrypt_data.get('uuid'), route_address)
         if decrypt_data.get('uuid') in self.__caching_dict:
             del self.__caching_dict[decrypt_data.get('uuid')]
     elif command == 'GETDATA':
         self.__sending_queue.put((route_address, self.__caching_dict.get(decrypt_data.get('uuid'))))
     elif command == 'DATA':
         interface_dict.get(decrypt_data.get('command'))(worker=self, **decrypt_data.get('options', {}))
Пример #2
0
 def __handle_packet(self, route_address, now_packet):
     command = now_packet.get_command_string()
     decrypt_data = json.loads(
         utils.json_decrypt(secret_key, now_packet.payload))
     if command == 'POST':
         self.__send_get_data_packet(route_address,
                                     decrypt_data.get('uuid', '\0' * 16))
     elif command == 'ACK':
         if DEBUG:
             print '[LOG][%s]: the data packet %s has been received by %s!' % (
                 time.ctime(), decrypt_data.get('uuid'), route_address)
         if decrypt_data.get('uuid') in self.__caching_dict:
             del self.__caching_dict[decrypt_data.get('uuid')]
     elif command == 'GETDATA':
         self.__sending_queue.put(
             (route_address,
              self.__caching_dict.get(decrypt_data.get('uuid'))))
     elif command == 'DATA':
         interface_dict.get(decrypt_data.get('command'))(worker=self,
                                                         **decrypt_data.get(
                                                             'options', {}))
Пример #3
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')
Пример #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')