rns 1.4.0__tar.gz → 1.4.2__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.4.0/rns.egg-info → rns-1.4.2}/PKG-INFO +1 -1
- {rns-1.4.0 → rns-1.4.2}/RNS/Channel.py +74 -205
- {rns-1.4.0 → rns-1.4.2}/RNS/Destination.py +15 -4
- {rns-1.4.0 → rns-1.4.2}/RNS/Discovery.py +27 -6
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/AutoInterface.py +1 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/BackboneInterface.py +1 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/I2PInterface.py +93 -225
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/Interface.py +7 -5
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/TCPInterface.py +1 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/WeaveInterface.py +1 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Link.py +77 -42
- {rns-1.4.0 → rns-1.4.2}/RNS/Reticulum.py +65 -6
- {rns-1.4.0 → rns-1.4.2}/RNS/Transport.py +107 -48
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsd.py +25 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/__init__.py +6 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/initiator.py +25 -48
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/listener.py +4 -6
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/process.py +0 -16
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/rnsh.py +2 -2
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/session.py +7 -3
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnstatus.py +6 -2
- rns-1.4.2/RNS/_version.py +1 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/aiosam.py +23 -42
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/exceptions.py +9 -12
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/sam.py +2 -5
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/tunnel.py +58 -67
- {rns-1.4.0 → rns-1.4.2/rns.egg-info}/PKG-INFO +1 -1
- rns-1.4.0/RNS/_version.py +0 -1
- {rns-1.4.0 → rns-1.4.2}/CRNS/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/README.md +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Buffer.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/AES.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/Ed25519.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/HKDF.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/HMAC.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/Hashes.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/PKCS7.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/Provider.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/Proxies.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/SHA256.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/SHA512.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/Token.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/X25519.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/aes/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/aes/aes128.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/aes/aes256.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/pure25519/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/pure25519/_ed25519.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/pure25519/basic.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/pure25519/ed25519_oop.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Cryptography/pure25519/eddsa.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Identity.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/AX25KISSInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/Android/KISSInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/Android/RNodeInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/Android/SerialInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/Android/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/KISSInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/LocalInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/PipeInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/RNodeInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/RNodeMultiInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/SerialInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/UDPInterface.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/util/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Interfaces/util/netinfo.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Packet.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Resolver.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Resource.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rncp.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/client.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/commitsigs.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/highlight.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/main.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/pages.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/server.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rngit/util.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnid.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnir.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnodeconf.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnpath.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnpkg.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnprobe.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/_version.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/args.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/exception.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/helpers.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/loop.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/protocol.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnsh/retry.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/Utilities/rnx.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/configobj.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/__init__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/__version__.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/log.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/i2plib/utils.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/platformutils.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/umsgpack.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/RNS/vendor/validate.py +0 -0
- {rns-1.4.0 → rns-1.4.2}/rns.egg-info/SOURCES.txt +0 -0
- {rns-1.4.0 → rns-1.4.2}/rns.egg-info/dependency_links.txt +0 -0
- {rns-1.4.0 → rns-1.4.2}/rns.egg-info/entry_points.txt +0 -0
- {rns-1.4.0 → rns-1.4.2}/rns.egg-info/requires.txt +0 -0
- {rns-1.4.0 → rns-1.4.2}/rns.egg-info/top_level.txt +0 -0
- {rns-1.4.0 → rns-1.4.2}/setup.cfg +0 -0
- {rns-1.4.0 → rns-1.4.2}/setup.py +0 -0
|
@@ -45,63 +45,6 @@ TPacket = TypeVar("TPacket")
|
|
|
45
45
|
class SystemMessageTypes(enum.IntEnum):
|
|
46
46
|
SMT_STREAM_DATA = 0xff00
|
|
47
47
|
|
|
48
|
-
class ChannelOutletBase(ABC, Generic[TPacket]):
|
|
49
|
-
"""
|
|
50
|
-
An abstract transport layer interface used by Channel.
|
|
51
|
-
|
|
52
|
-
DEPRECATED: This was created for testing; eventually
|
|
53
|
-
Channel will use Link or a LinkBase interface
|
|
54
|
-
directly.
|
|
55
|
-
"""
|
|
56
|
-
@abstractmethod
|
|
57
|
-
def send(self, raw: bytes) -> TPacket:
|
|
58
|
-
raise NotImplemented()
|
|
59
|
-
|
|
60
|
-
@abstractmethod
|
|
61
|
-
def resend(self, packet: TPacket) -> TPacket:
|
|
62
|
-
raise NotImplemented()
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
@abstractmethod
|
|
66
|
-
def mdu(self):
|
|
67
|
-
raise NotImplemented()
|
|
68
|
-
|
|
69
|
-
@property
|
|
70
|
-
@abstractmethod
|
|
71
|
-
def rtt(self):
|
|
72
|
-
raise NotImplemented()
|
|
73
|
-
|
|
74
|
-
@property
|
|
75
|
-
@abstractmethod
|
|
76
|
-
def is_usable(self):
|
|
77
|
-
raise NotImplemented()
|
|
78
|
-
|
|
79
|
-
@abstractmethod
|
|
80
|
-
def get_packet_state(self, packet: TPacket) -> MessageState:
|
|
81
|
-
raise NotImplemented()
|
|
82
|
-
|
|
83
|
-
@abstractmethod
|
|
84
|
-
def timed_out(self):
|
|
85
|
-
raise NotImplemented()
|
|
86
|
-
|
|
87
|
-
@abstractmethod
|
|
88
|
-
def __str__(self):
|
|
89
|
-
raise NotImplemented()
|
|
90
|
-
|
|
91
|
-
@abstractmethod
|
|
92
|
-
def set_packet_timeout_callback(self, packet: TPacket, callback: Callable[[TPacket], None] | None,
|
|
93
|
-
timeout: float | None = None):
|
|
94
|
-
raise NotImplemented()
|
|
95
|
-
|
|
96
|
-
@abstractmethod
|
|
97
|
-
def set_packet_delivered_callback(self, packet: TPacket, callback: Callable[[TPacket], None] | None):
|
|
98
|
-
raise NotImplemented()
|
|
99
|
-
|
|
100
|
-
@abstractmethod
|
|
101
|
-
def get_packet_id(self, packet: TPacket) -> any:
|
|
102
|
-
raise NotImplemented()
|
|
103
|
-
|
|
104
|
-
|
|
105
48
|
class CEType(enum.IntEnum):
|
|
106
49
|
"""
|
|
107
50
|
ChannelException type codes
|
|
@@ -113,7 +56,6 @@ class CEType(enum.IntEnum):
|
|
|
113
56
|
ME_ALREADY_SENT = 4
|
|
114
57
|
ME_TOO_BIG = 5
|
|
115
58
|
|
|
116
|
-
|
|
117
59
|
class ChannelException(Exception):
|
|
118
60
|
"""
|
|
119
61
|
An exception thrown by Channel, with a type code.
|
|
@@ -122,7 +64,6 @@ class ChannelException(Exception):
|
|
|
122
64
|
super().__init__(args)
|
|
123
65
|
self.type = ce_type
|
|
124
66
|
|
|
125
|
-
|
|
126
67
|
class MessageState(enum.IntEnum):
|
|
127
68
|
"""
|
|
128
69
|
Set of possible states for a Message
|
|
@@ -132,7 +73,6 @@ class MessageState(enum.IntEnum):
|
|
|
132
73
|
MSGSTATE_DELIVERED = 2
|
|
133
74
|
MSGSTATE_FAILED = 3
|
|
134
75
|
|
|
135
|
-
|
|
136
76
|
class MessageBase(abc.ABC):
|
|
137
77
|
"""
|
|
138
78
|
Base type for any messages sent or received on a Channel.
|
|
@@ -170,7 +110,6 @@ class MessageBase(abc.ABC):
|
|
|
170
110
|
|
|
171
111
|
MessageCallbackType = NewType("MessageCallbackType", Callable[[MessageBase], bool])
|
|
172
112
|
|
|
173
|
-
|
|
174
113
|
class Envelope:
|
|
175
114
|
"""
|
|
176
115
|
Internal wrapper used to transport messages over a channel and
|
|
@@ -180,8 +119,7 @@ class Envelope:
|
|
|
180
119
|
msgtype, self.sequence, length = struct.unpack(">HHH", self.raw[:6])
|
|
181
120
|
raw = self.raw[6:]
|
|
182
121
|
ctor = message_factories.get(msgtype, None)
|
|
183
|
-
if ctor is None:
|
|
184
|
-
raise ChannelException(CEType.ME_NOT_REGISTERED, f"Unable to find constructor for Channel MSGTYPE {hex(msgtype)}")
|
|
122
|
+
if ctor is None: raise ChannelException(CEType.ME_NOT_REGISTERED, f"Unable to find constructor for Channel MSGTYPE {hex(msgtype)}")
|
|
185
123
|
message = ctor()
|
|
186
124
|
message.unpack(raw)
|
|
187
125
|
self.unpacked = True
|
|
@@ -190,14 +128,13 @@ class Envelope:
|
|
|
190
128
|
return message
|
|
191
129
|
|
|
192
130
|
def pack(self) -> bytes:
|
|
193
|
-
if self.message.__class__.MSGTYPE is None:
|
|
194
|
-
raise ChannelException(CEType.ME_NO_MSG_TYPE, f"{self.message.__class__} lacks MSGTYPE")
|
|
131
|
+
if self.message.__class__.MSGTYPE is None: raise ChannelException(CEType.ME_NO_MSG_TYPE, f"{self.message.__class__} lacks MSGTYPE")
|
|
195
132
|
data = self.message.pack()
|
|
196
133
|
self.raw = struct.pack(">HHH", self.message.MSGTYPE, self.sequence, len(data)) + data
|
|
197
134
|
self.packed = True
|
|
198
135
|
return self.raw
|
|
199
136
|
|
|
200
|
-
def __init__(self, outlet:
|
|
137
|
+
def __init__(self, outlet: LinkChannelOutlet, message: MessageBase = None, raw: bytes = None, sequence: int = None):
|
|
201
138
|
self.ts = time.time()
|
|
202
139
|
self.id = id(self)
|
|
203
140
|
self.message = message
|
|
@@ -278,7 +215,7 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
278
215
|
SEQ_MAX = 0xFFFF
|
|
279
216
|
SEQ_MODULUS = SEQ_MAX+1
|
|
280
217
|
|
|
281
|
-
def __init__(self, outlet:
|
|
218
|
+
def __init__(self, outlet: LinkChannelOutlet):
|
|
282
219
|
"""
|
|
283
220
|
|
|
284
221
|
@param outlet:
|
|
@@ -307,11 +244,9 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
307
244
|
self.window_min = Channel.WINDOW_MIN
|
|
308
245
|
self.window_flexibility = Channel.WINDOW_FLEXIBILITY
|
|
309
246
|
|
|
310
|
-
def __enter__(self) -> Channel:
|
|
311
|
-
return self
|
|
247
|
+
def __enter__(self) -> Channel: return self
|
|
312
248
|
|
|
313
|
-
def __exit__(self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None,
|
|
314
|
-
__traceback: TracebackType | None) -> bool | None:
|
|
249
|
+
def __exit__(self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None) -> bool | None:
|
|
315
250
|
self._shutdown()
|
|
316
251
|
return False
|
|
317
252
|
|
|
@@ -327,20 +262,13 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
327
262
|
|
|
328
263
|
def _register_message_type(self, message_class: Type[MessageBase], *, is_system_type: bool = False):
|
|
329
264
|
with self._lock:
|
|
330
|
-
if not issubclass(message_class, MessageBase):
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
f"{message_class} has invalid MSGTYPE class attribute.")
|
|
336
|
-
if message_class.MSGTYPE >= 0xf000 and not is_system_type:
|
|
337
|
-
raise ChannelException(CEType.ME_INVALID_MSG_TYPE,
|
|
338
|
-
f"{message_class} has system-reserved message type.")
|
|
339
|
-
try:
|
|
340
|
-
message_class()
|
|
265
|
+
if not issubclass(message_class, MessageBase): raise ChannelException(CEType.ME_INVALID_MSG_TYPE, f"{message_class} is not a subclass of {MessageBase}.")
|
|
266
|
+
if message_class.MSGTYPE is None: raise ChannelException(CEType.ME_INVALID_MSG_TYPE, f"{message_class} has invalid MSGTYPE class attribute.")
|
|
267
|
+
if message_class.MSGTYPE >= 0xf000 and not is_system_type: raise ChannelException(CEType.ME_INVALID_MSG_TYPE, f"{message_class} has system-reserved message type.")
|
|
268
|
+
|
|
269
|
+
try: message_class()
|
|
341
270
|
except Exception as ex:
|
|
342
|
-
raise ChannelException(CEType.ME_INVALID_MSG_TYPE,
|
|
343
|
-
f"{message_class} raised an exception when constructed with no arguments: {ex}")
|
|
271
|
+
raise ChannelException(CEType.ME_INVALID_MSG_TYPE, f"{message_class} raised an exception when constructed with no arguments: {ex}")
|
|
344
272
|
|
|
345
273
|
self._message_factories[message_class.MSGTYPE] = message_class
|
|
346
274
|
|
|
@@ -384,8 +312,10 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
384
312
|
self._outlet.set_packet_timeout_callback(envelope.packet, None)
|
|
385
313
|
self._outlet.set_packet_delivered_callback(envelope.packet, None)
|
|
386
314
|
envelope.tracked = False
|
|
315
|
+
|
|
387
316
|
for envelope in self._rx_ring:
|
|
388
317
|
envelope.tracked = False
|
|
318
|
+
|
|
389
319
|
self._tx_ring.clear()
|
|
390
320
|
self._rx_ring.clear()
|
|
391
321
|
|
|
@@ -394,14 +324,12 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
394
324
|
i = 0
|
|
395
325
|
|
|
396
326
|
for existing in ring:
|
|
397
|
-
|
|
398
327
|
if envelope.sequence == existing.sequence:
|
|
399
|
-
RNS.log(f"Envelope: Emplacement of duplicate envelope with sequence "+str(envelope.sequence), RNS.LOG_EXTREME)
|
|
328
|
+
RNS.log(f"Envelope: Emplacement of duplicate envelope with sequence "+str(envelope.sequence), RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
|
|
400
329
|
return False
|
|
401
330
|
|
|
402
331
|
if envelope.sequence < existing.sequence and not (self._next_rx_sequence - envelope.sequence) > (Channel.SEQ_MAX//2):
|
|
403
332
|
ring.insert(i, envelope)
|
|
404
|
-
|
|
405
333
|
envelope.tracked = True
|
|
406
334
|
return True
|
|
407
335
|
|
|
@@ -417,10 +345,8 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
417
345
|
|
|
418
346
|
for cb in cbs:
|
|
419
347
|
try:
|
|
420
|
-
if cb(message):
|
|
421
|
-
|
|
422
|
-
except Exception as e:
|
|
423
|
-
RNS.log("Channel "+str(self)+" experienced an error while running a message callback. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
|
348
|
+
if cb(message): return
|
|
349
|
+
except Exception as e: RNS.log(f"Channel {str(self)} experienced an error while running a message callback. The contained exception was: {e}", RNS.LOG_ERROR)
|
|
424
350
|
|
|
425
351
|
def _receive(self, raw: bytes):
|
|
426
352
|
try:
|
|
@@ -432,16 +358,20 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
432
358
|
window_overflow = (self._next_rx_sequence+Channel.WINDOW_MAX) % Channel.SEQ_MODULUS
|
|
433
359
|
if window_overflow < self._next_rx_sequence:
|
|
434
360
|
if envelope.sequence > window_overflow:
|
|
435
|
-
RNS.log("Invalid packet sequence (
|
|
361
|
+
RNS.log(f"Invalid packet sequence ({envelope.sequence}) received on channel {self}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
|
436
362
|
return
|
|
437
363
|
else:
|
|
438
|
-
RNS.log("Invalid packet sequence (
|
|
364
|
+
RNS.log(f"Invalid packet sequence ({envelope.sequence}) received on channel {self}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
|
439
365
|
return
|
|
440
366
|
|
|
367
|
+
elif envelope.sequence > self._next_rx_sequence + self.WINDOW_MAX:
|
|
368
|
+
RNS.log(f"Invalid packet sequence ({envelope.sequence}) received on channel {self}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
|
369
|
+
return
|
|
370
|
+
|
|
441
371
|
is_new = self._emplace_envelope(envelope, self._rx_ring)
|
|
442
372
|
|
|
443
373
|
if not is_new:
|
|
444
|
-
RNS.log("Duplicate message received on channel "+str(self), RNS.LOG_EXTREME)
|
|
374
|
+
RNS.log("Duplicate message received on channel "+str(self), RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
|
|
445
375
|
return
|
|
446
376
|
else:
|
|
447
377
|
with self._lock:
|
|
@@ -457,10 +387,8 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
457
387
|
self._next_rx_sequence = (self._next_rx_sequence + 1) % Channel.SEQ_MODULUS
|
|
458
388
|
|
|
459
389
|
for e in contigous:
|
|
460
|
-
if not e.unpacked:
|
|
461
|
-
|
|
462
|
-
else:
|
|
463
|
-
m = e.message
|
|
390
|
+
if not e.unpacked: m = e.unpack(self._message_factories)
|
|
391
|
+
else: m = e.message
|
|
464
392
|
|
|
465
393
|
self._rx_ring.remove(e)
|
|
466
394
|
self._run_callbacks(m)
|
|
@@ -474,9 +402,7 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
474
402
|
|
|
475
403
|
:return: True if ready
|
|
476
404
|
"""
|
|
477
|
-
if not self._outlet.is_usable:
|
|
478
|
-
return False
|
|
479
|
-
|
|
405
|
+
if not self._outlet.is_usable: return False
|
|
480
406
|
with self._lock:
|
|
481
407
|
outstanding = 0
|
|
482
408
|
for envelope in self._tx_ring:
|
|
@@ -484,59 +410,38 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
484
410
|
if not envelope.packet or not self._outlet.get_packet_state(envelope.packet) == MessageState.MSGSTATE_DELIVERED:
|
|
485
411
|
outstanding += 1
|
|
486
412
|
|
|
487
|
-
if outstanding >= self.window:
|
|
488
|
-
return False
|
|
413
|
+
if outstanding >= self.window: return False
|
|
489
414
|
|
|
490
415
|
return True
|
|
491
416
|
|
|
492
417
|
def _packet_tx_op(self, packet: TPacket, op: Callable[[TPacket], bool]):
|
|
493
418
|
target_id = self._outlet.get_packet_id(packet)
|
|
494
419
|
with self._lock:
|
|
495
|
-
envelope = next(filter(lambda e: e.packet is not None
|
|
496
|
-
and self._outlet.get_packet_id(e.packet) == target_id,
|
|
497
|
-
self._tx_ring), None)
|
|
498
|
-
|
|
420
|
+
envelope = next(filter(lambda e: e.packet is not None and self._outlet.get_packet_id(e.packet) == target_id, self._tx_ring), None)
|
|
499
421
|
if envelope and op(envelope):
|
|
500
422
|
envelope.tracked = False
|
|
501
423
|
if envelope in self._tx_ring:
|
|
502
424
|
self._tx_ring.remove(envelope)
|
|
503
425
|
|
|
504
|
-
if self.window < self.window_max:
|
|
505
|
-
self.window += 1
|
|
506
|
-
|
|
507
|
-
# TODO: Remove at some point
|
|
508
|
-
# RNS.log("Increased "+str(self)+" window to "+str(self.window), RNS.LOG_DEBUG)
|
|
426
|
+
if self.window < self.window_max: self.window += 1
|
|
509
427
|
|
|
510
428
|
if self._outlet.rtt != 0:
|
|
511
429
|
if self._outlet.rtt > Channel.RTT_FAST:
|
|
512
430
|
self.fast_rate_rounds = 0
|
|
513
|
-
|
|
514
|
-
if self._outlet.rtt > Channel.RTT_MEDIUM:
|
|
515
|
-
self.medium_rate_rounds = 0
|
|
516
|
-
|
|
431
|
+
if self._outlet.rtt > Channel.RTT_MEDIUM: self.medium_rate_rounds = 0
|
|
517
432
|
else:
|
|
518
433
|
self.medium_rate_rounds += 1
|
|
519
434
|
if self.window_max < Channel.WINDOW_MAX_MEDIUM and self.medium_rate_rounds == Channel.FAST_RATE_THRESHOLD:
|
|
520
435
|
self.window_max = Channel.WINDOW_MAX_MEDIUM
|
|
521
436
|
self.window_min = Channel.WINDOW_MIN_LIMIT_MEDIUM
|
|
522
|
-
# TODO: Remove at some point
|
|
523
|
-
# RNS.log("Increased "+str(self)+" max window to "+str(self.window_max), RNS.LOG_DEBUG)
|
|
524
|
-
# RNS.log("Increased "+str(self)+" min window to "+str(self.window_min), RNS.LOG_DEBUG)
|
|
525
|
-
|
|
526
437
|
else:
|
|
527
438
|
self.fast_rate_rounds += 1
|
|
528
439
|
if self.window_max < Channel.WINDOW_MAX_FAST and self.fast_rate_rounds == Channel.FAST_RATE_THRESHOLD:
|
|
529
440
|
self.window_max = Channel.WINDOW_MAX_FAST
|
|
530
441
|
self.window_min = Channel.WINDOW_MIN_LIMIT_FAST
|
|
531
|
-
# TODO: Remove at some point
|
|
532
|
-
# RNS.log("Increased "+str(self)+" max window to "+str(self.window_max), RNS.LOG_DEBUG)
|
|
533
|
-
# RNS.log("Increased "+str(self)+" min window to "+str(self.window_min), RNS.LOG_DEBUG)
|
|
534
|
-
|
|
535
442
|
|
|
536
|
-
else:
|
|
537
|
-
|
|
538
|
-
if not envelope:
|
|
539
|
-
RNS.log("Spurious message received on "+str(self), RNS.LOG_EXTREME)
|
|
443
|
+
else: RNS.log("Envelope not found in TX ring for "+str(self), RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
|
|
444
|
+
if not envelope: RNS.log("Spurious message received on "+str(self), RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None
|
|
540
445
|
|
|
541
446
|
def _packet_delivered(self, packet: TPacket):
|
|
542
447
|
self._packet_tx_op(packet, lambda env: True)
|
|
@@ -545,29 +450,23 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
545
450
|
for envelope in self._tx_ring:
|
|
546
451
|
updated_timeout = self._get_packet_timeout_time(envelope.tries)
|
|
547
452
|
if envelope.packet and hasattr(envelope.packet, "receipt") and envelope.packet.receipt and envelope.packet.receipt.timeout:
|
|
548
|
-
if updated_timeout > envelope.packet.receipt.timeout:
|
|
549
|
-
envelope.packet.receipt.set_timeout(updated_timeout)
|
|
453
|
+
if updated_timeout > envelope.packet.receipt.timeout: envelope.packet.receipt.set_timeout(updated_timeout)
|
|
550
454
|
|
|
551
455
|
def _get_packet_timeout_time(self, tries: int) -> float:
|
|
552
456
|
to = pow(1.5, tries - 1) * max(self._outlet.rtt*2.5, 0.025) * (len(self._tx_ring)+1.5)
|
|
553
457
|
return to
|
|
554
458
|
|
|
555
459
|
def _packet_timeout(self, packet: TPacket):
|
|
556
|
-
if self._outlet.get_packet_state(packet) == MessageState.MSGSTATE_DELIVERED:
|
|
557
|
-
return
|
|
460
|
+
if self._outlet.get_packet_state(packet) == MessageState.MSGSTATE_DELIVERED: return
|
|
558
461
|
|
|
559
462
|
target_id = self._outlet.get_packet_id(packet)
|
|
560
463
|
envelope_to_resend: Envelope | None = None
|
|
561
464
|
should_teardown = False
|
|
562
465
|
with self._lock:
|
|
563
|
-
envelope = next(filter(
|
|
564
|
-
|
|
565
|
-
self._tx_ring), None)
|
|
566
|
-
if envelope is None:
|
|
567
|
-
return
|
|
466
|
+
envelope = next(filter(lambda e: e.packet is not None and self._outlet.get_packet_id(e.packet) == target_id, self._tx_ring), None)
|
|
467
|
+
if envelope is None: return
|
|
568
468
|
|
|
569
|
-
if envelope.tries >= self._max_tries:
|
|
570
|
-
should_teardown = True
|
|
469
|
+
if envelope.tries >= self._max_tries: should_teardown = True
|
|
571
470
|
else:
|
|
572
471
|
envelope.tries += 1
|
|
573
472
|
envelope_to_resend = envelope
|
|
@@ -587,14 +486,11 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
587
486
|
self._outlet.resend(envelope_to_resend.packet)
|
|
588
487
|
with self._lock:
|
|
589
488
|
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))
|
|
489
|
+
self._outlet.set_packet_timeout_callback(envelope_to_resend.packet, self._packet_timeout, self._get_packet_timeout_time(envelope_to_resend.tries))
|
|
593
490
|
self._update_packet_timeouts()
|
|
594
491
|
already_delivered = (self._outlet.get_packet_state(envelope_to_resend.packet) == MessageState.MSGSTATE_DELIVERED)
|
|
595
492
|
|
|
596
|
-
if already_delivered:
|
|
597
|
-
self._packet_delivered(envelope_to_resend.packet)
|
|
493
|
+
if already_delivered: self._packet_delivered(envelope_to_resend.packet)
|
|
598
494
|
|
|
599
495
|
def send(self, message: MessageBase) -> Envelope:
|
|
600
496
|
"""
|
|
@@ -605,24 +501,19 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
605
501
|
"""
|
|
606
502
|
with self._send_lock:
|
|
607
503
|
with self._lock:
|
|
608
|
-
if not self.is_ready_to_send():
|
|
609
|
-
raise ChannelException(CEType.ME_LINK_NOT_READY, f"Link is not ready")
|
|
504
|
+
if not self.is_ready_to_send(): raise ChannelException(CEType.ME_LINK_NOT_READY, f"Link is not ready")
|
|
610
505
|
|
|
611
506
|
reserved_sequence = self._next_sequence
|
|
612
507
|
envelope = Envelope(self._outlet, message=message, sequence=reserved_sequence)
|
|
613
508
|
envelope.pack()
|
|
614
509
|
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}")
|
|
510
|
+
raise ChannelException(CEType.ME_TOO_BIG, f"Packed message too big for packet: {len(envelope.raw)} > {self._outlet.mdu}")
|
|
617
511
|
self._next_sequence = (reserved_sequence + 1) % Channel.SEQ_MODULUS
|
|
618
512
|
|
|
619
513
|
envelope.packet = self._outlet.send(envelope.raw)
|
|
620
514
|
|
|
621
|
-
if (envelope.packet is None
|
|
622
|
-
|
|
623
|
-
or (hasattr(envelope.packet, "receipt") and envelope.packet.receipt is None)):
|
|
624
|
-
with self._lock:
|
|
625
|
-
self._next_sequence = reserved_sequence
|
|
515
|
+
if envelope.packet is None or getattr(envelope.packet, "raw", None) is None or (hasattr(envelope.packet, "receipt") and envelope.packet.receipt is None):
|
|
516
|
+
with self._lock: self._next_sequence = reserved_sequence
|
|
626
517
|
raise ChannelException(CEType.ME_LINK_NOT_READY, "Outlet did not transmit packet")
|
|
627
518
|
|
|
628
519
|
with self._lock:
|
|
@@ -633,9 +524,8 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
633
524
|
self._update_packet_timeouts()
|
|
634
525
|
already_delivered = (self._outlet.get_packet_state(envelope.packet) == MessageState.MSGSTATE_DELIVERED)
|
|
635
526
|
|
|
636
|
-
#
|
|
637
|
-
if already_delivered:
|
|
638
|
-
self._packet_delivered(envelope.packet)
|
|
527
|
+
# Prevent _tx_ring envelope leak
|
|
528
|
+
if already_delivered: self._packet_delivered(envelope.packet)
|
|
639
529
|
|
|
640
530
|
return envelope
|
|
641
531
|
|
|
@@ -650,14 +540,13 @@ class Channel(contextlib.AbstractContextManager):
|
|
|
650
540
|
:return: number of bytes available
|
|
651
541
|
"""
|
|
652
542
|
mdu = self._outlet.mdu - 6 # sizeof(msgtype) + sizeof(length) + sizeof(sequence)
|
|
653
|
-
if mdu > 0xFFFF:
|
|
654
|
-
mdu = 0xFFFF
|
|
543
|
+
if mdu > 0xFFFF: mdu = 0xFFFF
|
|
655
544
|
return mdu
|
|
656
545
|
|
|
657
546
|
|
|
658
|
-
class LinkChannelOutlet(
|
|
547
|
+
class LinkChannelOutlet(ABC, Generic[TPacket]):
|
|
659
548
|
"""
|
|
660
|
-
|
|
549
|
+
A channel outlet implementation for RNS.Link.
|
|
661
550
|
Allows Channel to send packets over an RNS Link with
|
|
662
551
|
Packets.
|
|
663
552
|
|
|
@@ -668,71 +557,51 @@ class LinkChannelOutlet(ChannelOutletBase):
|
|
|
668
557
|
|
|
669
558
|
def send(self, raw: bytes) -> RNS.Packet:
|
|
670
559
|
packet = RNS.Packet(self.link, raw, context=RNS.Packet.CHANNEL)
|
|
671
|
-
if self.link.status == RNS.Link.ACTIVE:
|
|
672
|
-
packet.send()
|
|
560
|
+
if self.link.status == RNS.Link.ACTIVE: packet.send()
|
|
673
561
|
return packet
|
|
674
562
|
|
|
675
563
|
def resend(self, packet: RNS.Packet) -> RNS.Packet:
|
|
676
564
|
receipt = packet.resend()
|
|
677
|
-
if not receipt:
|
|
678
|
-
RNS.log("Failed to resend packet", RNS.LOG_ERROR)
|
|
565
|
+
if not receipt: RNS.log("Failed to resend packet", RNS.LOG_ERROR)
|
|
679
566
|
return packet
|
|
680
567
|
|
|
681
568
|
@property
|
|
682
|
-
def mdu(self):
|
|
683
|
-
return self.link.mdu
|
|
569
|
+
def mdu(self): return self.link.mdu
|
|
684
570
|
|
|
685
571
|
@property
|
|
686
|
-
def rtt(self):
|
|
687
|
-
return self.link.rtt
|
|
572
|
+
def rtt(self): return self.link.rtt
|
|
688
573
|
|
|
574
|
+
# TODO: Initial implementation had issues
|
|
575
|
+
# proxying this to link status. Should
|
|
576
|
+
# return False when link is not ACTIVE.
|
|
577
|
+
# Investigate what happened here.
|
|
689
578
|
@property
|
|
690
|
-
def is_usable(self):
|
|
691
|
-
return True # had issues looking at Link.status
|
|
579
|
+
def is_usable(self): return True
|
|
692
580
|
|
|
693
581
|
def get_packet_state(self, packet: TPacket) -> MessageState:
|
|
694
582
|
if packet.receipt == None:
|
|
695
583
|
return MessageState.MSGSTATE_FAILED
|
|
696
584
|
|
|
697
585
|
status = packet.receipt.get_status()
|
|
698
|
-
if status == RNS.PacketReceipt.SENT:
|
|
699
|
-
|
|
700
|
-
if status == RNS.PacketReceipt.
|
|
701
|
-
|
|
702
|
-
if status == RNS.PacketReceipt.FAILED:
|
|
703
|
-
return MessageState.MSGSTATE_FAILED
|
|
704
|
-
else:
|
|
705
|
-
raise Exception(f"Unexpected receipt state: {status}")
|
|
706
|
-
|
|
707
|
-
def timed_out(self):
|
|
708
|
-
self.link.teardown()
|
|
709
|
-
|
|
710
|
-
def __str__(self):
|
|
711
|
-
return f"{self.__class__.__name__}({self.link})"
|
|
712
|
-
|
|
713
|
-
def set_packet_timeout_callback(self, packet: RNS.Packet, callback: Callable[[RNS.Packet], None] | None,
|
|
714
|
-
timeout: float | None = None):
|
|
715
|
-
if timeout and packet.receipt:
|
|
716
|
-
packet.receipt.set_timeout(timeout)
|
|
717
|
-
|
|
718
|
-
def inner(receipt: RNS.PacketReceipt):
|
|
719
|
-
callback(packet)
|
|
586
|
+
if status == RNS.PacketReceipt.SENT: return MessageState.MSGSTATE_SENT
|
|
587
|
+
if status == RNS.PacketReceipt.DELIVERED: return MessageState.MSGSTATE_DELIVERED
|
|
588
|
+
if status == RNS.PacketReceipt.FAILED: return MessageState.MSGSTATE_FAILED
|
|
589
|
+
else: raise Exception(f"Unexpected receipt state: {status}")
|
|
720
590
|
|
|
721
|
-
|
|
722
|
-
|
|
591
|
+
def set_packet_timeout_callback(self, packet: RNS.Packet, callback: Callable[[RNS.Packet], None] | None, timeout: float | None = None):
|
|
592
|
+
if timeout and packet.receipt: packet.receipt.set_timeout(timeout)
|
|
593
|
+
def inner(receipt: RNS.PacketReceipt): callback(packet)
|
|
594
|
+
if packet and packet.receipt: packet.receipt.set_timeout_callback(inner if callback else None)
|
|
723
595
|
|
|
724
596
|
def set_packet_delivered_callback(self, packet: RNS.Packet, callback: Callable[[RNS.Packet], None] | None):
|
|
725
|
-
def inner(receipt: RNS.PacketReceipt):
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
if packet and packet.receipt:
|
|
729
|
-
packet.receipt.set_delivery_callback(inner if callback else None)
|
|
597
|
+
def inner(receipt: RNS.PacketReceipt): callback(packet)
|
|
598
|
+
if packet and packet.receipt: packet.receipt.set_delivery_callback(inner if callback else None)
|
|
730
599
|
|
|
731
600
|
def get_packet_id(self, packet: RNS.Packet) -> any:
|
|
732
|
-
if (packet
|
|
733
|
-
and getattr(packet, "raw", None) is not None
|
|
734
|
-
and hasattr(packet, "get_hash")
|
|
735
|
-
and callable(packet.get_hash)):
|
|
601
|
+
if packet and getattr(packet, "raw", None) is not None and hasattr(packet, "get_hash") and callable(packet.get_hash):
|
|
736
602
|
return packet.get_hash()
|
|
737
|
-
else:
|
|
738
|
-
|
|
603
|
+
else: return None
|
|
604
|
+
|
|
605
|
+
def timed_out(self): self.link.teardown()
|
|
606
|
+
|
|
607
|
+
def __str__(self): return f"{self.__class__.__name__}({self.link})"
|
|
@@ -155,6 +155,7 @@ class Destination:
|
|
|
155
155
|
self.accept_link_requests = True
|
|
156
156
|
self.callbacks = Callbacks()
|
|
157
157
|
self.request_handlers = {}
|
|
158
|
+
self.max_request_size = None
|
|
158
159
|
self.type = type
|
|
159
160
|
self.direction = direction
|
|
160
161
|
self.proof_strategy = Destination.PROVE_NONE
|
|
@@ -362,10 +363,20 @@ class Destination:
|
|
|
362
363
|
|
|
363
364
|
:param proof_strategy: One of ``RNS.Destination.PROVE_NONE``, ``RNS.Destination.PROVE_ALL`` or ``RNS.Destination.PROVE_APP``. If ``RNS.Destination.PROVE_APP`` is set, the `proof_requested_callback` will be called to determine whether a proof should be sent or not.
|
|
364
365
|
"""
|
|
365
|
-
if not proof_strategy in Destination.proof_strategies:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
366
|
+
if not proof_strategy in Destination.proof_strategies: raise TypeError("Unsupported proof strategy")
|
|
367
|
+
else: self.proof_strategy = proof_strategy
|
|
368
|
+
|
|
369
|
+
def set_max_request_size(self, max_request_size):
|
|
370
|
+
"""
|
|
371
|
+
Sets the maximum accepted request size for registered request handlers.
|
|
372
|
+
|
|
373
|
+
:param max_request_size: The maximum accepted request size in bytes, as an integer.
|
|
374
|
+
:raises: ``TypeError`` or ``ValueError`` if any of the argument is invalid.
|
|
375
|
+
"""
|
|
376
|
+
try: max_request_size = int(max_request_size)
|
|
377
|
+
except: raise TypeError("Invalid maximum request size specified")
|
|
378
|
+
if max_request_size < 0: raise ValueError("Maximum request size cannot be negative")
|
|
379
|
+
self.max_request_size = max_request_size
|
|
369
380
|
|
|
370
381
|
def register_request_handler(self, path, response_generator = None, allow = ALLOW_NONE, allowed_list = None, auto_compress = True):
|
|
371
382
|
"""
|
|
@@ -331,7 +331,7 @@ class InterfaceAnnounceHandler:
|
|
|
331
331
|
if IFAC_NETKEY in unpacked: info["ifac_netkey"] = str(unpacked[IFAC_NETKEY])
|
|
332
332
|
|
|
333
333
|
if interface_type in ["BackboneInterface", "TCPServerInterface"]:
|
|
334
|
-
backbone_support = not RNS.vendor.platformutils.is_windows()
|
|
334
|
+
backbone_support = not RNS.vendor.platformutils.is_windows() and not RNS.vendor.platformutils.is_darwin()
|
|
335
335
|
info["reachable_on"] = unpacked[REACHABLE_ON]
|
|
336
336
|
info["port"] = unpacked[PORT]
|
|
337
337
|
connection_interface = "BackboneInterface" if backbone_support else "TCPClientInterface"
|
|
@@ -430,6 +430,9 @@ class InterfaceDiscovery():
|
|
|
430
430
|
AUTOCONNECT_TYPES = ["BackboneInterface", "TCPServerInterface"]
|
|
431
431
|
DISCOVERABLE_TYPES = ["BackboneInterface", "TCPServerInterface", "I2PInterface", "RNodeInterface", "WeaveInterface", "KISSInterface"]
|
|
432
432
|
|
|
433
|
+
AC_TRANSPORT_MODE = RNS.Interfaces.Interface.Interface.MODE_GATEWAY
|
|
434
|
+
AC_GRAVITY = 0
|
|
435
|
+
|
|
433
436
|
discovery_lock = Lock()
|
|
434
437
|
|
|
435
438
|
def __init__(self, required_value=InterfaceAnnouncer.DEFAULT_STAMP_VALUE, callback=None, discover_interfaces=True):
|
|
@@ -443,6 +446,8 @@ class InterfaceDiscovery():
|
|
|
443
446
|
self.monitor_interval = self.MONITOR_INTERVAL
|
|
444
447
|
self.detach_threshold = self.DETACH_THRESHOLD
|
|
445
448
|
self.initial_autoconnect_ran = False
|
|
449
|
+
self.blackholed_updated = 0
|
|
450
|
+
self.__blackholed = {}
|
|
446
451
|
|
|
447
452
|
if not self.rns_instance: raise SystemError("Attempt to start interface discovery listener without an active RNS instance")
|
|
448
453
|
self.storagepath = os.path.join(RNS.Reticulum.storagepath, "discovery", "interfaces")
|
|
@@ -453,10 +458,18 @@ class InterfaceDiscovery():
|
|
|
453
458
|
RNS.Transport.register_announce_handler(self.handler)
|
|
454
459
|
threading.Thread(target=self.connect_discovered, daemon=True).start()
|
|
455
460
|
|
|
461
|
+
def __blackholed_identities(self):
|
|
462
|
+
st = time.time()
|
|
463
|
+
if not self.__blackholed or time.time() > self.blackholed_updated+60:
|
|
464
|
+
self.__blackholed = self.rns_instance.get_blackholed_identities()
|
|
465
|
+
self.blackholed_updated = time.time()
|
|
466
|
+
return self.__blackholed
|
|
467
|
+
|
|
456
468
|
def list_discovered_interfaces(self, only_available=False, only_transport=False):
|
|
457
469
|
now = time.time()
|
|
458
470
|
discovered_interfaces = []
|
|
459
471
|
discovery_sources = RNS.Reticulum.interface_discovery_sources()
|
|
472
|
+
blackholed_identities = self.__blackholed_identities()
|
|
460
473
|
for filename in os.listdir(self.storagepath):
|
|
461
474
|
try:
|
|
462
475
|
with self.discovery_lock:
|
|
@@ -464,13 +477,17 @@ class InterfaceDiscovery():
|
|
|
464
477
|
with open(filepath, "rb") as f: info = msgpack.unpackb(f.read())
|
|
465
478
|
|
|
466
479
|
should_remove = False
|
|
467
|
-
heard_delta
|
|
468
|
-
info["name"]
|
|
480
|
+
heard_delta = now-info["last_heard"]
|
|
481
|
+
info["name"] = InterfaceAnnounceHandler.sanitize_name(info["name"])
|
|
469
482
|
|
|
470
|
-
if
|
|
483
|
+
if heard_delta > self.THRESHOLD_REMOVE: should_remove = True
|
|
484
|
+
elif not "transport_id" in info or not info["transport_id"]: should_remove = True
|
|
485
|
+
elif not "network_id" in info or not info["network_id"]: should_remove = True
|
|
471
486
|
elif discovery_sources and not "network_id" in info: should_remove = True
|
|
472
487
|
elif discovery_sources and not bytes.fromhex(info["network_id"]) in discovery_sources: should_remove = True
|
|
473
488
|
elif not "type" in info or ("type" in info and not info["type"] in self.DISCOVERABLE_TYPES): should_remove = True
|
|
489
|
+
elif bytes.fromhex(info["network_id"]) in blackholed_identities: should_remove = True
|
|
490
|
+
elif bytes.fromhex(info["transport_id"]) in blackholed_identities: should_remove = True
|
|
474
491
|
elif "reachable_on" in info:
|
|
475
492
|
if not (is_ip_address(info["reachable_on"]) or is_hostname(info["reachable_on"])): should_remove = True
|
|
476
493
|
|
|
@@ -722,12 +739,16 @@ class InterfaceDiscovery():
|
|
|
722
739
|
RNS.log(f"Auto-connecting discovered {interface_type} {interface_name}")
|
|
723
740
|
interface.autoconnect_hash = endpoint_hash
|
|
724
741
|
interface.autoconnect_source = info["network_id"]
|
|
725
|
-
|
|
742
|
+
if RNS.Reticulum.autoconnect_interface_mode(): mode = RNS.Reticulum.autoconnect_interface_mode()
|
|
743
|
+
else: mode = self.AC_TRANSPORT_MODE if RNS.Reticulum.transport_enabled() else None
|
|
744
|
+
internal_a = True if RNS.Reticulum.autoconnect_announces_to_internal() else None
|
|
745
|
+
gravity = RNS.Reticulum.autoconnect_interface_gravity() or self.AC_GRAVITY
|
|
726
746
|
ar_target = RNS.Reticulum.get_instance()._default_ar_target() if RNS.Reticulum.transport_enabled() else None
|
|
727
747
|
ar_penalty = RNS.Reticulum.get_instance()._default_ar_penalty() if RNS.Reticulum.transport_enabled() else None
|
|
728
748
|
ar_grace = RNS.Reticulum.get_instance()._default_ar_grace() if RNS.Reticulum.transport_enabled() else None
|
|
729
749
|
RNS.Reticulum.get_instance()._add_interface(interface, mode=mode, ifac_netname=ifac_netname, ifac_netkey=ifac_netkey, configured_bitrate=5E6,
|
|
730
|
-
announce_rate_target=ar_target, announce_rate_grace=ar_grace, announce_rate_penalty=ar_penalty
|
|
750
|
+
announce_rate_target=ar_target, announce_rate_grace=ar_grace, announce_rate_penalty=ar_penalty,
|
|
751
|
+
announces_to_internal=internal_a, gravity=gravity)
|
|
731
752
|
self.monitor_interface(interface)
|
|
732
753
|
|
|
733
754
|
except Exception as e:
|