Example #1
0
    def test_normal_group_msg_from_user(self, _: Any) -> None:
        # Setup
        assembly_ct_list = assembly_packet_creator(MESSAGE, self.msg, origin_header=ORIGIN_USER_HEADER,
                                                   group_id=self.group_id, encrypt_packet=True,
                                                   onion_pub_key=nick_to_pub_key('Alice'))

        for p in assembly_ct_list:
            self.assertIsNone(process_message_packet(self.ts, p, *self.args))
Example #2
0
    def test_private_msg_from_contact(self, _: Any) -> None:
        # Setup
        assembly_ct_list = assembly_packet_creator(MESSAGE, self.msg, origin_header=ORIGIN_CONTACT_HEADER,
                                                   encrypt_packet=True, onion_pub_key=nick_to_pub_key('Alice'))

        # Test
        for p in assembly_ct_list:
            self.assertIsNone(process_message_packet(self.ts, p, *self.args))
Example #3
0
def process_cached_messages(window_list: 'WindowList',
                            contact_list: 'ContactList',
                            group_list: 'GroupList', key_list: 'KeyList',
                            settings: 'Settings', packet_list: 'PacketList',
                            message_log: 'MessageLog',
                            file_keys: 'file_keys_type',
                            packet_buffer: 'packet_buffer_type') -> None:
    """Process cached message packets."""
    for onion_pub_key in packet_buffer:
        if (contact_list.has_pub_key(onion_pub_key)
                and key_list.has_rx_mk(onion_pub_key)
                and packet_buffer[onion_pub_key]):
            ts, packet = packet_buffer[onion_pub_key].pop(0)
            process_message_packet(ts, packet, window_list, packet_list,
                                   contact_list, key_list, group_list,
                                   settings, file_keys, message_log)
            raise SoftError("Cached message processing complete.",
                            output=False)
Example #4
0
    def test_empty_whisper_msg_from_user(self, _: Any) -> None:
        # Setup
        assembly_ct_list = assembly_packet_creator(MESSAGE, '', origin_header=ORIGIN_USER_HEADER,
                                                   encrypt_packet=True, onion_pub_key=nick_to_pub_key('Alice'),
                                                   whisper_header=bool_to_bytes(True))
        # Test
        for p in assembly_ct_list[:-1]:
            self.assertIsNone(process_message_packet(self.ts, p, *self.args))

        for p in assembly_ct_list[-1:]:
            self.assert_se("Whisper message complete.", process_message_packet, self.ts, p, *self.args)
Example #5
0
    def test_file(self, _: Any) -> None:
        # Setup
        assembly_ct_list = assembly_packet_creator(FILE, origin_header=ORIGIN_CONTACT_HEADER,
                                                   encrypt_packet=True, onion_pub_key=nick_to_pub_key('Alice'))

        # Test
        for p in assembly_ct_list[:-1]:
            self.assertIsNone(process_message_packet(self.ts, p, *self.args))

        for p in assembly_ct_list[-1:]:
            self.assert_se("File storage complete.",
                           process_message_packet, self.ts, p, *self.args)
Example #6
0
def process_message_queue(queues: 'queue_dict', window_list: 'WindowList',
                          contact_list: 'ContactList', group_list: 'GroupList',
                          key_list: 'KeyList', settings: 'Settings',
                          packet_list: 'PacketList', message_log: 'MessageLog',
                          file_keys: 'file_keys_type',
                          packet_buffer: 'packet_buffer_type') -> None:
    """Check message queue for packets."""
    message_queue = queues[MESSAGE_DATAGRAM_HEADER]

    if message_queue.qsize():
        ts, packet = message_queue.get()
        onion_pub_key = packet[:ONION_SERVICE_PUBLIC_KEY_LENGTH]

        if contact_list.has_pub_key(onion_pub_key) and key_list.has_rx_mk(
                onion_pub_key):
            process_message_packet(ts, packet, window_list, packet_list,
                                   contact_list, key_list, group_list,
                                   settings, file_keys, message_log)
        else:
            packet_buffer.setdefault(onion_pub_key, []).append((ts, packet))

        raise SoftError("Message processing complete.", output=False)