mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-07-12 11:38:11 -07:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fd13e20165 | |||
| 66ce58f0f4 | |||
| e8ee26f78d | |||
| c0fb419fe1 |
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
import base64
|
import base64
|
||||||
import math
|
import math
|
||||||
|
import time
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
@@ -146,7 +147,7 @@ class Destination:
|
|||||||
:param path_response: Internal flag used by :ref:`RNS.Transport<api-transport>`. Ignore.
|
:param path_response: Internal flag used by :ref:`RNS.Transport<api-transport>`. Ignore.
|
||||||
"""
|
"""
|
||||||
destination_hash = self.hash
|
destination_hash = self.hash
|
||||||
random_hash = RNS.Identity.get_random_hash()
|
random_hash = RNS.Identity.get_random_hash()[0:5]+int(time.time()).to_bytes(5, "big")
|
||||||
|
|
||||||
if app_data == None and self.default_app_data != None:
|
if app_data == None and self.default_app_data != None:
|
||||||
if isinstance(self.default_app_data, bytes):
|
if isinstance(self.default_app_data, bytes):
|
||||||
|
|||||||
+1
-1
@@ -804,7 +804,7 @@ class Resource:
|
|||||||
return progress
|
return progress
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return RNS.prettyhexrep(self.hash)+str(self.link)
|
return "<"+RNS.hexrep(self.hash)+"/"+RNS.hexrep(self.link.link_id)+">"
|
||||||
|
|
||||||
|
|
||||||
class ResourceAdvertisement:
|
class ResourceAdvertisement:
|
||||||
|
|||||||
+20
-3
@@ -775,7 +775,8 @@ class Transport:
|
|||||||
# First, check that the announce is not for a destination
|
# First, check that the announce is not for a destination
|
||||||
# local to this system, and that hops are less than the max
|
# local to this system, and that hops are less than the max
|
||||||
if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
|
if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
|
||||||
random_blob = packet.data[RNS.Identity.KEYSIZE//8+10:RNS.Identity.KEYSIZE//8+20]
|
random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8]
|
||||||
|
announce_emitted = int.from_bytes(random_blob[5:10], "big")
|
||||||
random_blobs = []
|
random_blobs = []
|
||||||
if packet.destination_hash in Transport.destination_table:
|
if packet.destination_hash in Transport.destination_table:
|
||||||
random_blobs = Transport.destination_table[packet.destination_hash][4]
|
random_blobs = Transport.destination_table[packet.destination_hash][4]
|
||||||
@@ -796,8 +797,18 @@ class Transport:
|
|||||||
else:
|
else:
|
||||||
# If an announce arrives with a larger hop
|
# If an announce arrives with a larger hop
|
||||||
# count than we already have in the table,
|
# count than we already have in the table,
|
||||||
# ignore it, unless the path is expired
|
# ignore it, unless the path is expired, or
|
||||||
if (time.time() > Transport.destination_table[packet.destination_hash][3]):
|
# the emission timestamp is more recent.
|
||||||
|
now = time.time()
|
||||||
|
path_expires = Transport.destination_table[packet.destination_hash][3]
|
||||||
|
|
||||||
|
path_announce_emitted = 0
|
||||||
|
for path_random_blob in random_blobs:
|
||||||
|
path_announce_emitted = max(path_announce_emitted, int.from_bytes(path_random_blob[5:10], "big"))
|
||||||
|
if path_announce_emitted >= announce_emitted:
|
||||||
|
break
|
||||||
|
|
||||||
|
if (now >= path_expires):
|
||||||
# We also check that the announce hash is
|
# We also check that the announce hash is
|
||||||
# different from ones we've already heard,
|
# different from ones we've already heard,
|
||||||
# to avoid loops in the network
|
# to avoid loops in the network
|
||||||
@@ -808,8 +819,14 @@ class Transport:
|
|||||||
should_add = True
|
should_add = True
|
||||||
else:
|
else:
|
||||||
should_add = False
|
should_add = False
|
||||||
|
else:
|
||||||
|
if (announce_emitted > path_announce_emitted):
|
||||||
|
if not random_blob in random_blobs:
|
||||||
|
RNS.log("Replacing destination table entry for "+str(RNS.prettyhexrep(packet.destination_hash))+" with new announce, since it was more recently emitted", RNS.LOG_DEBUG)
|
||||||
|
should_add = True
|
||||||
else:
|
else:
|
||||||
should_add = False
|
should_add = False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# If this destination is unknown in our table
|
# If this destination is unknown in our table
|
||||||
# we should add it
|
# we should add it
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
__version__ = "0.2.7"
|
__version__ = "0.2.8"
|
||||||
Reference in New Issue
Block a user