Use `_tpt_proto_to_maddr` lookup in `mk_maddr()`
Address Copilot review: the mapping table was defined but never referenced. Now `mk_maddr()` resolves `proto_key` -> maddr protocol name via the table and rejects unknown keys upfront. Also add missing `Path` import to the `multiaddr` usage snippet. Review: PR #429 (Copilot) https://github.com/goodboy/tractor/pull/429#pullrequestreview-4010456884 (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codesubint_spawner_backend
parent
926e861f52
commit
c72d495d68
|
|
@ -1,4 +1,6 @@
|
|||
from pathlib import Path
|
||||
from multiaddr import Multiaddr
|
||||
|
||||
# construct from a string
|
||||
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
|
||||
m2 = Multiaddr("/unix/run/user/1000/sway-ipc.1000.1557.sock")
|
||||
|
|
|
|||
|
|
@ -50,7 +50,14 @@ def mk_maddr(
|
|||
multiaddr-spec-compliant protocol path.
|
||||
|
||||
'''
|
||||
match addr.proto_key:
|
||||
proto_key: str = addr.proto_key
|
||||
maddr_proto: str|None = _tpt_proto_to_maddr.get(proto_key)
|
||||
if maddr_proto is None:
|
||||
raise ValueError(
|
||||
f'Unsupported proto_key: {proto_key!r}'
|
||||
)
|
||||
|
||||
match proto_key:
|
||||
case 'tcp':
|
||||
host, port = addr.unwrap()
|
||||
ip = ipaddress.ip_address(host)
|
||||
|
|
@ -59,17 +66,12 @@ def mk_maddr(
|
|||
else 'ip6'
|
||||
)
|
||||
return Multiaddr(
|
||||
f'/{net_proto}/{host}/tcp/{port}'
|
||||
f'/{net_proto}/{host}/{maddr_proto}/{port}'
|
||||
)
|
||||
|
||||
case 'uds':
|
||||
filedir, filename = addr.unwrap()
|
||||
filepath = Path(filedir) / filename
|
||||
return Multiaddr(
|
||||
f'/unix/{filepath}'
|
||||
)
|
||||
|
||||
case _:
|
||||
raise ValueError(
|
||||
f'Unsupported proto_key: {addr.proto_key!r}'
|
||||
f'/{maddr_proto}/{filepath}'
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue