rns 1.2.3__tar.gz → 1.2.5__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.
Files changed (111) hide show
  1. {rns-1.2.3 → rns-1.2.5}/PKG-INFO +1 -1
  2. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/Ed25519.py +0 -1
  3. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/Hashes.py +4 -0
  4. {rns-1.2.3 → rns-1.2.5}/RNS/Discovery.py +57 -16
  5. {rns-1.2.3 → rns-1.2.5}/RNS/Identity.py +46 -15
  6. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/AutoInterface.py +5 -0
  7. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/BackboneInterface.py +82 -13
  8. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/I2PInterface.py +11 -0
  9. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/Interface.py +120 -29
  10. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/LocalInterface.py +6 -0
  11. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/RNodeMultiInterface.py +6 -0
  12. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/TCPInterface.py +12 -1
  13. {rns-1.2.3 → rns-1.2.5}/RNS/Packet.py +5 -4
  14. {rns-1.2.3 → rns-1.2.5}/RNS/Resource.py +29 -29
  15. {rns-1.2.3 → rns-1.2.5}/RNS/Reticulum.py +174 -20
  16. {rns-1.2.3 → rns-1.2.5}/RNS/Transport.py +272 -192
  17. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/highlight.py +35 -12
  18. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/pages.py +70 -50
  19. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/server.py +450 -115
  20. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/util.py +69 -10
  21. rns-1.2.5/RNS/Utilities/rnid.py +802 -0
  22. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnpath.py +4 -4
  23. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnstatus.py +101 -21
  24. {rns-1.2.3 → rns-1.2.5}/RNS/__init__.py +12 -4
  25. rns-1.2.5/RNS/_version.py +1 -0
  26. {rns-1.2.3 → rns-1.2.5}/rns.egg-info/PKG-INFO +1 -1
  27. rns-1.2.3/RNS/Utilities/rnid.py +0 -612
  28. rns-1.2.3/RNS/_version.py +0 -1
  29. {rns-1.2.3 → rns-1.2.5}/CRNS/__init__.py +0 -0
  30. {rns-1.2.3 → rns-1.2.5}/README.md +0 -0
  31. {rns-1.2.3 → rns-1.2.5}/RNS/Buffer.py +0 -0
  32. {rns-1.2.3 → rns-1.2.5}/RNS/Channel.py +0 -0
  33. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/AES.py +0 -0
  34. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/HKDF.py +0 -0
  35. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/HMAC.py +0 -0
  36. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/PKCS7.py +0 -0
  37. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/Provider.py +0 -0
  38. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/Proxies.py +0 -0
  39. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/SHA256.py +0 -0
  40. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/SHA512.py +0 -0
  41. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/Token.py +0 -0
  42. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/X25519.py +0 -0
  43. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/__init__.py +0 -0
  44. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/aes/__init__.py +0 -0
  45. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/aes/aes128.py +0 -0
  46. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/aes/aes256.py +0 -0
  47. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/pure25519/__init__.py +0 -0
  48. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/pure25519/_ed25519.py +0 -0
  49. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/pure25519/basic.py +0 -0
  50. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/pure25519/ed25519_oop.py +0 -0
  51. {rns-1.2.3 → rns-1.2.5}/RNS/Cryptography/pure25519/eddsa.py +0 -0
  52. {rns-1.2.3 → rns-1.2.5}/RNS/Destination.py +0 -0
  53. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/AX25KISSInterface.py +0 -0
  54. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/Android/KISSInterface.py +0 -0
  55. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/Android/RNodeInterface.py +0 -0
  56. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/Android/SerialInterface.py +0 -0
  57. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/Android/__init__.py +0 -0
  58. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/KISSInterface.py +0 -0
  59. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/PipeInterface.py +0 -0
  60. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/RNodeInterface.py +0 -0
  61. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/SerialInterface.py +0 -0
  62. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/UDPInterface.py +0 -0
  63. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/WeaveInterface.py +0 -0
  64. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/__init__.py +0 -0
  65. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/util/__init__.py +0 -0
  66. {rns-1.2.3 → rns-1.2.5}/RNS/Interfaces/util/netinfo.py +0 -0
  67. {rns-1.2.3 → rns-1.2.5}/RNS/Link.py +0 -0
  68. {rns-1.2.3 → rns-1.2.5}/RNS/Resolver.py +0 -0
  69. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/__init__.py +0 -0
  70. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rncp.py +0 -0
  71. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/__init__.py +0 -0
  72. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/client.py +0 -0
  73. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rngit/main.py +0 -0
  74. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnir.py +0 -0
  75. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnodeconf.py +0 -0
  76. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnpkg.py +0 -0
  77. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnprobe.py +0 -0
  78. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsd.py +0 -0
  79. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/__init__.py +0 -0
  80. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/_version.py +0 -0
  81. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/args.py +0 -0
  82. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/exception.py +0 -0
  83. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/helpers.py +0 -0
  84. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/initiator.py +0 -0
  85. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/listener.py +0 -0
  86. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/loop.py +0 -0
  87. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/process.py +0 -0
  88. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/protocol.py +0 -0
  89. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/retry.py +0 -0
  90. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/rnsh.py +0 -0
  91. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnsh/session.py +0 -0
  92. {rns-1.2.3 → rns-1.2.5}/RNS/Utilities/rnx.py +0 -0
  93. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/__init__.py +0 -0
  94. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/configobj.py +0 -0
  95. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/__init__.py +0 -0
  96. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/__version__.py +0 -0
  97. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/aiosam.py +0 -0
  98. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/exceptions.py +0 -0
  99. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/log.py +0 -0
  100. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/sam.py +0 -0
  101. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/tunnel.py +0 -0
  102. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/i2plib/utils.py +0 -0
  103. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/platformutils.py +0 -0
  104. {rns-1.2.3 → rns-1.2.5}/RNS/vendor/umsgpack.py +0 -0
  105. {rns-1.2.3 → rns-1.2.5}/rns.egg-info/SOURCES.txt +0 -0
  106. {rns-1.2.3 → rns-1.2.5}/rns.egg-info/dependency_links.txt +0 -0
  107. {rns-1.2.3 → rns-1.2.5}/rns.egg-info/entry_points.txt +0 -0
  108. {rns-1.2.3 → rns-1.2.5}/rns.egg-info/requires.txt +0 -0
  109. {rns-1.2.3 → rns-1.2.5}/rns.egg-info/top_level.txt +0 -0
  110. {rns-1.2.3 → rns-1.2.5}/setup.cfg +0 -0
  111. {rns-1.2.3 → rns-1.2.5}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rns
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: Self-configuring, encrypted and resilient mesh networking stack for LoRa, packet radio, WiFi and everything in between
5
5
  Home-page: https://reticulum.network/
