rns 1.2.8__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rns-1.2.8 → rns-1.3.0}/PKG-INFO +1 -1
- {rns-1.2.8 → rns-1.3.0}/RNS/Channel.py +94 -61
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/Hashes.py +2 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Identity.py +26 -10
- {rns-1.2.8 → rns-1.3.0}/RNS/Transport.py +14 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/pages.py +22 -6
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/server.py +270 -145
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnid.py +14 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/initiator.py +2 -0
- rns-1.3.0/RNS/_version.py +1 -0
- {rns-1.2.8 → rns-1.3.0}/rns.egg-info/PKG-INFO +1 -1
- {rns-1.2.8 → rns-1.3.0}/setup.py +4 -0
- rns-1.2.8/RNS/_version.py +0 -1
- {rns-1.2.8 → rns-1.3.0}/CRNS/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/README.md +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Buffer.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/AES.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/Ed25519.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/HKDF.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/HMAC.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/PKCS7.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/Provider.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/Proxies.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/SHA256.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/SHA512.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/Token.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/X25519.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/aes/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/aes/aes128.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/aes/aes256.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/pure25519/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/pure25519/_ed25519.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/pure25519/basic.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/pure25519/ed25519_oop.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Cryptography/pure25519/eddsa.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Destination.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Discovery.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/AX25KISSInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/Android/KISSInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/Android/RNodeInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/Android/SerialInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/Android/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/AutoInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/BackboneInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/I2PInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/Interface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/KISSInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/LocalInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/PipeInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/RNodeInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/RNodeMultiInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/SerialInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/TCPInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/UDPInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/WeaveInterface.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/util/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Interfaces/util/netinfo.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Link.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Packet.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Resolver.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Resource.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Reticulum.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rncp.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/client.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/highlight.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/main.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rngit/util.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnir.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnodeconf.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnpath.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnpkg.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnprobe.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsd.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/_version.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/args.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/exception.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/helpers.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/listener.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/loop.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/process.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/protocol.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/retry.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/rnsh.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnsh/session.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnstatus.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/Utilities/rnx.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/configobj.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/__init__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/__version__.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/aiosam.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/exceptions.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/log.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/sam.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/tunnel.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/i2plib/utils.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/platformutils.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/umsgpack.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/RNS/vendor/validate.py +0 -0
- {rns-1.2.8 → rns-1.3.0}/rns.egg-info/SOURCES.txt +0 -0
- {rns-1.2.8 → rns-1.3.0}/rns.egg-info/dependency_links.txt +0 -0
- {rns-1.2.8 → rns-1.3.0}/rns.egg-info/entry_points.txt +0 -0
- {rns-1.2.8 → rns-1.3.0}/rns.egg-info/requires.txt +0 -0
- {rns-1.2.8 → rns-1.3.0}/rns.egg-info/top_level.txt +0 -0
- {rns-1.2.8 → rns-1.3.0}/setup.cfg +0 -0
{rns-1.2.8 → rns-1.3.0}/PKG-INFO
RENAMED
|
@@ -144,7 +144,7 @@ class MessageBase(abc.ABC):
|
|
|
144
144
|
MSGTYPE = None
|
|
145
145
|
"""
|
|
146
146
|
Defines a unique identifier for a message class.
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
* Must be unique within all classes registered with a ``Channel``
|
|
149
149
|
* Must be less than ``0xf000``. Values greater than or equal to ``0xf000`` are reserved.
|
|
150
150
|
"""
|
|
@@ -255,11 +255,11 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
255
255
|
|
|
256
256
|
# The maximum window size for transfers on fast links
|
|
257
257
|
WINDOW_MAX_FAST = 48
|
|
258
|
-
|
|
258
|
+
|
|
259
259
|
# For calculating maps and guard segments, this
|
|
260
260
|
# must be set to the global maximum window.
|
|
261
261
|
WINDOW_MAX = WINDOW_MAX_FAST
|
|
262
|
-
|
|
262
|
+
|
|
263
263
|
# If the fast rate is sustained for this many request
|
|
264
264
|
# rounds, the fast link window size will be allowed.
|
|
265
265
|
FAST_RATE_THRESHOLD = 10
|
|
@@ -285,6 +285,7 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
285
285
|
"""
|
|
286
286
|
self._outlet = outlet
|
|
287
287
|
self._lock = threading.RLock()
|
|
288
|
+
self._send_lock = threading.Lock()
|
|
288
289
|
self._tx_ring: collections.deque[Envelope] = collections.deque()
|
|
289
290
|
self._rx_ring: collections.deque[Envelope] = collections.deque()
|
|
290
291
|
self._message_callbacks: [MessageCallbackType] = []
|
|
@@ -382,27 +383,30 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
382
383
|
if envelope.packet is not None:
|
|
383
384
|
self._outlet.set_packet_timeout_callback(envelope.packet, None)
|
|
384
385
|
self._outlet.set_packet_delivered_callback(envelope.packet, None)
|
|
386
|
+
envelope.tracked = False
|
|
387
|
+
for envelope in self._rx_ring:
|
|
388
|
+
envelope.tracked = False
|
|
385
389
|
self._tx_ring.clear()
|
|
386
390
|
self._rx_ring.clear()
|
|
387
391
|
|
|
388
392
|
def _emplace_envelope(self, envelope: Envelope, ring: collections.deque[Envelope]) -> bool:
|
|
389
393
|
with self._lock:
|
|
390
394
|
i = 0
|
|
391
|
-
|
|
395
|
+
|
|
392
396
|
for existing in ring:
|
|
393
397
|
|
|
394
398
|
if envelope.sequence == existing.sequence:
|
|
395
399
|
RNS.log(f"Envelope: Emplacement of duplicate envelope with sequence "+str(envelope.sequence), RNS.LOG_EXTREME)
|
|
396
400
|
return False
|
|
397
|
-
|
|
401
|
+
|
|
398
402
|
if envelope.sequence < existing.sequence and not (self._next_rx_sequence - envelope.sequence) > (Channel.SEQ_MAX//2):
|
|
399
403
|
ring.insert(i, envelope)
|
|
400
404
|
|
|
401
405
|
envelope.tracked = True
|
|
402
406
|
return True
|
|
403
|
-
|
|
407
|
+
|
|
404
408
|
i += 1
|
|
405
|
-
|
|
409
|
+
|
|
406
410
|
envelope.tracked = True
|
|
407
411
|
ring.append(envelope)
|
|
408
412
|
|
|
@@ -457,7 +461,7 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
457
461
|
m = e.unpack(self._message_factories)
|
|
458
462
|
else:
|
|
459
463
|
m = e.message
|
|
460
|
-
|
|
464
|
+
|
|
461
465
|
self._rx_ring.remove(e)
|
|
462
466
|
self._run_callbacks(m)
|
|
463
467
|
|
|
@@ -476,7 +480,7 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
476
480
|
with self._lock:
|
|
477
481
|
outstanding = 0
|
|
478
482
|
for envelope in self._tx_ring:
|
|
479
|
-
if envelope.outlet == self._outlet:
|
|
483
|
+
if envelope.outlet == self._outlet:
|
|
480
484
|
if not envelope.packet or not self._outlet.get_packet_state(envelope.packet) == MessageState.MSGSTATE_DELIVERED:
|
|
481
485
|
outstanding += 1
|
|
482
486
|
|
|
@@ -486,8 +490,10 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
486
490
|
return True
|
|
487
491
|
|
|
488
492
|
def _packet_tx_op(self, packet: TPacket, op: Callable[[TPacket], bool]):
|
|
493
|
+
target_id = self._outlet.get_packet_id(packet)
|
|
489
494
|
with self._lock:
|
|
490
|
-
envelope = next(filter(lambda e:
|
|
495
|
+
envelope = next(filter(lambda e: e.packet is not None
|
|
496
|
+
and self._outlet.get_packet_id(e.packet) == target_id,
|
|
491
497
|
self._tx_ring), None)
|
|
492
498
|
|
|
493
499
|
if envelope and op(envelope):
|
|
@@ -516,7 +522,7 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
516
522
|
# TODO: Remove at some point
|
|
517
523
|
# RNS.log("Increased "+str(self)+" max window to "+str(self.window_max), RNS.LOG_DEBUG)
|
|
518
524
|
# RNS.log("Increased "+str(self)+" min window to "+str(self.window_min), RNS.LOG_DEBUG)
|
|
519
|
-
|
|
525
|
+
|
|
520
526
|
else:
|
|
521
527
|
self.fast_rate_rounds += 1
|
|
522
528
|
if self.window_max < Channel.WINDOW_MAX_FAST and self.fast_rate_rounds == Channel.FAST_RATE_THRESHOLD:
|
|
@@ -547,36 +553,48 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
547
553
|
return to
|
|
548
554
|
|
|
549
555
|
def _packet_timeout(self, packet: TPacket):
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
RNS.log("Retry count exceeded on "+str(self)+", tearing down Link.", RNS.LOG_ERROR)
|
|
553
|
-
self._shutdown() # start on separate thread?
|
|
554
|
-
self._outlet.timed_out()
|
|
555
|
-
return True
|
|
556
|
-
|
|
557
|
-
envelope.tries += 1
|
|
558
|
-
self._outlet.resend(envelope.packet)
|
|
559
|
-
self._outlet.set_packet_delivered_callback(envelope.packet, self._packet_delivered)
|
|
560
|
-
self._outlet.set_packet_timeout_callback(envelope.packet, self._packet_timeout, self._get_packet_timeout_time(envelope.tries))
|
|
561
|
-
self._update_packet_timeouts()
|
|
562
|
-
|
|
563
|
-
if self.window > self.window_min:
|
|
564
|
-
self.window -= 1
|
|
565
|
-
# TODO: Remove at some point
|
|
566
|
-
# RNS.log("Decreased "+str(self)+" window to "+str(self.window), RNS.LOG_DEBUG)
|
|
567
|
-
|
|
568
|
-
if self.window_max > (self.window_min+self.window_flexibility):
|
|
569
|
-
self.window_max -= 1
|
|
570
|
-
# TODO: Remove at some point
|
|
571
|
-
# RNS.log("Decreased "+str(self)+" max window to "+str(self.window_max), RNS.LOG_DEBUG)
|
|
572
|
-
|
|
573
|
-
# TODO: Remove at some point
|
|
574
|
-
# RNS.log("Decreased "+str(self)+" window to "+str(self.window), RNS.LOG_EXTREME)
|
|
556
|
+
if self._outlet.get_packet_state(packet) == MessageState.MSGSTATE_DELIVERED:
|
|
557
|
+
return
|
|
575
558
|
|
|
576
|
-
|
|
559
|
+
target_id = self._outlet.get_packet_id(packet)
|
|
560
|
+
envelope_to_resend: Envelope | None = None
|
|
561
|
+
should_teardown = False
|
|
562
|
+
with self._lock:
|
|
563
|
+
envelope = next(filter(
|
|
564
|
+
lambda e: e.packet is not None and self._outlet.get_packet_id(e.packet) == target_id,
|
|
565
|
+
self._tx_ring), None)
|
|
566
|
+
if envelope is None:
|
|
567
|
+
return
|
|
568
|
+
|
|
569
|
+
if envelope.tries >= self._max_tries:
|
|
570
|
+
should_teardown = True
|
|
571
|
+
else:
|
|
572
|
+
envelope.tries += 1
|
|
573
|
+
envelope_to_resend = envelope
|
|
574
|
+
|
|
575
|
+
if self.window > self.window_min:
|
|
576
|
+
self.window -= 1
|
|
577
|
+
if self.window_max > (self.window_min+self.window_flexibility):
|
|
578
|
+
self.window_max -= 1
|
|
579
|
+
|
|
580
|
+
if should_teardown:
|
|
581
|
+
RNS.log("Retry count exceeded on "+str(self)+", tearing down Link.", RNS.LOG_ERROR)
|
|
582
|
+
self._shutdown()
|
|
583
|
+
self._outlet.timed_out()
|
|
584
|
+
return
|
|
585
|
+
|
|
586
|
+
if envelope_to_resend is not None:
|
|
587
|
+
self._outlet.resend(envelope_to_resend.packet)
|
|
588
|
+
with self._lock:
|
|
589
|
+
self._outlet.set_packet_delivered_callback(envelope_to_resend.packet, self._packet_delivered)
|
|
590
|
+
self._outlet.set_packet_timeout_callback(
|
|
591
|
+
envelope_to_resend.packet, self._packet_timeout,
|
|
592
|
+
self._get_packet_timeout_time(envelope_to_resend.tries))
|
|
593
|
+
self._update_packet_timeouts()
|
|
594
|
+
already_delivered = (self._outlet.get_packet_state(envelope_to_resend.packet) == MessageState.MSGSTATE_DELIVERED)
|
|
577
595
|
|
|
578
|
-
|
|
579
|
-
|
|
596
|
+
if already_delivered:
|
|
597
|
+
self._packet_delivered(envelope_to_resend.packet)
|
|
580
598
|
|
|
581
599
|
def send(self, message: MessageBase) -> Envelope:
|
|
582
600
|
"""
|
|
@@ -585,27 +603,39 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
585
603
|
|
|
586
604
|
:param message: an instance of a ``MessageBase`` subclass
|
|
587
605
|
"""
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
606
|
+
with self._send_lock:
|
|
607
|
+
with self._lock:
|
|
608
|
+
if not self.is_ready_to_send():
|
|
609
|
+
raise ChannelException(CEType.ME_LINK_NOT_READY, f"Link is not ready")
|
|
610
|
+
|
|
611
|
+
reserved_sequence = self._next_sequence
|
|
612
|
+
envelope = Envelope(self._outlet, message=message, sequence=reserved_sequence)
|
|
613
|
+
envelope.pack()
|
|
614
|
+
if len(envelope.raw) > self._outlet.mdu:
|
|
615
|
+
raise ChannelException(CEType.ME_TOO_BIG,
|
|
616
|
+
f"Packed message too big for packet: {len(envelope.raw)} > {self._outlet.mdu}")
|
|
617
|
+
self._next_sequence = (reserved_sequence + 1) % Channel.SEQ_MODULUS
|
|
618
|
+
|
|
619
|
+
envelope.packet = self._outlet.send(envelope.raw)
|
|
620
|
+
|
|
621
|
+
if (envelope.packet is None
|
|
622
|
+
or getattr(envelope.packet, "raw", None) is None
|
|
623
|
+
or (hasattr(envelope.packet, "receipt") and envelope.packet.receipt is None)):
|
|
624
|
+
with self._lock:
|
|
625
|
+
self._next_sequence = reserved_sequence
|
|
626
|
+
raise ChannelException(CEType.ME_LINK_NOT_READY, "Outlet did not transmit packet")
|
|
627
|
+
|
|
628
|
+
with self._lock:
|
|
629
|
+
self._emplace_envelope(envelope, self._tx_ring)
|
|
630
|
+
envelope.tries += 1
|
|
631
|
+
self._outlet.set_packet_delivered_callback(envelope.packet, self._packet_delivered)
|
|
632
|
+
self._outlet.set_packet_timeout_callback(envelope.packet, self._packet_timeout, self._get_packet_timeout_time(envelope.tries))
|
|
633
|
+
self._update_packet_timeouts()
|
|
634
|
+
already_delivered = (self._outlet.get_packet_state(envelope.packet) == MessageState.MSGSTATE_DELIVERED)
|
|
635
|
+
|
|
636
|
+
# prevent _tx_ring envelope leak
|
|
637
|
+
if already_delivered:
|
|
638
|
+
self._packet_delivered(envelope.packet)
|
|
609
639
|
|
|
610
640
|
return envelope
|
|
611
641
|
|
|
@@ -699,7 +729,10 @@ class LinkChannelOutlet(ChannelOutletBase):
|
|
|
699
729
|
packet.receipt.set_delivery_callback(inner if callback else None)
|
|
700
730
|
|
|
701
731
|
def get_packet_id(self, packet: RNS.Packet) -> any:
|
|
702
|
-
if
|
|
732
|
+
if (packet
|
|
733
|
+
and getattr(packet, "raw", None) is not None
|
|
734
|
+
and hasattr(packet, "get_hash")
|
|
735
|
+
and callable(packet.get_hash)):
|
|
703
736
|
return packet.get_hash()
|
|
704
737
|
else:
|
|
705
738
|
return None
|
|
@@ -65,4 +65,6 @@ def sha512(data):
|
|
|
65
65
|
|
|
66
66
|
def file_sha256(file):
|
|
67
67
|
if not hashlib: raise SystemError("The hashlib module is not available on this system")
|
|
68
|
+
# TODO: Could implement fallback for old snakes here
|
|
69
|
+
if not hasattr(hashlib, "file_digest"): raise SystemError("The file_digest method is not available on this system. This functionality requires Python 3.11 or later.")
|
|
68
70
|
else: return hashlib.file_digest(file, "sha256").digest()
|
|
@@ -127,13 +127,15 @@ class Identity:
|
|
|
127
127
|
:returns: An :ref:`RNS.Identity<api-identity>` instance that can be used to create an outgoing :ref:`RNS.Destination<api-destination>`, or *None* if the destination is unknown.
|
|
128
128
|
"""
|
|
129
129
|
if from_identity_hash:
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
with Identity.known_destinations_lock: destination_hashes = list(Identity.known_destinations.keys())
|
|
131
|
+
for destination_hash in destination_hashes:
|
|
132
|
+
entry = Identity.known_destinations.get(destination_hash)
|
|
133
|
+
if not entry: continue
|
|
134
|
+
if target_hash == Identity.truncated_hash(entry[2]):
|
|
132
135
|
if not _no_use: RNS.Reticulum.get_instance()._used_destination_data(destination_hash)
|
|
133
|
-
identity_data = Identity.known_destinations[destination_hash]
|
|
134
136
|
identity = Identity(create_keys=False)
|
|
135
|
-
identity.load_public_key(
|
|
136
|
-
identity.app_data =
|
|
137
|
+
identity.load_public_key(entry[2])
|
|
138
|
+
identity.app_data = entry[3]
|
|
137
139
|
return identity
|
|
138
140
|
|
|
139
141
|
return None
|
|
@@ -212,8 +214,17 @@ class Identity:
|
|
|
212
214
|
RNS.log("Skipped recombining known destinations from disk, since an error occurred: "+str(e), RNS.LOG_WARNING)
|
|
213
215
|
|
|
214
216
|
RNS.log("Saving "+str(len(Identity.known_destinations))+" known destinations to storage...", RNS.LOG_VERBOSE)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
+
temp_file = RNS.Reticulum.storagepath+f"/known_destinations.tmp.{time.time()}"
|
|
218
|
+
|
|
219
|
+
try:
|
|
220
|
+
with open(temp_file,"wb") as file: umsgpack.dump(Identity.known_destinations.copy(), file)
|
|
221
|
+
os.rename(temp_file, RNS.Reticulum.storagepath+f"/known_destinations")
|
|
222
|
+
|
|
223
|
+
except Exception as e:
|
|
224
|
+
RNS.log(f"Error while serializing and writing known destinations: {e}", RNS.LOG_ERROR)
|
|
225
|
+
try: os.unlink(temp_file)
|
|
226
|
+
except Exception as e: RNS.log(f"Could not clean up temporary file {temp_file}: {e}", RNS.LOG_WARNING)
|
|
227
|
+
raise e
|
|
217
228
|
|
|
218
229
|
save_time = time.time() - save_start
|
|
219
230
|
if save_time < 1: time_str = str(round(save_time*1000,2))+"ms"
|
|
@@ -285,8 +296,11 @@ class Identity:
|
|
|
285
296
|
def _retain_identity(identity_hash):
|
|
286
297
|
try:
|
|
287
298
|
retained = False
|
|
288
|
-
|
|
289
|
-
|
|
299
|
+
with Identity.known_destinations_lock: destination_hashes = list(Identity.known_destinations.keys())
|
|
300
|
+
for destination_hash in destination_hashes:
|
|
301
|
+
entry = Identity.known_destinations.get(destination_hash)
|
|
302
|
+
if not entry: continue
|
|
303
|
+
if identity_hash == Identity.truncated_hash(entry[2]):
|
|
290
304
|
if Identity._retain_destination_data(destination_hash): retained = True
|
|
291
305
|
|
|
292
306
|
return retained
|
|
@@ -302,7 +316,9 @@ class Identity:
|
|
|
302
316
|
no_path = 0
|
|
303
317
|
retained = 0
|
|
304
318
|
never_used = 0
|
|
305
|
-
|
|
319
|
+
|
|
320
|
+
with Identity.known_destinations_lock: destination_hashes = list(Identity.known_destinations.keys())
|
|
321
|
+
for destination_hash in destination_hashes:
|
|
306
322
|
try:
|
|
307
323
|
if RNS.Transport.has_path(destination_hash): has_path = True
|
|
308
324
|
else:
|
|
@@ -3405,6 +3405,14 @@ class Transport:
|
|
|
3405
3405
|
|
|
3406
3406
|
@staticmethod
|
|
3407
3407
|
def blackhole_identity(identity_hash, until=None, reason=None):
|
|
3408
|
+
"""
|
|
3409
|
+
Blackholes an identity.
|
|
3410
|
+
|
|
3411
|
+
:param identity_hash: The identity hash to blackhole as *bytes*.
|
|
3412
|
+
:param until: Optional unix timestamp of when the blackhole expires as *float* or *int*.
|
|
3413
|
+
:param reason: Optional reason for the blackhole as *str*.
|
|
3414
|
+
:returns: *True* if successful, otherwise *False*.
|
|
3415
|
+
"""
|
|
3408
3416
|
try:
|
|
3409
3417
|
if not identity_hash in Transport.blackholed_identities:
|
|
3410
3418
|
entry = {"source": Transport.identity.hash, "until": until, "reason": reason}
|
|
@@ -3422,6 +3430,12 @@ class Transport:
|
|
|
3422
3430
|
|
|
3423
3431
|
@staticmethod
|
|
3424
3432
|
def unblackhole_identity(identity_hash):
|
|
3433
|
+
"""
|
|
3434
|
+
Lifts blackhole for an identity.
|
|
3435
|
+
|
|
3436
|
+
:param identity_hash: The identity hash to blackhole as *bytes*.
|
|
3437
|
+
:returns: *True* if successful, otherwise *False*.
|
|
3438
|
+
"""
|
|
3425
3439
|
try:
|
|
3426
3440
|
if identity_hash in Transport.blackholed_identities:
|
|
3427
3441
|
Transport.blackholed_identities.pop(identity_hash)
|
|
@@ -864,7 +864,7 @@ class NomadNetworkNode():
|
|
|
864
864
|
author = commit["author"]
|
|
865
865
|
date = self.format_absolute_time(commit["timestamp"])+" - "+self.format_relative_time(commit["timestamp"])
|
|
866
866
|
|
|
867
|
-
hash_link = self.m_link(short_hash, self.PATH_COMMIT, g=group_name, r=repo_name, h=commit["hash"])
|
|
867
|
+
hash_link = self.m_link(short_hash, self.PATH_COMMIT, g=group_name, r=repo_name, ref=ref, h=commit["hash"])
|
|
868
868
|
|
|
869
869
|
content_parts.append(f"`F66d{hash_link}`f {self.m_escape(author)} {self.CLR_DIM}{date}`f\n")
|
|
870
870
|
content_parts.append(f"{self.m_escape(subject)}\n\n")
|
|
@@ -891,6 +891,7 @@ class NomadNetworkNode():
|
|
|
891
891
|
if not data or not type(data) == dict: data = {}
|
|
892
892
|
group_name = data.get("var_g", "") if data else ""
|
|
893
893
|
repo_name = data.get("var_r", "") if data else ""
|
|
894
|
+
ref = data.get("var_ref", "HEAD") if data else "HEAD"
|
|
894
895
|
commit_hash = data.get("var_h", "") if data else ""
|
|
895
896
|
|
|
896
897
|
if not group_name or not repo_name:
|
|
@@ -904,6 +905,12 @@ class NomadNetworkNode():
|
|
|
904
905
|
|
|
905
906
|
repo_path = repo["path"]
|
|
906
907
|
|
|
908
|
+
# Validate ref exists
|
|
909
|
+
resolved_ref = self.resolve_ref(repo_path, ref)
|
|
910
|
+
if not resolved_ref:
|
|
911
|
+
content = self.m_heading("Ref Not Found", 1) + f"\n\nThe ref '{ref}' does not exist in this repository.\n"
|
|
912
|
+
return self.render_template(content, st=st)
|
|
913
|
+
|
|
907
914
|
# Validate commit hash
|
|
908
915
|
if not commit_hash or len(commit_hash) < 7:
|
|
909
916
|
content = self.m_heading("Error", 2) + "\nNo valid commit hash specified.\n"
|
|
@@ -917,7 +924,7 @@ class NomadNetworkNode():
|
|
|
917
924
|
|
|
918
925
|
# Breadcrumb navigation
|
|
919
926
|
nav_parts = []
|
|
920
|
-
breadcrumb = f"{self.m_link('Node', self.PATH_INDEX)} / {self.m_link(group_name, self.PATH_GROUP, g=group_name)} / {self.m_link(repo_name, self.PATH_REPO, g=group_name, r=repo_name)} / {resolved_hash[:7]}"
|
|
927
|
+
breadcrumb = f"{self.m_link('Node', self.PATH_INDEX)} / {self.m_link(group_name, self.PATH_GROUP, g=group_name)} / {self.m_link(repo_name, self.PATH_REPO, g=group_name, r=repo_name)} / {self.m_link('commits', self.PATH_COMMITS, g=group_name, r=repo_name, ref=ref)} / {resolved_hash[:7]}"
|
|
921
928
|
nav_parts.append(">>\n" + breadcrumb + "\n")
|
|
922
929
|
nav_content = "".join(nav_parts)
|
|
923
930
|
|
|
@@ -955,7 +962,7 @@ class NomadNetworkNode():
|
|
|
955
962
|
if commit_info.get("parents"):
|
|
956
963
|
parent_links = []
|
|
957
964
|
for parent_hash in commit_info["parents"]:
|
|
958
|
-
parent_link = self.m_link(parent_hash[:7], self.PATH_COMMIT, g=group_name, r=repo_name, h=parent_hash)
|
|
965
|
+
parent_link = self.m_link(parent_hash[:7], self.PATH_COMMIT, g=group_name, r=repo_name, ref=ref, h=parent_hash)
|
|
959
966
|
parent_links.append(parent_link)
|
|
960
967
|
|
|
961
968
|
content_parts.append(f"Parents: {' '.join(parent_links)}\n")
|
|
@@ -971,7 +978,7 @@ class NomadNetworkNode():
|
|
|
971
978
|
|
|
972
979
|
# Commit message
|
|
973
980
|
if commit_info.get("message"):
|
|
974
|
-
content_parts.append(self.
|
|
981
|
+
content_parts.append(self.format_commit(commit_info["message"]) + "\n")
|
|
975
982
|
content_parts.append("\n")
|
|
976
983
|
|
|
977
984
|
# Changed files
|
|
@@ -1140,7 +1147,7 @@ class NomadNetworkNode():
|
|
|
1140
1147
|
|
|
1141
1148
|
# Breadcrumb navigation
|
|
1142
1149
|
repo_link = self.m_link(repo_name, self.PATH_REPO, g=group_name, r=repo_name)
|
|
1143
|
-
breadcrumb = f">>\n{self.m_link('Node', self.PATH_INDEX)} / {self.m_link(group_name, self.PATH_GROUP, g=group_name)} / {repo_link}"
|
|
1150
|
+
breadcrumb = f">>\n{self.m_link('Node', self.PATH_INDEX)} / {self.m_link(group_name, self.PATH_GROUP, g=group_name)} / {repo_link} / stats"
|
|
1144
1151
|
nav_parts.append(breadcrumb + "\n")
|
|
1145
1152
|
|
|
1146
1153
|
repo = self.get_accessible_repository(remote_identity, group_name, repo_name)
|
|
@@ -2338,6 +2345,15 @@ class NomadNetworkNode():
|
|
|
2338
2345
|
|
|
2339
2346
|
return "\n".join(formatted_lines)
|
|
2340
2347
|
|
|
2348
|
+
def format_commit(self, diff_text):
|
|
2349
|
+
lines = diff_text.replace("\\", "\\\\").split("\n")
|
|
2350
|
+
formatted_lines = []
|
|
2351
|
+
|
|
2352
|
+
for line in lines:
|
|
2353
|
+
if line.startswith("-"): formatted_lines.append(self.m_escape(f"\\{line}"))
|
|
2354
|
+
else: formatted_lines.append(self.m_escape(line))
|
|
2355
|
+
|
|
2356
|
+
return "\n".join(formatted_lines)
|
|
2341
2357
|
|
|
2342
2358
|
def repository_thanks(self, repo_path, add=False, link_id=None):
|
|
2343
2359
|
if add:
|
|
@@ -2465,7 +2481,7 @@ class NomadNetworkNode():
|
|
|
2465
2481
|
line = "│"
|
|
2466
2482
|
for val in data:
|
|
2467
2483
|
upper_filled = val >= row_top
|
|
2468
|
-
lower_filled = val >= row_mid
|
|
2484
|
+
lower_filled = val >= row_mid or row == 1 and val > 0
|
|
2469
2485
|
|
|
2470
2486
|
if not upper_filled and not lower_filled: line += " "
|
|
2471
2487
|
elif upper_filled: line += f"`FT{gradient_color(grad_top)}`BT{gradient_color(grad_mid)}▀`f`b"
|