def outbound(packet): while (Transport.jobs_running): sleep(0.01) Transport.jobs_locked = True packet.updateHash() sent = False for interface in Transport.interfaces: if interface.OUT: should_transmit = True if packet.destination.type == RNS.Destination.LINK: if packet.destination.status == RNS.Link.CLOSED: should_transmit = False if interface != packet.destination.attached_interface: should_transmit = False if should_transmit: # TODO: Remove RNS.log( "Transmitting " + str(len(packet.raw)) + " bytes via: " + str(interface), RNS.LOG_EXTREME) RNS.log("Hash is " + RNS.prettyhexrep(packet.packet_hash), RNS.LOG_EXTREME) interface.processOutgoing(packet.raw) sent = True if sent: packet.sent = True packet.sent_at = time.time() if (packet.packet_type == RNS.Packet.DATA): packet.receipt = RNS.PacketReceipt(packet) Transport.receipts.append(packet.receipt) Transport.cache(packet) Transport.jobs_locked = False return sent
def outbound(packet): while (Transport.jobs_running): sleep(0.01) Transport.jobs_locked = True # TODO: This updateHash call might be redundant packet.updateHash() sent = False # Check if we have a known path for the destination # in the destination table if packet.packet_type != RNS.Packet.ANNOUNCE and packet.destination_hash in Transport.destination_table: outbound_interface = Transport.destination_table[ packet.destination_hash][5] if Transport.destination_table[packet.destination_hash][2] > 1: # Insert packet into transport new_flags = (RNS.Packet.HEADER_2) << 6 | ( Transport.TRANSPORT) << 4 | (packet.flags & 0b00001111) new_raw = struct.pack("!B", new_flags) new_raw += packet.raw[1:2] new_raw += Transport.destination_table[ packet.destination_hash][1] new_raw += packet.raw[2:] RNS.log( "Packet was inserted into transport via " + RNS.prettyhexrep(Transport.destination_table[ packet.destination_hash][1]) + " on: " + str(outbound_interface), RNS.LOG_DEBUG) outbound_interface.processOutgoing(new_raw) Transport.destination_table[ packet.destination_hash][0] = time.time() sent = True else: # Destination is directly reachable, and we know on # what interface, so transmit only on that one RNS.log( "Transmitting " + str(len(packet.raw)) + " bytes on: " + str(outbound_interface), RNS.LOG_EXTREME) RNS.log("Hash is " + RNS.prettyhexrep(packet.packet_hash), RNS.LOG_EXTREME) outbound_interface.processOutgoing(packet.raw) sent = True else: # Broadcast packet on all outgoing interfaces, or relevant # interface, if packet is for a link or has an attachede interface for interface in Transport.interfaces: if interface.OUT: should_transmit = True if packet.destination.type == RNS.Destination.LINK: if packet.destination.status == RNS.Link.CLOSED: should_transmit = False if interface != packet.destination.attached_interface: should_transmit = False if packet.attached_interface != None and interface != packet.attached_interface: should_transmit = False if should_transmit: RNS.log( "Transmitting " + str(len(packet.raw)) + " bytes on: " + str(interface), RNS.LOG_EXTREME) RNS.log( "Hash is " + RNS.prettyhexrep(packet.packet_hash), RNS.LOG_EXTREME) interface.processOutgoing(packet.raw) sent = True if sent: packet.sent = True packet.sent_at = time.time() if (packet.packet_type == RNS.Packet.DATA and packet.destination.type != RNS.Destination.PLAIN): packet.receipt = RNS.PacketReceipt(packet) Transport.receipts.append(packet.receipt) Transport.cache(packet) Transport.jobs_locked = False return sent