Beispiel #1
0
    def validateProof(self, packet):
        if self.initiator:
            peer_pub_bytes = packet.data[:Link.ECPUBSIZE]
            signed_data = self.link_id + peer_pub_bytes
            signature = packet.data[Link.ECPUBSIZE:RNS.Identity.KEYSIZE / 8 +
                                    Link.ECPUBSIZE]

            if self.destination.identity.validate(signature, signed_data):
                self.loadPeer(peer_pub_bytes)
                self.handshake()
                self.rtt = time.time() - self.request_time
                self.attached_interface = packet.receiving_interface
                RNS.Transport.activateLink(self)
                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_packet = RNS.Packet(self,
                                        rtt_data,
                                        context=RNS.Packet.LRRTT)
                RNS.log("Sending RTT packet", RNS.LOG_EXTREME)
                rtt_packet.send()

                self.status = Link.ACTIVE
                if self.callbacks.link_established != None:
                    self.callbacks.link_established(self)
            else:
                RNS.log(
                    "Invalid link proof signature received by " + str(self),
                    RNS.LOG_VERBOSE)
                # TODO: should we really do this, or just wait
                # for a valid one? Needs analysis.
                self.teardown()
Beispiel #2
0
 def exitHandler():
     try:
         packet_hashlist_path = RNS.Reticulum.configdir + "/packet_hashlist"
         file = open(packet_hashlist_path, "w")
         file.write(umsgpack.packb(Transport.packet_hashlist))
         file.close()
     except Exception as e:
         RNS.log(
             "Could not save packet hashlist to disk, the contained exception was: "
             + str(e), RNS.LOG_ERROR)
Beispiel #3
0
	def pack(self, segment=0):
		hashmap_start = segment*ResourceAdvertisement.HASHMAP_MAX_LEN
		hashmap_end   = min((segment+1)*ResourceAdvertisement.HASHMAP_MAX_LEN, self.n)

		hashmap = ""
		for i in range(hashmap_start,hashmap_end):
			hashmap += self.m[i*Resource.MAPHASH_LEN:(i+1)*Resource.MAPHASH_LEN]

		dictionary = {
			u"t": self.t,
			u"d": self.d,
			u"n": self.n,
			u"h": self.h,
			u"r": self.r,
			u"f": self.f,
			u"m": hashmap
		}

		return umsgpack.packb(dictionary)
Beispiel #4
0
	def request(self, request_data):
		if not self.status == Resource.FAILED:
			rtt = time.time() - self.adv_sent
			if self.rtt == None:
				self.rtt = rtt

			if self.status != Resource.TRANSFERRING:
				self.status = Resource.TRANSFERRING
				self.watchdog_job()

			self.retries_left = self.max_retries

			wants_more_hashmap = True if ord(request_data[0]) == Resource.HASHMAP_IS_EXHAUSTED else False
			pad = 1+Resource.MAPHASH_LEN if wants_more_hashmap else 1

			requested_hashes = request_data[pad+RNS.Identity.HASHLENGTH/8:]

			for i in range(0,len(requested_hashes)/Resource.MAPHASH_LEN):
				requested_hash = requested_hashes[i*Resource.MAPHASH_LEN:(i+1)*Resource.MAPHASH_LEN]
				
				pi = 0
				for part in self.parts:
					if part.map_hash == requested_hash:
						if not part.sent:
							part.send()
							self.sent_parts += 1
						else:
							part.resend()
						self.last_activity = time.time()
						self.last_part_sent = self.last_activity
						break
					pi += 1

			if wants_more_hashmap:
				last_map_hash = request_data[1:Resource.MAPHASH_LEN+1]
				
				part_index = 0
				for part in self.parts:
					part_index += 1
					if part.map_hash == last_map_hash:
						break

				if part_index % ResourceAdvertisement.HASHMAP_MAX_LEN != 0:
					RNS.log("Resource sequencing error, cancelling transfer!", RNS.LOG_ERROR)
					self.cancel()
				else:
					segment = part_index / ResourceAdvertisement.HASHMAP_MAX_LEN

				
				hashmap_start = segment*ResourceAdvertisement.HASHMAP_MAX_LEN
				hashmap_end   = min((segment+1)*ResourceAdvertisement.HASHMAP_MAX_LEN, len(self.parts))

				hashmap = ""
				for i in range(hashmap_start,hashmap_end):
					hashmap += self.hashmap[i*Resource.MAPHASH_LEN:(i+1)*Resource.MAPHASH_LEN]

				hmu = self.hash+umsgpack.packb([segment, hashmap])
				hmu_packet = RNS.Packet(self.link, hmu, context = RNS.Packet.RESOURCE_HMU)

				hmu_packet.send()
				self.last_activity = time.time()

			if self.sent_parts == len(self.parts):
				self.status = Resource.AWAITING_PROOF