6
6
  Author: Mark Qvist
@@ -35,7 +35,6 @@ class Ed25519PrivateKey:
35
35
  def __init__(self, seed):
36
36
  self.seed = seed
37
37
  self.sk = ed25519.SigningKey(self.seed)
38
- #self.vk = self.sk.get_verifying_key()
39
38
 
40
39
  @classmethod
41
40
  def generate(cls):
@@ -62,3 +62,7 @@ def sha512(data):
62
62
  digest.update(data)
63
63
 
64
64
  return digest.digest()
65
+
66
+ def file_sha256(file):
67
+ if not hashlib: raise SystemError("The hashlib module is not available on this system")
68
+ else: return hashlib.file_digest(file, "sha256").digest()
@@ -200,6 +200,15 @@ class InterfaceAnnounceHandler:
200
200
  self.callback = callback
201
201
  self.stamper = LXStamper
202
202
 
203
+ @staticmethod
204
+ def sanitize_name(name):
205
+ if not name: return None
206
+ name = name.encode("ascii", "ignore").decode("ascii").strip()
207
+ for i in [5,3,2]: name = name.replace(" "*i, " ")
208
+ while len(name) and name[0] not in san_map: name = name[1:]
209
+ while len(name) and name[-1] not in san_map+")": name = name[:-1]
210
+ return name
211
+
203
212
  def received_announce(self, destination_hash, announced_identity, app_data):
204
213
  try:
205
214
  discovery_sources = RNS.Reticulum.interface_discovery_sources()
@@ -234,10 +243,24 @@ class InterfaceAnnounceHandler:
234
243
  info = None
235
244
  unpacked = msgpack.unpackb(packed)
236
245
  if INTERFACE_TYPE in unpacked:
237
- interface_type = unpacked[INTERFACE_TYPE]
246
+ interface_type = unpacked[INTERFACE_TYPE]
247
+ name = self.sanitize_name(unpacked[NAME])
248
+
249
+ if type(unpacked[TRANSPORT]) != bool: raise ValueError("Invalid data in transport field of announce")
250
+ if type(unpacked[LATITUDE]) not in [type(None), float]: raise ValueError("Invalid data in latitude field of announce")
251
+ if type(unpacked[LONGITUDE]) not in [type(None), float]: raise ValueError("Invalid data in longitude field of announce")
252
+ if type(unpacked[HEIGHT]) not in [type(None), float]: raise ValueError("Invalid data in height field of announce")
253
+ if len(unpacked[TRANSPORT_ID]) != RNS.Identity.TRUNCATED_HASHLENGTH//8: raise ValueError("Invalid data in transport_id field of announce")
254
+ if not interface_type in InterfaceAnnouncer.DISCOVERABLE_INTERFACE_TYPES:
255
+ raise ValueError("Invalid interface type in announce data")
256
+
257
+ if REACHABLE_ON in unpacked:
258
+ if not (is_ip_address(unpacked[REACHABLE_ON]) or is_hostname(unpacked[REACHABLE_ON])):
259
+ raise ValueError("Invalid data in reachable_on field of announce")
260
+
238
261
  info = {"type": interface_type,
239
262
  "transport": unpacked[TRANSPORT],
240
- "name": unpacked[NAME] or f"Discovered {interface_type}",
263
+ "name": name or f"Discovered {interface_type}",
241
264
  "received": time.time(),
242
265
  "stamp": stamp,
243
266
  "value": value,
@@ -248,12 +271,8 @@ class InterfaceAnnounceHandler:
248
271
  "longitude": unpacked[LONGITUDE],
249
272
  "height": unpacked[HEIGHT]}
