Package multiaddr provides an implementation of the Multiaddr network address format. Multiaddr emphasizes explicitness, self-description, and portability. It allows applications to treat addresses as opaque tokens, and to avoid making assumptions about the address representation (e.g. length). Learn more at https://github.com/multiformats/multiaddr
Basic Use:
import ( "bytes" "strings" ma "github.com/multiformats/go-multiaddr" ) // construct from a string (err signals parse failure) m1, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234") // construct from bytes (err signals parse failure) m2, err := ma.NewMultiaddrBytes(m1.Bytes()) // true strings.Equal(m1.String(), "/ip4/127.0.0.1/udp/1234") strings.Equal(m1.String(), m2.String()) bytes.Equal(m1.Bytes(), m2.Bytes()) m1.Equal(m2) m2.Equal(m1) // tunneling (en/decap) printer, _ := ma.NewMultiaddr("/ip4/192.168.0.13/tcp/80") proxy, _ := ma.NewMultiaddr("/ip4/10.20.30.40/tcp/443") printerOverProxy := proxy.Encapsulate(printer) proxyAgain := printerOverProxy.Decapsulate(printer)
const ( P_IP4 = 4 P_TCP = 6 P_DNS = 53 P_DNS4 = 54 P_DNS6 = 55 P_DNSADDR = 56 P_UDP = 273 P_DCCP = 33 P_IP6 = 41 P_IP6ZONE = 42 P_IPCIDR = 43 P_QUIC = 460 P_QUIC_V1 = 461 P_WEBTRANSPORT = 465 P_CERTHASH = 466 P_SCTP = 132 P_CIRCUIT = 290 P_UDT = 301 P_UTP = 302 P_UNIX = 400 P_P2P = 421 P_IPFS = P_P2P P_HTTP = 480 P_HTTP_PATH = 481 P_HTTPS = 443 P_ONION = 444 P_ONION3 = 445 P_GARLIC64 = 446 P_GARLIC32 = 447 P_P2P_WEBRTC_DIRECT = 276 P_TLS = 448 P_SNI = 449 P_NOISE = 454 P_WS = 477 P_WSS = 478 P_PLAINTEXTV2 = 7367777 P_WEBRTC_DIRECT = 280 P_WEBRTC = 281 P_MEMORY = 777 )
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
These are special sizes
Protocols is the list of multiaddr protocols supported by this module.
CodeToVarint converts an integer to a varint-encoded []byte
Contains reports whether addr is contained in addrs.
ForEach walks over the multiaddr, component by component.
This function iterates over components. Return true to continue iteration, false to stop.
Prefer a standard for range loop instead e.g. `for _, c := range m { ... }`
SplitFirst returns the first component and the rest of the multiaddr.
SplitFunc splits the multiaddr when the callback first returns true. The component on which the callback first returns will be included in the *second* multiaddr.
SplitLast returns the rest of the multiaddr and the last component.
Action is an enum modelling all possible filter actions.
const ( ActionNone Action = iota ActionAccept ActionDeny )
type Component struct { }
Component is a single multiaddr Component.
NewComponent constructs a new multiaddr component
Split returns the sub-address portions of a multiaddr.
type Filters struct { DefaultAction Action }
Filters is a structure representing a collection of accept/deny net.IPNet filters, together with the DefaultAction flag, which represents the default filter policy.
Note that the last policy added to the Filters is authoritative.
NewFilters constructs and returns a new set of net.IPNet filters. By default, the new filter accepts all addresses.
AddFilter adds a rule to the Filters set, enforcing the desired action for the provided IPNet mask.
AddrBlocked parses a ma.Multiaddr and, if a valid netip is found, it applies the Filter set rules, returning true if the given address should be denied, and false if the given address is accepted.
If a parsing error occurs, or no filter matches, the Filters' default is returned.
TODO: currently, the last filter to match wins always, but it shouldn't be that way.
Instead, the highest-specific last filter should win; that way more specific filters override more general ones.
FiltersForAction returns the filters associated with the indicated action.
RemoveLiteral removes the first filter associated with the supplied IPNet, returning whether something was removed or not. It makes no distinction between whether the rule is an accept or a deny.
Multiaddr is the data structure representing a Multiaddr
Cast re-casts a byte slice as a multiaddr. will panic if it fails to parse.
FilterAddrs is a filter that removes certain addresses, according to the given filters. If all filters return true, the address is kept.
Join returns a combination of addresses. Note: This copies all the components from the input Multiaddrs. Depending on your use case, you may prefer to use `append(leftMA, rightMA...)` instead.
NewMultiaddr parses and validates an input string, returning a *Multiaddr
NewMultiaddrBytes initializes a Multiaddr from a byte representation. It validates it as an input string.
StringCast like Cast, but parses a string. Will also panic if it fails to parse.
Unique deduplicates addresses in place, leave only unique addresses. It doesn't allocate.
AppendComponent is the same as using `append(m, *c)`, but with a safety check for a nil Component.
Bytes returns the []byte representation of this Multiaddr
Decapsulate unwraps Multiaddr up until the given Multiaddr is found.
Encapsulate wraps a given Multiaddr, returning the resulting joined Multiaddr
Equal tests whether two multiaddrs are equal
Protocols returns the list of protocols this Multiaddr has. will panic in case we access bytes incorrectly.
String returns the string representation of a Multiaddr
type Multiaddrer interface { Multiaddr() Multiaddr }
Protocol is a Multiaddr protocol description structure.
ProtocolWithCode returns the Protocol description with given protocol code.
ProtocolWithName returns the Protocol description with given string name.
ProtocolsWithString returns a slice of protocols matching given string.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4