Reticulum/FPE/Transport.py

36 lines
926 B
Python
Raw Normal View History

2018-03-19 09:39:08 -06:00
import FPE
2016-06-03 11:02:02 -06:00
class Transport:
2018-03-19 09:39:08 -06:00
# Constants
BROADCAST = 0x00;
TRANSPORT = 0x01;
RELAY = 0x02;
TUNNEL = 0x03;
types = [BROADCAST, TRANSPORT, RELAY, TUNNEL]
2018-03-19 13:51:26 -06:00
packet_hashlist = []
2016-06-03 11:02:02 -06:00
@staticmethod
def outbound(raw):
2018-03-19 09:39:08 -06:00
FPE.FlexPE.outbound(raw)
2016-06-03 11:02:02 -06:00
2018-03-19 13:51:26 -06:00
@staticmethod
def inbound(raw):
packet_hash = FPE.Identity.fullHash(raw)
if not packet_hash in Transport.packet_hashlist:
Transport.packet_hashlist.append(packet_hash)
packet = FPE.Packet(None, raw)
packet.unpack()
if packet.packet_type == FPE.Packet.ANNOUNCE:
FPE.Identity.validateAnnounce(packet)
if packet.packet_type == FPE.Packet.RESOURCE:
for destination in FlexPE.destinations:
if destination.hash == packet.destination_hash and destination.type == packet.destination_type:
destination.receive(packet.data)
2016-06-03 11:02:02 -06:00
@staticmethod
def registerDestination(destination):
2018-03-19 09:39:08 -06:00
FPE.FlexPE.addDestination(destination)