From 86da79a8547d7037a44880cb713614b837a343a1 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 29 Sep 2023 14:49:18 -0400 Subject: [PATCH] Rename to `parse_maddr()` and fill out doc strings --- tractor/_multiaddr.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tractor/_multiaddr.py b/tractor/_multiaddr.py index f6b37a35..d0f562c0 100644 --- a/tractor/_multiaddr.py +++ b/tractor/_multiaddr.py @@ -96,21 +96,30 @@ def iter_prot_layers( yield prot, params -def parse_addr( +def parse_maddr( multiaddr: str, ) -> dict[str, str | int | dict]: ''' Parse a libp2p style "multiaddress" into it's distinct protocol - segments where each segment: + segments where each segment is of the form: `..////../` - is loaded into a layers `dict[str, dict[str, Any]` which holds - each prot segment of the path as a separate entry sortable by - it's approx OSI "layer number". + and is loaded into a (order preserving) `layers: dict[str, + dict[str, Any]` which holds each protocol-layer-segment of the + original `str` path as a separate entry according to its approx + OSI "layer number". - Any `paramN` in the path must be distinctly defined in order - according to the (global) `prot_params` table in this module. + Any `paramN` in the path must be distinctly defined by a str-token in the + (module global) `prot_params` table. + + For eg. for wireguard which requires an address, port number and publickey + the protocol params are specified as the entry: + + 'wg': ('addr', 'port', 'pubkey'), + + and are thus parsed from a maddr in that order: + `'/wg/1.1.1.1/51820/'` ''' layers: dict[str, str | int | dict] = {}