Strip transport headers at final hop

This commit is contained in:
Mark Qvist 2020-03-06 09:51:59 +01:00
parent a24a9623d3
commit 09a19aed72
2 changed files with 18 additions and 6 deletions

View File

@ -96,7 +96,8 @@ def client(destination_hexhash, configpath, timeout=None):
# We override the loglevel to provide feedback when # We override the loglevel to provide feedback when
# an announce is received # an announce is received
RNS.loglevel = RNS.LOG_INFO # TODO: Reset this
RNS.loglevel = RNS.LOG_DEBUG
# Tell the user that the client is ready! # Tell the user that the client is ready!
RNS.log("Echo client ready, hit enter to send echo request to "+destination_hexhash+" (Ctrl-C to quit)") RNS.log("Echo client ready, hit enter to send echo request to "+destination_hexhash+" (Ctrl-C to quit)")

View File

@ -236,6 +236,7 @@ class Transport:
if packet.packet_type == RNS.Packet.ANNOUNCE: if packet.packet_type == RNS.Packet.ANNOUNCE:
return True return True
# TODO: Probably changee to LOG_EXTREME
RNS.log("Filtered packet with hash "+RNS.prettyhexrep(packet.packet_hash), RNS.LOG_DEBUG) RNS.log("Filtered packet with hash "+RNS.prettyhexrep(packet.packet_hash), RNS.LOG_DEBUG)
return False return False
@ -262,11 +263,21 @@ class Transport:
RNS.log("Received packet in transport for "+RNS.prettyhexrep(packet.destination_hash)+" with matching transport ID, transporting it...", RNS.LOG_DEBUG) RNS.log("Received packet in transport for "+RNS.prettyhexrep(packet.destination_hash)+" with matching transport ID, transporting it...", RNS.LOG_DEBUG)
if packet.destination_hash in Transport.destination_table: if packet.destination_hash in Transport.destination_table:
next_hop = Transport.destination_table[packet.destination_hash][1] next_hop = Transport.destination_table[packet.destination_hash][1]
RNS.log("Next hop to destination is "+RNS.prettyhexrep(next_hop)+", transporting it.", RNS.LOG_DEBUG) remaining_hops = Transport.destination_table[packet.destination_hash][2]
new_raw = packet.raw[0:1] RNS.log("Next hop to destination is "+RNS.prettyhexrep(next_hop)+" with "+str(remaining_hops)+" hops remaining, transporting it.", RNS.LOG_DEBUG)
new_raw += struct.pack("!B", packet.hops) if remaining_hops > 1:
new_raw += next_hop # Just increase hop count and transmit
new_raw += packet.raw[12:] new_raw = packet.raw[0:1]
new_raw += struct.pack("!B", packet.hops)
new_raw += next_hop
new_raw += packet.raw[12:]
else:
# Strip transport headers and transmit
new_flags = (RNS.Packet.HEADER_1) << 6 | (Transport.BROADCAST) << 4 | (packet.flags & 0b00001111)
new_raw = struct.pack("!B", new_flags)
new_raw += struct.pack("!B", packet.hops)
new_raw += packet.raw[12:]
outbound_interface = Transport.destination_table[packet.destination_hash][5] outbound_interface = Transport.destination_table[packet.destination_hash][5]
outbound_interface.processOutgoing(new_raw) outbound_interface.processOutgoing(new_raw)