def input_loop(queues: Dict[bytes, 'Queue[bytes]'], settings: 'Settings', gateway: 'Gateway', contact_list: 'ContactList', group_list: 'GroupList', master_key: 'MasterKey', onion_service: 'OnionService', stdin_fd: int) -> NoReturn: """Get input from user and process it accordingly. Running this loop as a process allows handling different functions including inputs, key exchanges, file loading and assembly packet generation, separate from assembly packet output. """ sys.stdin = os.fdopen(stdin_fd) window = TxWindow(contact_list, group_list) while True: with ignored(EOFError, FunctionReturn, KeyboardInterrupt): readline.set_completer( get_tab_completer(contact_list, group_list, settings, gateway)) readline.parse_and_bind('tab: complete') window.update_window(group_list) while not onion_service.is_delivered: export_onion_service_data(contact_list, settings, onion_service, gateway) while not contact_list.has_local_contact(): new_local_key(contact_list, settings, queues) while not contact_list.has_contacts(): add_new_contact(contact_list, group_list, settings, queues, onion_service) while not window.is_selected(): window.select_tx_window(settings, queues, onion_service, gateway) user_input = get_input(window, settings) if user_input.type == MESSAGE: queue_message(user_input, window, settings, queues) elif user_input.type == FILE: queue_file(window, settings, queues) elif user_input.type == COMMAND: process_command(user_input, window, contact_list, group_list, settings, queues, master_key, onion_service, gateway)
def test_file_queue_long_normal(self, *_): # Setup input_data = os.urandom(2000) with open('testfile.txt', 'wb+') as f: f.write(input_data) window = TxWindow(name='Alice', type=WIN_TYPE_CONTACT, type_print='contact', uid=nick_to_pub_key("Alice"), window_contacts=[create_contact('Alice')], log_messages=True) settings = Settings(traffic_masking=False, disable_gui_dialog=True, confirm_sent_files=True, multi_packet_random_delay=True) # Test self.assertIsNone(queue_file(window, settings, self.queues)) self.assertEqual(self.queues[RELAY_PACKET_QUEUE].qsize(), 1)
def test_file_queue_short_traffic_masking(self, *_): # Setup input_data = os.urandom(5) with open('testfile.txt', 'wb+') as f: f.write(input_data) window = TxWindow(name='Alice', type=WIN_TYPE_CONTACT, type_print='contact', uid=nick_to_pub_key("Alice"), log_messages=True) settings = Settings(traffic_masking=True, disable_gui_dialog=True) # Test self.assertIsNone(queue_file(window, settings, self.queues)) self.assertEqual(self.queues[TM_FILE_PACKET_QUEUE].qsize(), 1) q_data, log_messages, log_as_ph = self.queues[TM_FILE_PACKET_QUEUE].get() self.assertIsInstance(q_data, bytes) self.assertTrue(log_messages) self.assertTrue(log_as_ph)