def test_get_tab_complete_list(self): tab_complete_list = [ 'about', 'add ', 'all', 'clear', 'cmd', 'create ', 'exit', 'export ', 'false', 'file', 'fingerprints', 'group ', 'help', 'history ', 'join ', 'localkey', 'logging ', 'msg ', 'names', 'nick ', 'notify ', 'passwd ', 'psk', 'reset', 'rm', 'rmlogs ', 'set ', 'settings', 'store ', 'true', 'unread', 'key1 ', 'key2 ', '[email protected] ', '[email protected] ', 'Alice ', '[email protected] ', 'Bob ', 'testgroup ', 'whisper ' ] self.assertEqual( set( get_tab_complete_list(self.contact_list, self.group_list, self.settings)), set(tab_complete_list)) self.assertIsInstance( get_tab_completer(self.contact_list, self.group_list, self.settings), types.FunctionType) completer = get_tab_completer(self.contact_list, self.group_list, self.settings) options = completer('a', state=0) self.assertEqual(options, 'about') self.assertIsNone(completer('a', state=5))
def tx_loop( settings: 'Settings', queues: Dict[bytes, 'Queue'], gateway: 'Gateway', contact_list: 'ContactList', group_list: 'GroupList', master_key: 'MasterKey', file_no: int # stdin input file descriptor ) -> None: """Get input from user and process it accordingly. Tx side of TFC runs two processes -- input and output loop -- separate from one another. This approach allows queueing assembly packets and their output based on priority of different packets. tx_loop handles TxM-side functions excluding message encryption, output and hash ratchet key/counter updates in key_list database and log file writes. """ sys.stdin = os.fdopen(file_no) window = Window(contact_list, group_list) while True: try: readline.set_completer( get_tab_completer(contact_list, group_list, settings)) readline.parse_and_bind('tab: complete') window.update_group_win_members(group_list) while not contact_list.has_local_contact(): new_local_key(contact_list, settings, queues, gateway) while not contact_list.has_contacts(): add_new_contact(contact_list, group_list, settings, queues, gateway) while not window.is_selected(): window.select_tx_window(settings, queues) user_input = UserInput(window, settings) if user_input.type == 'message': queue_message(user_input, window, settings, queues[MESSAGE_PACKET_QUEUE]) elif user_input.type == 'file': queue_file(window, settings, queues[FILE_PACKET_QUEUE], gateway) elif user_input.type == 'command': process_command(user_input, window, settings, queues, contact_list, group_list, gateway, master_key) except (EOFError, FunctionReturn, KeyboardInterrupt): pass
def test_get_tab_complete_list(self): tab_complete_list = [ a + ' ' for a in self.contact_list.get_list_of_addresses() ] tab_complete_list += [ i + ' ' for i in self.group_list.get_list_of_hr_group_ids() ] tab_complete_list += [s + ' ' for s in self.settings.key_list] tab_complete_list += [s + ' ' for s in self.gateway.settings.key_list] tc_list = get_tab_complete_list(self.contact_list, self.group_list, self.settings, self.gateway) self.assertTrue(set(tab_complete_list) < set(tc_list)) self.assertIsInstance( get_tab_completer(self.contact_list, self.group_list, self.settings, self.gateway), types.FunctionType) completer = get_tab_completer(self.contact_list, self.group_list, self.settings, self.gateway) options = completer('a', state=0) self.assertEqual(options, 'all') self.assertIsNone(completer('a', state=5))
def test_get_tab_complete_list(self): # Setup contact_list = ContactList(nicks=['Alice', 'Bob']) group_list = GroupList(groups=['testgroup']) settings = Settings(key_list = ['key1', 'key2']) tclst = ['about', 'add ', 'all', 'clear', 'cmd', 'create ', 'exit', 'export ', 'false', 'file', 'fingerprints', 'group ', 'help', 'history ', 'localkey', 'logging ', 'msg ', 'names', 'nick ', 'notify ', 'passwd ', 'psk', 'reset', 'rm ', 'set ', 'settings', 'store ', 'true', 'unread', 'key1 ', 'key2 ', '[email protected] ', '[email protected] ', 'Alice ', '[email protected] ', 'Bob ', 'testgroup '] # Test self.assertEqual(set(get_tab_complete_list(contact_list, group_list, settings)), set(tclst)) self.assertIsInstance(get_tab_completer(contact_list, group_list, settings), types.FunctionType)
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 input_loop(queues: Dict[bytes, 'Queue'], settings: 'Settings', gateway: 'Gateway', contact_list: 'ContactList', group_list: 'GroupList', master_key: 'MasterKey', stdin_fd: int) -> None: """Get input from user and process it accordingly. Tx side of TFC runs two processes -- input and sender loop -- separate from one another. This allows prioritized output of queued assembly packets. input_loop handles Tx-side functions excluding assembly packet encryption, output and logging, and hash ratchet key/counter updates in key_list database. """ 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)) readline.parse_and_bind('tab: complete') window.update_group_win_members(group_list) 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) while not window.is_selected(): window.select_tx_window(settings, queues) user_input = get_input(window, settings) if user_input.type == MESSAGE: queue_message(user_input, window, settings, queues[MESSAGE_PACKET_QUEUE]) elif user_input.type == FILE: queue_file(window, settings, queues[FILE_PACKET_QUEUE], gateway) elif user_input.type == COMMAND: process_command(user_input, window, settings, queues, contact_list, group_list, master_key)