250
273
 
251
- if REACHABLE_ON in unpacked:
252
- if not (is_ip_address(unpacked[REACHABLE_ON]) or is_hostname(unpacked[REACHABLE_ON])):
253
- raise ValueError("Invalid data in reachable_on field of announce")
254
-
255
- if IFAC_NETNAME in unpacked: info["ifac_netname"] = unpacked[IFAC_NETNAME]
256
- if IFAC_NETKEY in unpacked: info["ifac_netkey"] = unpacked[IFAC_NETKEY]
274
+ if IFAC_NETNAME in unpacked: info["ifac_netname"] = str(unpacked[IFAC_NETNAME])
275
+ if IFAC_NETKEY in unpacked: info["ifac_netkey"] = str(unpacked[IFAC_NETKEY])
257
276
 
258
277
  if interface_type in ["BackboneInterface", "TCPServerInterface"]:
259
278
  backbone_support = not RNS.vendor.platformutils.is_windows()
@@ -386,6 +405,7 @@ class InterfaceDiscovery():
386
405
  with open(filepath, "rb") as f: info = msgpack.unpackb(f.read())
387
406
  should_remove = False
388
407
  heard_delta = now-info["last_heard"]
408
+ info["name"] = InterfaceAnnounceHandler.sanitize_name(info["name"])
389
409
 
390
410
  if heard_delta > self.THRESHOLD_REMOVE: should_remove = True
391
411
  elif discovery_sources and not "network_id" in info: should_remove = True
@@ -450,12 +470,15 @@ class InterfaceDiscovery():
450
470
  discovered = None
451
471
  heard_count = None
452
472
  try:
453
- with open(filepath, "rb") as f:
454
- last_info = msgpack.unpackb(f.read())
455
- discovered = last_info["discovered"]
456
- heard_count = last_info["heard_count"]
473
+ try:
474
+ with open(filepath, "rb") as f:
475
+ last_info = msgpack.unpackb(f.read())
476
+ discovered = last_info["discovered"]
477
+ heard_count = last_info["heard_count"]
457
478
 
458
- if discovered == None: discovered = info["discovered"]
479
+ except Exception as e: RNS.log(f"Error while reading existing data for discovered interface, re-creating data", RNS.LOG_ERROR)
480
+
481
+ if discovered == None: discovered = info["received"]
459
482
  if heard_count == None: heard_count = 0
460
483
 
461
484
  with open(filepath, "wb") as f:
@@ -489,7 +512,7 @@ class InterfaceDiscovery():
489
512
  threading.Thread(target=self.__monitor_job, daemon=True).start()
490
513
 
491
514
  def __monitor_job(self):
492
- while self.monitoring_autoconnects:
515
+ while self.monitoring_autoconnects and RNS.Transport._should_run:
493
516
  time.sleep(self.monitor_interval)
494
517
  detached_interfaces = []
495
518
  online_interfaces = 0
@@ -616,8 +639,11 @@ class InterfaceDiscovery():
616
639
  RNS.log(f"You can obtain the configuration entry and add this interface manually instead using rnstatus -D", RNS.LOG_WARNING)
617
640
  return
618
641
 
642
+ if is_ygg_ipv6(info["reachable_on"]):
643
+ # TODO: Somehow detect if yggdrasil is enabled on the system
644
+ return
645
+
619
646
  interface_name = info["name"]
620
- RNS.log(f"Auto-connecting discovered {interface_type} {interface_name}")
621
647
  config_entry = info["config_entry"]
622
648
  interface_config = {}
623
649
  interface_config["name"] = f"{interface_name}"
@@ -632,9 +658,15 @@ class InterfaceDiscovery():
632
658
  interface = BackboneInterface.BackboneClientInterface(RNS.Transport, interface_config)
633
659
 
634
660
  if interface:
661
+ RNS.log(f"Auto-connecting discovered {interface_type} {interface_name}")
635
662
  interface.autoconnect_hash = endpoint_hash
636
663
  interface.autoconnect_source = info["network_id"]
