def test_loops(self): queues = gen_queue_dict() window = TxWindow(log_messages=True) settings = Settings(traffic_masking=True, tm_static_delay=0.001, tm_random_delay=0.001) gateway = Gateway() key_list = KeyList(nicks=['Bob', LOCAL_ID]) # Output Bob as existing contact queues[TM_NOISE_COMMAND_QUEUE].put( (C_N_HEADER + bytes(PADDING_LENGTH))) queues[TM_NOISE_PACKET_QUEUE].put( (P_N_HEADER + bytes(PADDING_LENGTH), True, True)) queues[WINDOW_SELECT_QUEUE].put(window.window_contacts) queues[SENDER_MODE_QUEUE].put(settings) queue_command(b'test', settings, queues) # Output command self.assertIsNone( sender_loop(queues, settings, gateway, key_list, unittest=True)) self.assertEqual(len(gateway.packets), 1) settings.traffic_masking = False queues[SENDER_MODE_QUEUE].put(settings) self.assertIsNone( sender_loop(queues, settings, gateway, key_list, unittest=True)) # Output Alice and Bob again self.assertEqual(len(gateway.packets), 1)
def queue_delayer(): """Place packets to queue after delay.""" time.sleep(0.01) queues[WINDOW_SELECT_QUEUE].put(window.window_contacts) time.sleep(0.01) queue_command(b'test', settings, queues) # 1 queue_message(user_input, window, settings, queues) # 2 queue_message(user_input, window, settings, queues) # 3 queue_command(b'test', settings, queues) # 4 queues[TM_NOISE_COMMAND_QUEUE].put((C_N_HEADER + bytes(PADDING_LENGTH))) # 5 queue_to_nc(UNENCRYPTED_DATAGRAM_HEADER + UNENCRYPTED_EXIT_COMMAND, queues[RELAY_PACKET_QUEUE]) # 6 queue_to_nc(UNENCRYPTED_DATAGRAM_HEADER + UNENCRYPTED_WIPE_COMMAND, queues[RELAY_PACKET_QUEUE]) # 7 queues[SENDER_MODE_QUEUE].put(settings)
def queue_delayer(): """Place datagrams into queue after delay.""" time.sleep(delay) queue_command(b'test', settings, queues) time.sleep(delay) queue_to_nc( PUBLIC_KEY_DATAGRAM_HEADER + TFC_PUBLIC_KEY_LENGTH * b'a' + nick_to_pub_key('Alice'), # 1 queues[RELAY_PACKET_QUEUE]) time.sleep(delay) queue_to_nc(UNENCRYPTED_DATAGRAM_HEADER + UNENCRYPTED_WIPE_COMMAND, queues[RELAY_PACKET_QUEUE]) # 2 time.sleep(delay) queue_to_nc(UNENCRYPTED_DATAGRAM_HEADER + UNENCRYPTED_EXIT_COMMAND, queues[RELAY_PACKET_QUEUE]) # 3 time.sleep(delay) queues[KEY_MANAGEMENT_QUEUE].put(( KDB_ADD_ENTRY_HEADER, LOCAL_PUBKEY, # 4 SYMMETRIC_KEY_LENGTH * b'a', SYMMETRIC_KEY_LENGTH * b'a', SYMMETRIC_KEY_LENGTH * b'a', SYMMETRIC_KEY_LENGTH * b'a')) time.sleep(delay) queue_message(user_input, window, settings, queues) # 5 time.sleep(delay) queue_message(user_input, window, settings, queues) # 6 time.sleep(delay) queues[KEY_MANAGEMENT_QUEUE].put( (KDB_ADD_ENTRY_HEADER, nick_to_pub_key('Alice'), SYMMETRIC_KEY_LENGTH * b'a', SYMMETRIC_KEY_LENGTH * b'a', SYMMETRIC_KEY_LENGTH * b'a', SYMMETRIC_KEY_LENGTH * b'a')) time.sleep(delay) queue_message(user_input, window, settings, queues) # 7 time.sleep(delay) queue_message(user_input, window, settings, queues) # 8 time.sleep(delay) queues[SENDER_MODE_QUEUE].put(settings)