Example #1
0
    def start():
        if Transport.identity == None:
            transport_identity_path = RNS.Reticulum.configdir + "/transportidentity"
            if os.path.isfile(transport_identity_path):
                Transport.identity = RNS.Identity.from_file(
                    transport_identity_path)

            if Transport.identity == None:
                RNS.log("No valid Transport Identity on disk, creating...",
                        RNS.LOG_VERBOSE)
                Transport.identity = RNS.Identity()
                Transport.identity.save(transport_identity_path)
            else:
                RNS.log("Loaded Transport Identity from disk", RNS.LOG_VERBOSE)

        packet_hashlist_path = RNS.Reticulum.configdir + "/packet_hashlist"
        if os.path.isfile(packet_hashlist_path):
            try:
                file = open(packet_hashlist_path, "r")
                Transport.packet_hashlist = umsgpack.unpackb(file.read())
                file.close()
            except Exception as e:
                RNS.log(
                    "Could not load packet hashlist from disk, the contained exception was: "
                    + str(e), RNS.LOG_ERROR)

        thread = threading.Thread(target=Transport.jobloop)
        thread.setDaemon(True)
        thread.start()

        RNS.log("Transport instance " + str(Transport.identity) + " started")
Example #2
0
	def hashmap_update_packet(self, plaintext):
		if not self.status == Resource.FAILED:
			self.last_activity = time.time()
			self.retries_left = self.max_retries

			update = umsgpack.unpackb(plaintext[RNS.Identity.HASHLENGTH/8:])
			self.hashmap_update(update[0], update[1])
Example #3
0
	def unpack(data):
		dictionary = umsgpack.unpackb(data)
		
		adv   = ResourceAdvertisement()
		adv.t = dictionary["t"]
		adv.d = dictionary["d"]
		adv.n = dictionary["n"]
		adv.h = dictionary["h"]
		adv.r = dictionary["r"]
		adv.m = dictionary["m"]
		adv.f = dictionary["f"]
		adv.e = True if (adv.f & 0x01) == 0x01 else False
		adv.c = True if ((adv.f >> 1) & 0x01) == 0x01 else False

		return adv
Example #4
0
    def rtt_packet(self, packet):
        try:
            # TODO: This is crude, we should use the delta
            # to model a more representative per-bit round
            # trip time, and use that to set a sensible RTT
            # expectancy for the link. This will have to do
            # for now though.
            measured_rtt = time.time() - self.request_time
            plaintext = self.decrypt(packet.data)
            rtt = umsgpack.unpackb(plaintext)
            self.rtt = max(measured_rtt, rtt)
            self.status = Link.ACTIVE

            if self.owner.callbacks.link_established != None:
                self.owner.callbacks.link_established(self)
        except Exception as e:
            RNS.log(
                "Error occurred while processing RTT packet, tearing down link",
                RNS.LOG_ERROR)
            traceback.print_exc()
            self.teardown()