637
- RNS.Reticulum.get_instance()._add_interface(interface, ifac_netname=ifac_netname, ifac_netkey=ifac_netkey, configured_bitrate=5E6)
664
+ mode = RNS.Interfaces.Interface.Interface.MODE_GATEWAY if RNS.Reticulum.transport_enabled() else None
665
+ ar_target = RNS.Reticulum.get_instance()._default_ar_target() if RNS.Reticulum.transport_enabled() else None
666
+ ar_penalty = RNS.Reticulum.get_instance()._default_ar_penalty() if RNS.Reticulum.transport_enabled() else None
667
+ ar_grace = RNS.Reticulum.get_instance()._default_ar_grace() if RNS.Reticulum.transport_enabled() else None
668
+ RNS.Reticulum.get_instance()._add_interface(interface, mode=mode, ifac_netname=ifac_netname, ifac_netkey=ifac_netkey, configured_bitrate=5E6,
669
+ announce_rate_target=ar_target, announce_rate_grace=ar_grace, announce_rate_penalty=ar_penalty)
638
670
  self.monitor_interface(interface)
639
671
 
640
672
  except Exception as e:
@@ -733,6 +765,10 @@ def is_ip_address(address_string):
733
765
  return True
734
766
  except: return False
735
767
 
768
+ def is_ygg_ipv6(address_string):
769
+ try: return ipaddress.ip_address(address_string) in ipaddress.IPv6Network("200::/7")
770
+ except: return False
771
+
736
772
  def is_hostname(hostname):
737
773
  if hostname[-1] == ".": hostname = hostname[:-1]
738
774
  if len(hostname) > 253: return False
@@ -740,3 +776,8 @@ def is_hostname(hostname):
740
776
  if re.match(r"[0-9]+$", components[-1]): return False
741
777
  allowed = re.compile(r"(?!-)[a-z0-9-]{1,63}(?<!-)$", re.IGNORECASE)
742
778
  return all(allowed.match(label) for label in components)
779
+
780
+ san_map = ""
781
+ for i in range(48, 58): san_map += bytes([i]).decode("ascii")
782
+ for i in range(65, 91): san_map += bytes([i]).decode("ascii")
783
+ for i in range(97, 123): san_map += bytes([i]).decode("ascii")
@@ -76,6 +76,7 @@ class Identity:
76
76
  # Non-configurable constants
77
77
  TOKEN_OVERHEAD = RNS.Cryptography.Token.TOKEN_OVERHEAD
78
78
  AES128_BLOCKSIZE = 16 # In bytes
79
+ AES256_BLOCKSIZE = 16 # In bytes
79
80
  HASHLENGTH = 256 # In bits
80
81
  SIGLENGTH = KEYSIZE # In bits
81
82
 
@@ -279,6 +280,18 @@ class Identity:
279
280
  return True
280
281
 
281
282
  return False
283
+
284
+ @staticmethod
285
+ def _retain_identity(identity_hash):
286
+ try:
287
+ retained = False
288
+ for destination_hash in Identity.known_destinations:
289
+ if identity_hash == Identity.truncated_hash(Identity.known_destinations[destination_hash][2]):
290
+ if Identity._retain_destination_data(destination_hash): retained = True
291
+
292
+ return retained
293
+
294
+ except Exception as e: RNS.log(f"Error while retaining identity {RNS.prettyhexrep(identity_hash)}: {e}", RNS.LOG_ERROR)
282
295
 
283
296
  @staticmethod
284
297
  def clean_known_destinations():
@@ -321,7 +334,7 @@ class Identity:
321
334
  if not was_used and now - last_announce > RNS.Transport.UNUSED_DESTINATION_LINGER: stale.append(destination_hash)
322
335
  elif unused_for > RNS.Transport.DESTINATION_TIMEOUT*1.25: stale.append(destination_hash)
323
336
 
