Skip to content

Commit a08145f

Browse files
committed
chore: clean up multiaddr re-exports
1 parent 68767d1 commit a08145f

File tree

1 file changed

+24
-44
lines changed

1 file changed

+24
-44
lines changed
Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,50 @@
11
"""Re-export of the multiaddr library."""
22

33
from multiaddr import Multiaddr
4-
from multiaddr.protocols import (
5-
P_TCP,
6-
P_IP4,
7-
P_IP6,
8-
P_DNS,
9-
P_UDP,
10-
P_P2P,
11-
Protocol
12-
)
13-
14-
__all__ = [
15-
"Multiaddr",
16-
"Protocol",
17-
"is_valid_address"
18-
]
19-
20-
PROTOCOL_CONFIG = {
21-
P_IP4: {
22-
'transports': [P_TCP, P_UDP],
23-
'overlays': [P_P2P]
24-
},
25-
P_IP6: {
26-
'transports': [P_TCP, P_UDP],
27-
'overlays': [P_P2P]
28-
},
29-
P_DNS: {
30-
'transports': [P_TCP],
31-
'overlays': [P_P2P]
32-
}
4+
from multiaddr.protocols import (P_DNS, P_IP4, P_IP6, P_P2P, P_TCP, P_UDP,
5+
Protocol)
6+
7+
__all__ = ["Multiaddr", "Protocol", "is_valid_address"]
8+
9+
_PROTOCOL_CONFIG = {
10+
P_IP4: {"transports": [P_TCP, P_UDP], "overlays": [P_P2P]},
11+
P_IP6: {"transports": [P_TCP, P_UDP], "overlays": [P_P2P]},
12+
P_DNS: {"transports": [P_TCP], "overlays": [P_P2P]},
3313
}
3414

15+
3516
def _generate_supported_protocols():
3617
"""Generate all valid protocol combinations."""
3718
protocols = set()
38-
39-
for network, config in PROTOCOL_CONFIG.items():
40-
for transport in config['transports']:
19+
20+
for network, config in _PROTOCOL_CONFIG.items():
21+
for transport in config["transports"]:
4122

4223
base_combo = (network, transport)
4324
protocols.add(base_combo)
44-
45-
for overlay in config['overlays']:
25+
26+
for overlay in config["overlays"]:
4627
protocols.add(base_combo + (overlay,))
47-
28+
4829
return protocols
4930

50-
SUPPORTED_PROTOCOLS = _generate_supported_protocols()
31+
32+
_SUPPORTED_PROTOCOLS = _generate_supported_protocols()
33+
5134

5235
def is_valid_address(addr: Multiaddr) -> bool:
5336
"""
5437
Check if a multiaddr uses only supported protocols.
55-
38+
5639
synlink network only supports a subset of multiaddr protocols.
57-
58-
59-
Example
40+
41+
42+
### Example:
6043
```
6144
"/ip4/127.0.0.1/tcp/8080",
6245
"/ip6/::1/tcp/8080",
6346
"/dns/example.com/tcp/443/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N"
6447
```
6548
"""
6649
protocol_tuple = tuple(protocol.code for protocol in addr.protocols())
67-
return protocol_tuple in SUPPORTED_PROTOCOLS
68-
69-
70-
50+
return protocol_tuple in _SUPPORTED_PROTOCOLS

0 commit comments

Comments
 (0)