mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 15:30:18 +00:00
Refactored Transport method names
This commit is contained in:
parent
8496ee19d9
commit
235b1cea4c
@ -127,7 +127,7 @@ class Destination:
|
|||||||
self.callback = None
|
self.callback = None
|
||||||
self.proofcallback = None
|
self.proofcallback = None
|
||||||
|
|
||||||
RNS.Transport.registerDestination(self)
|
RNS.Transport.register_destination(self)
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -64,7 +64,7 @@ class Link:
|
|||||||
link.attached_interface = packet.receiving_interface
|
link.attached_interface = packet.receiving_interface
|
||||||
link.prove()
|
link.prove()
|
||||||
link.request_time = time.time()
|
link.request_time = time.time()
|
||||||
RNS.Transport.registerLink(link)
|
RNS.Transport.register_link(link)
|
||||||
link.last_inbound = time.time()
|
link.last_inbound = time.time()
|
||||||
link.start_watchdog()
|
link.start_watchdog()
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class Link:
|
|||||||
self.packet = RNS.Packet(destination, self.request_data, packet_type=RNS.Packet.LINKREQUEST)
|
self.packet = RNS.Packet(destination, self.request_data, packet_type=RNS.Packet.LINKREQUEST)
|
||||||
self.packet.pack()
|
self.packet.pack()
|
||||||
self.set_link_id(self.packet)
|
self.set_link_id(self.packet)
|
||||||
RNS.Transport.registerLink(self)
|
RNS.Transport.register_link(self)
|
||||||
self.request_time = time.time()
|
self.request_time = time.time()
|
||||||
self.start_watchdog()
|
self.start_watchdog()
|
||||||
self.packet.send()
|
self.packet.send()
|
||||||
@ -196,7 +196,7 @@ class Link:
|
|||||||
self.handshake()
|
self.handshake()
|
||||||
self.rtt = time.time() - self.request_time
|
self.rtt = time.time() - self.request_time
|
||||||
self.attached_interface = packet.receiving_interface
|
self.attached_interface = packet.receiving_interface
|
||||||
RNS.Transport.activateLink(self)
|
RNS.Transport.activate_link(self)
|
||||||
RNS.log("Link "+str(self)+" established with "+str(self.destination)+", RTT is "+str(self.rtt), RNS.LOG_VERBOSE)
|
RNS.log("Link "+str(self)+" established with "+str(self.destination)+", RTT is "+str(self.rtt), RNS.LOG_VERBOSE)
|
||||||
rtt_data = umsgpack.packb(self.rtt)
|
rtt_data = umsgpack.packb(self.rtt)
|
||||||
rtt_packet = RNS.Packet(self, rtt_data, context=RNS.Packet.LRRTT)
|
rtt_packet = RNS.Packet(self, rtt_data, context=RNS.Packet.LRRTT)
|
||||||
|
@ -874,7 +874,7 @@ class Transport:
|
|||||||
Transport.jobs_locked = False
|
Transport.jobs_locked = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def registerDestination(destination):
|
def register_destination(destination):
|
||||||
destination.MTU = RNS.Reticulum.MTU
|
destination.MTU = RNS.Reticulum.MTU
|
||||||
if destination.direction == RNS.Destination.IN:
|
if destination.direction == RNS.Destination.IN:
|
||||||
for registered_destination in Transport.destinations:
|
for registered_destination in Transport.destinations:
|
||||||
@ -888,7 +888,7 @@ class Transport:
|
|||||||
Transport.destinations.remove(destination)
|
Transport.destinations.remove(destination)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def registerLink(link):
|
def register_link(link):
|
||||||
RNS.log("Registering link "+str(link), RNS.LOG_DEBUG)
|
RNS.log("Registering link "+str(link), RNS.LOG_DEBUG)
|
||||||
if link.initiator:
|
if link.initiator:
|
||||||
Transport.pending_links.append(link)
|
Transport.pending_links.append(link)
|
||||||
@ -896,7 +896,7 @@ class Transport:
|
|||||||
Transport.active_links.append(link)
|
Transport.active_links.append(link)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def activateLink(link):
|
def activate_link(link):
|
||||||
RNS.log("Activating link "+str(link), RNS.LOG_DEBUG)
|
RNS.log("Activating link "+str(link), RNS.LOG_DEBUG)
|
||||||
if link in Transport.pending_links:
|
if link in Transport.pending_links:
|
||||||
Transport.pending_links.remove(link)
|
Transport.pending_links.remove(link)
|
||||||
@ -925,7 +925,7 @@ class Transport:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def shouldCache(packet):
|
def should_cache(packet):
|
||||||
if packet.context == RNS.Packet.RESOURCE_PRF:
|
if packet.context == RNS.Packet.RESOURCE_PRF:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -938,7 +938,7 @@ class Transport:
|
|||||||
# the packet cache.
|
# the packet cache.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cache(packet, force_cache=False):
|
def cache(packet, force_cache=False):
|
||||||
if RNS.Transport.shouldCache(packet) or force_cache:
|
if RNS.Transport.should_cache(packet) or force_cache:
|
||||||
try:
|
try:
|
||||||
packet_hash = RNS.hexrep(packet.getHash(), delimit=False)
|
packet_hash = RNS.hexrep(packet.getHash(), delimit=False)
|
||||||
interface_reference = None
|
interface_reference = None
|
||||||
@ -1015,14 +1015,14 @@ class Transport:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def requestPath(destination_hash):
|
def request_path(destination_hash):
|
||||||
path_request_data = destination_hash + RNS.Identity.get_random_hash()
|
path_request_data = destination_hash + RNS.Identity.get_random_hash()
|
||||||
path_request_dst = RNS.Destination(None, RNS.Destination.OUT, RNS.Destination.PLAIN, Transport.APP_NAME, "path", "request")
|
path_request_dst = RNS.Destination(None, RNS.Destination.OUT, RNS.Destination.PLAIN, Transport.APP_NAME, "path", "request")
|
||||||
packet = RNS.Packet(path_request_dst, path_request_data, packet_type = RNS.Packet.DATA, transport_type = RNS.Transport.BROADCAST, header_type = RNS.Packet.HEADER_1)
|
packet = RNS.Packet(path_request_dst, path_request_data, packet_type = RNS.Packet.DATA, transport_type = RNS.Transport.BROADCAST, header_type = RNS.Packet.HEADER_1)
|
||||||
packet.send()
|
packet.send()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def requestPathOnInterface(destination_hash, interface):
|
def request_path_on_interface(destination_hash, interface):
|
||||||
path_request_data = destination_hash + RNS.Identity.get_random_hash()
|
path_request_data = destination_hash + RNS.Identity.get_random_hash()
|
||||||
path_request_dst = RNS.Destination(None, RNS.Destination.OUT, RNS.Destination.PLAIN, Transport.APP_NAME, "path", "request")
|
path_request_dst = RNS.Destination(None, RNS.Destination.OUT, RNS.Destination.PLAIN, Transport.APP_NAME, "path", "request")
|
||||||
packet = RNS.Packet(path_request_dst, path_request_data, packet_type = RNS.Packet.DATA, transport_type = RNS.Transport.BROADCAST, header_type = RNS.Packet.HEADER_1, attached_interface = interface)
|
packet = RNS.Packet(path_request_dst, path_request_data, packet_type = RNS.Packet.DATA, transport_type = RNS.Transport.BROADCAST, header_type = RNS.Packet.HEADER_1, attached_interface = interface)
|
||||||
@ -1031,14 +1031,14 @@ class Transport:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def path_request_handler(data, packet):
|
def path_request_handler(data, packet):
|
||||||
if len(data) >= RNS.Identity.TRUNCATED_HASHLENGTH//8:
|
if len(data) >= RNS.Identity.TRUNCATED_HASHLENGTH//8:
|
||||||
Transport.pathRequest(
|
Transport.path_request(
|
||||||
data[:RNS.Identity.TRUNCATED_HASHLENGTH//8],
|
data[:RNS.Identity.TRUNCATED_HASHLENGTH//8],
|
||||||
Transport.from_local_client(packet),
|
Transport.from_local_client(packet),
|
||||||
packet.receiving_interface
|
packet.receiving_interface
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pathRequest(destination_hash, is_from_local_client, attached_interface):
|
def path_request(destination_hash, is_from_local_client, attached_interface):
|
||||||
RNS.log("Path request for "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
|
RNS.log("Path request for "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
local_destination = next((d for d in Transport.destinations if d.hash == destination_hash), None)
|
local_destination = next((d for d in Transport.destinations if d.hash == destination_hash), None)
|
||||||
@ -1080,13 +1080,13 @@ class Transport:
|
|||||||
# except the local client
|
# except the local client
|
||||||
for interface in Transport.interfaces:
|
for interface in Transport.interfaces:
|
||||||
if not interface == attached_interface:
|
if not interface == attached_interface:
|
||||||
Transport.requestPathOnInterface(destination_hash, interface)
|
Transport.request_path_on_interface(destination_hash, interface)
|
||||||
|
|
||||||
elif not is_from_local_client and len(Transport.local_client_interfaces) > 0:
|
elif not is_from_local_client and len(Transport.local_client_interfaces) > 0:
|
||||||
# Forward the path request on all local
|
# Forward the path request on all local
|
||||||
# client interfaces
|
# client interfaces
|
||||||
for interface in Transport.local_client_interfaces:
|
for interface in Transport.local_client_interfaces:
|
||||||
Transport.requestPathOnInterface(destination_hash, interface)
|
Transport.request_path_on_interface(destination_hash, interface)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
RNS.log("No known path to requested destination, ignoring request", RNS.LOG_DEBUG)
|
RNS.log("No known path to requested destination, ignoring request", RNS.LOG_DEBUG)
|
||||||
|
Loading…
Reference in New Issue
Block a user