324
- except Exception as e: RNS.log(f"Faulty entry for {RNS.prettyhexrep(destination_hash)} while cleaning known destinations: {e}", RNS.LOG_DEBUG)
337
+ except Exception as e: RNS.log(f"Faulty entry for {RNS.prettyhexrep(destination_hash)} while cleaning known destinations: {e}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
325
338
 
326
339
  removed = 0
327
340
  for destination_hash in stale:
@@ -400,7 +413,7 @@ class Identity:
400
413
  ratchet_exists = False
401
414
 
402
415
  if not ratchet_exists:
403
- RNS.log(f"Remembering ratchet {RNS.prettyhexrep(Identity._get_ratchet_id(ratchet))} for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_EXTREME)
416
+ RNS.log(f"Remembering ratchet {RNS.prettyhexrep(Identity._get_ratchet_id(ratchet))} for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
404
417
  Identity.known_ratchets[destination_hash] = ratchet
405
418
  if not RNS.Transport.owner.is_connected_to_shared_instance:
406
419
  def persist_job():
@@ -429,7 +442,7 @@ class Identity:
429
442
 
430
443
  @staticmethod
431
444
  def _clean_ratchets():
432
- RNS.log("Cleaning ratchets...", RNS.LOG_DEBUG)
445
+ RNS.log("Cleaning ratchets...", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
433
446
  try:
434
447
  count = 0
435
448
  removed = 0
@@ -464,7 +477,7 @@ class Identity:
464
477
  RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
465
478
 
466
479
  except Exception as e: RNS.log(f"An error occurred while cleaning ratchets. The contained exception was: {e}", RNS.LOG_ERROR)
467
- RNS.log(f"Processed {count} ratchets in {RNS.prettytime(time.time()-now)}, not in use {not_known}, removed {removed}", RNS.LOG_DEBUG)
480
+ RNS.log(f"Processed {count} ratchets in {RNS.prettytime(time.time()-now)}, not in use {not_known}, removed {removed}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
468
481
 
469
482
  @staticmethod
470
483
  def get_ratchet(destination_hash):
@@ -489,7 +502,7 @@ class Identity:
489
502
  if destination_hash in Identity.known_ratchets:
490
503
  return Identity.known_ratchets[destination_hash]
491
504
  else:
492
- RNS.log(f"Could not load ratchet for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_DEBUG)
505
+ RNS.log(f"Could not load ratchet for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
493
506
  return None
494
507
 
495
508
  @staticmethod
@@ -537,7 +550,7 @@ class Identity:
537
550
 
538
551
  if len(RNS.Transport.blackholed_identities) > 0:
539
552
  if announced_identity.hash in RNS.Transport.blackholed_identities:
540
- RNS.log(f"Invalidated and dropped announce from blackholed identity {RNS.prettyhexrep(announced_identity.hash)}", RNS.LOG_EXTREME)
553
+ RNS.log(f"Invalidated and dropped announce from blackholed identity {RNS.prettyhexrep(announced_identity.hash)}", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
541
554
  return False
542
555
 
543
556
  if announced_identity.pub != None and announced_identity.validate(signature, signed_data):
@@ -575,9 +588,9 @@ class Identity:
575
588
  signal_str = ""
576
589
 
577
590
  if hasattr(packet, "transport_id") and packet.transport_id != None:
578
- RNS.log("Valid announce for "+RNS.prettyhexrep(destination_hash)+" "+str(packet.hops)+" hops away, received via "+RNS.prettyhexrep(packet.transport_id)+" on "+str(packet.receiving_interface)+signal_str, RNS.LOG_EXTREME)
591
+ RNS.log("Valid announce for "+RNS.prettyhexrep(destination_hash)+" "+str(packet.hops)+" hops away, received via "+RNS.prettyhexrep(packet.transport_id)+" on "+str(packet.receiving_interface)+signal_str, RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
579
592
  else:
580
- RNS.log("Valid announce for "+RNS.prettyhexrep(destination_hash)+" "+str(packet.hops)+" hops away, received on "+str(packet.receiving_interface)+signal_str, RNS.LOG_EXTREME)
593
+ RNS.log("Valid announce for "+RNS.prettyhexrep(destination_hash)+" "+str(packet.hops)+" hops away, received on "+str(packet.receiving_interface)+signal_str, RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
581
594
 
582
595
  if ratchet:
583
596
  Identity._remember_ratchet(destination_hash, ratchet)
@@ -585,11 +598,11 @@ class Identity:
585
598
  return True
586
599
 
587
600
  else:
588
- RNS.log("Received invalid announce for "+RNS.prettyhexrep(destination_hash)+": Destination mismatch.", RNS.LOG_DEBUG)
601
+ RNS.log("Received invalid announce for "+RNS.prettyhexrep(destination_hash)+": Destination mismatch.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
589
602
  return False
590
603
 
591
604
  else:
592
- RNS.log("Received invalid announce for "+RNS.prettyhexrep(destination_hash)+": Invalid signature.", RNS.LOG_DEBUG)
605
+ RNS.log("Received invalid announce for "+RNS.prettyhexrep(destination_hash)+": Invalid signature.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
593
606
  del announced_identity
594
607
  return False
595
608
 
@@ -656,6 +669,22 @@ class Identity:
656
669
  RNS.log("Error while saving identity to "+str(path), RNS.LOG_ERROR)
657
670
  RNS.log("The contained exception was: "+str(e))
658
671
 
672
+ def pub_to_file(self, path):
673
+ """
674
+ Saves the public identity to a file.
675
+
676
+ :param path: The full path specifying where to save the identity.
677
+ :returns: True if the file was saved, otherwise False.
678
+ """
679
+ try:
680
+ with open(path, "wb") as key_file:
681
+ key_file.write(self.get_public_key())
682
+ return True
683
+ return False
684
+ except Exception as e:
685
+ RNS.log("Error while saving identity to "+str(path), RNS.LOG_ERROR)
686
+ RNS.log("The contained exception was: "+str(e))
687
+
659
688
  def __init__(self,create_keys=True):
660
689
  # Initialize keys to none
661
690
  self.prv = None
@@ -695,13 +724,15 @@ class Identity:
695
724
  """
696
725
  :returns: The private key as *bytes*
697
726
  """
698
- return self.prv_bytes+self.sig_prv_bytes
727
+ if self.prv_bytes and self.sig_prv_bytes: return self.prv_bytes+self.sig_prv_bytes
728
+ else: return None
699
729
 
700
730
  def get_public_key(self):
701
731
  """
702
732
  :returns: The public key as *bytes*
703
733
  """
704
- return self.pub_bytes+self.sig_pub_bytes
734
+ if self.pub_bytes and self.sig_pub_bytes: return self.pub_bytes+self.sig_pub_bytes
735
+ else: return None
705
736
 
706
737
  def load_private_key(self, prv_bytes):
707
738
  """
@@ -848,7 +879,7 @@ class Identity:
848
879
  pass
849
880
 
850
881
  if enforce_ratchets and plaintext == None:
851
- RNS.log("Decryption with ratchet enforcement by "+RNS.prettyhexrep(self.hash)+" failed. Dropping packet.", RNS.LOG_DEBUG)
882
+ RNS.log("Decryption with ratchet enforcement by "+RNS.prettyhexrep(self.hash)+" failed. Dropping packet.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
852
883
  if ratchet_id_receiver:
853
884
  ratchet_id_receiver.latest_ratchet_id = None
854
885
  return None
@@ -861,14 +892,14 @@ class Identity:
861
892
  ratchet_id_receiver.latest_ratchet_id = None
862
893
 
863
894
  except Exception as e:
864
- RNS.log("Decryption by "+RNS.prettyhexrep(self.hash)+" failed: "+str(e), RNS.LOG_DEBUG)
895
+ RNS.log("Decryption by "+RNS.prettyhexrep(self.hash)+" failed: "+str(e), RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
865
896
  if ratchet_id_receiver:
866
897
  ratchet_id_receiver.latest_ratchet_id = None
867
898
 
868
899
  return plaintext
869
900
 
870
901
  else:
871
- RNS.log("Decryption failed because the token size was invalid.", RNS.LOG_DEBUG)
902
+ RNS.log("Decryption failed because the token size was invalid.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
872
903
  return None
873
904
  else:
874
905
  raise KeyError("Decryption failed because identity does not hold a private key")
@@ -539,6 +539,11 @@ class AutoInterface(Interface):
539
539
  spawned_interface.ic_new_time = self.ic_new_time
540
540
  spawned_interface.ic_burst_penalty = self.ic_burst_penalty
541
541
  spawned_interface.ic_held_release_interval = self.ic_held_release_interval
542
+
543
+ spawned_interface.egress_control = self.egress_control
544
+ spawned_interface.ec_pr_freq = self.ec_pr_freq
545
+ spawned_interface.ic_pr_burst_freq_new = self.ic_pr_burst_freq_new
546
+ spawned_interface.ic_pr_burst_freq = self.ic_pr_burst_freq
542
547
 
543
548
  spawned_interface.parent_interface = self
544
549
  spawned_interface.bitrate = self.bitrate
@@ -156,6 +156,58 @@ class BackboneInterface(Interface):
156
156
  else:
157
157
  raise SystemError("Insufficient parameters to create listener")
158
158
 
159
+
160
+ __last_ic_burst_check = 0
161
+ __last_ic_burst_state = False
162
+ @property
163
+ def ic_burst_active(self):
164
+ if time.time() > self.__last_ic_burst_check + 2:
165
+ self.__last_ic_burst_state = any(i.ic_burst_active for i in self.spawned_interfaces)
166
+
167
+ return self.__last_ic_burst_state
168
+
169
+ @ic_burst_active.setter
170
+ def ic_burst_active(self, value): pass
171
+
172
+ __ic_burst_activated_check = 0
173
+ __ic_burst_activated = 0
174
+ @property
175
+ def ic_burst_activated(self):
176
+ if time.time() > self.__ic_burst_activated_check + 2:
177
+ activated = [i.ic_burst_activated for i in self.spawned_interfaces if i.ic_burst_active]
178
+ if activated: self.__ic_burst_activated = min(activated)
179
+
180
+ return self.__ic_burst_activated
181
+
182
+ @ic_burst_activated.setter
183
+ def ic_burst_activated(self, value): pass
184
+
185
+
186
+ __last_ic_pr_burst_check = 0
187
+ __last_ic_pr_burst_state = False
188
+ @property
189
+ def ic_pr_burst_active(self):
190
+ if time.time() > self.__last_ic_pr_burst_check + 2:
191
+ self.__last_ic_pr_burst_state = any(i.ic_pr_burst_active for i in self.spawned_interfaces)
192
+
193
+ return self.__last_ic_pr_burst_state
194
+
195
+ @ic_pr_burst_active.setter
196
+ def ic_pr_burst_active(self, value): pass
197
+
198
+ __ic_pr_burst_activated_check = 0
199
+ __ic_pr_burst_activated = 0
200
+ @property
201
+ def ic_pr_burst_activated(self):
202
+ if time.time() > self.__ic_pr_burst_activated_check + 2:
203
+ activated = [i.ic_pr_burst_activated for i in self.spawned_interfaces if i.ic_pr_burst_active]
204
+ if activated: self.__ic_pr_burst_activated = min(activated)
205
+
206
+ return self.__ic_pr_burst_activated
207
+
208
+ @ic_pr_burst_activated.setter
209
+ def ic_pr_burst_activated(self, value): pass
210
+
159
211
  @staticmethod
160
212
  def start():
161
213
  if not BackboneInterface._job_active: threading.Thread(target=BackboneInterface.__job, daemon=True).start()
@@ -196,17 +248,17 @@ class BackboneInterface(Interface):
196
248
  @staticmethod
197
249
  def register_in(fileno):
198
250
  if fileno < 0:
199
- RNS.log(f"Attempt to register invalid file descriptor {fileno}", RNS.LOG_ERROR)
251
+ RNS.log(f"Attempt to register invalid file descriptor {fileno}", RNS.LOG_WARNING)
200
252
  return
201
253
 
202
254
  try: BackboneInterface.epoll.register(fileno, select.EPOLLIN)
203
255
  except Exception as e:
204
- RNS.log(f"An error occurred while registering EPOLL_IN for file descriptor {fileno}: {e}", RNS.LOG_ERROR)
256
+ RNS.log(f"An error occurred while registering EPOLL_IN for file descriptor {fileno}: {e}", RNS.LOG_WARNING)
205
257
 
206
258
  @staticmethod
207
259
  def deregister_fileno(fileno):
208
260
  if fileno < 0:
209
- RNS.log(f"Attempt to deregister invalid file descriptor {fileno}", RNS.LOG_ERROR)
261
+ RNS.log(f"Attempt to deregister invalid file descriptor {fileno}", RNS.LOG_WARNING)
210
262
  return
211
263
 
212
264
  try: BackboneInterface.epoll.unregister(fileno)
@@ -288,7 +340,7 @@ class BackboneInterface(Interface):
288
340
  except Exception as e: RNS.log(f"Error while removing spawned interface from {pif}: {e}", RNS.LOG_ERROR)
289
341
 
290
342
  try: client_socket.close()
291
- except Exception as e: RNS.log(f"Error while closing socket for {spawned_interface}: {e}", RNS.LOG_ERROR)
343
+ except Exception as e: RNS.log(f"Error while closing socket for {spawned_interface}: {e}", RNS.LOG_WARNING)
292
344
  spawned_interface.receive(b"")
293
345
 
294
346
  spawned_interface.transmit_buffer = spawned_interface.transmit_buffer[written:]
@@ -320,18 +372,24 @@ class BackboneInterface(Interface):
320
372
  elif fileno in BackboneInterface.listener_filenos:
321
373
  owner_interface, server_socket = BackboneInterface.listener_filenos[fileno]
322
374
  if fileno == server_socket.fileno() and (event & select.EPOLLIN):
323
- client_socket, address = server_socket.accept()
324
- client_socket.setblocking(0)
325
- if not owner_interface.incoming_connection(client_socket):
375
+ try:
376
+ client_socket, address = server_socket.accept()
377
+ client_socket.setblocking(0)
378
+ if not owner_interface.incoming_connection(client_socket):
379
+ try: client_socket.close()
380
+ except Exception as e: RNS.log(f"Error while closing socket for failed incoming connection: {e}", RNS.LOG_WARNING)
381
+
382
+ except:
383
+ RNS.log(f"Accepting socket failed for incoming connection: {e}", RNS.LOG_WARNING)
326
384
  try: client_socket.close()
327
- except Exception as e: RNS.log(f"Error while closing socket for failed incoming connection: {e}", RNS.LOG_ERROR)
385
+ except Exception as e: RNS.log(f"Error while closing socket for failed incoming socket accept: {e}", RNS.LOG_WARNING)
328
386
 
329
387
  elif fileno == server_socket.fileno() and (event & select.EPOLLHUP):
330
388
  try: BackboneInterface.deregister_fileno(fileno)
331
389
  except Exception as e: RNS.log(f"Error while deregistering listener file descriptor {fileno}: {e}", RNS.LOG_ERROR)
332
390
 
333
391
  try: server_socket.close()
334
- except Exception as e: RNS.log(f"Error while closing listener socket for {server_socket}: {e}", RNS.LOG_ERROR)
392
+ except Exception as e: RNS.log(f"Error while closing listener socket for {server_socket}: {e}", RNS.LOG_WARNING)
335
393
 
336
394
  except Exception as e:
337
395
  RNS.log(f"BackboneInterface error: {e}", RNS.LOG_ERROR)
@@ -356,6 +414,11 @@ class BackboneInterface(Interface):
356
414
  spawned_interface.ic_new_time = self.ic_new_time
357
415
  spawned_interface.ic_burst_penalty = self.ic_burst_penalty
358
416
  spawned_interface.ic_held_release_interval = self.ic_held_release_interval
417
+
418
+ spawned_interface.egress_control = self.egress_control
419
+ spawned_interface.ec_pr_freq = self.ec_pr_freq
420
+ spawned_interface.ic_pr_burst_freq_new = self.ic_pr_burst_freq_new
421
+ spawned_interface.ic_pr_burst_freq = self.ic_pr_burst_freq
359
422
 
360
423
  spawned_interface.socket = socket
361
424
  spawned_interface.target_ip = socket.getpeername()[0]
@@ -408,6 +471,12 @@ class BackboneInterface(Interface):
408
471
  def sent_announce(self, from_spawned=False):
409
472
  if from_spawned: self.oa_freq_deque.append(time.time())
410
473
 
474
+ def received_path_request(self, from_spawned=False):
475
+ if from_spawned: self.ip_freq_deque.append(time.time())
476
+
477
+ def sent_path_request(self, from_spawned=False):
478
+ if from_spawned: self.op_freq_deque.append(time.time())
479
+
411
480
  def process_outgoing(self, data):
412
481
  pass
413
482
 
@@ -578,8 +647,8 @@ class BackboneClientInterface(Interface):
578
647
 
579
648
  except Exception as e:
580
649
  if initial:
581
- RNS.log("Initial connection for "+str(self)+" could not be established: "+str(e), RNS.LOG_ERROR)
582
- RNS.log("Leaving unconnected and retrying connection in "+str(BackboneClientInterface.RECONNECT_WAIT)+" seconds.", RNS.LOG_ERROR)
650
+ RNS.log("Initial connection for "+str(self)+" could not be established: "+str(e), RNS.LOG_WARNING)
651
+ RNS.log("Leaving unconnected and retrying connection in "+str(BackboneClientInterface.RECONNECT_WAIT)+" seconds.", RNS.LOG_WARNING)
583
652
  return False
584
653
 
585
654
  else:
@@ -602,7 +671,7 @@ class BackboneClientInterface(Interface):
602
671
  attempts += 1
603
672
 
604
673
  if self.max_reconnect_tries != None and attempts > self.max_reconnect_tries:
605
- RNS.log("Max reconnection attempts reached for "+str(self), RNS.LOG_ERROR)
674
+ RNS.log("Max reconnection attempts reached for "+str(self), RNS.LOG_WARNING)
606
675
  self.teardown()
607
676
  break
608
677
 
@@ -669,7 +738,7 @@ class BackboneClientInterface(Interface):
669
738
  def job(): self.reconnect()
670
739
  threading.Thread(target=job, daemon=True).start()
671
740
  else:
672
- RNS.log("The socket for remote client "+str(self)+" was closed.", RNS.LOG_VERBOSE)
741
+ RNS.log("The socket for remote client "+str(self)+" was closed.", RNS.LOG_DEBUG)
673
742
  self.teardown()
674
743
 
675
744
  except Exception as e:
@@ -957,6 +957,11 @@ class I2PInterface(Interface):
957
957
  spawned_interface.ic_new_time = self.ic_new_time
958
958
  spawned_interface.ic_burst_penalty = self.ic_burst_penalty
959
959
  spawned_interface.ic_held_release_interval = self.ic_held_release_interval
960
+
961
+ spawned_interface.egress_control = self.egress_control
962
+ spawned_interface.ec_pr_freq = self.ec_pr_freq
963
+ spawned_interface.ic_pr_burst_freq_new = self.ic_pr_burst_freq_new
964
+ spawned_interface.ic_pr_burst_freq = self.ic_pr_burst_freq
960
965
 
961
966
  spawned_interface.parent_interface = self
962
967
  spawned_interface.online = True
@@ -1003,6 +1008,12 @@ class I2PInterface(Interface):
1003
1008
  def sent_announce(self, from_spawned=False):
1004
1009
  if from_spawned: self.oa_freq_deque.append(time.time())
1005
1010
 
1011
+ def received_path_request(self, from_spawned=False):
1012
+ if from_spawned: self.ip_freq_deque.append(time.time())
1013
+
1014
+ def sent_path_request(self, from_spawned=False):
1015
+ if from_spawned: self.op_freq_deque.append(time.time())
1016
+
1006
1017
  def detach(self):
1007
1018
  RNS.log("Detaching "+str(self), RNS.LOG_DEBUG)
1008
1019
  self.i2p.stop()