Documentation
¶
Index ¶
- Constants
- Variables
- type Component
- type Multiaddr
- type MultiaddrBytes
- type MultiaddrTranscoder
- func (t *MultiaddrTranscoder) AddProtocol(p Protocol) error
- func (t *MultiaddrTranscoder) AliasProtocolName(from ProtocolName, to ProtocolName) error
- func (t *MultiaddrTranscoder) Decode(mab MultiaddrBytes) (Multiaddr, error)
- func (t *MultiaddrTranscoder) FromBytes(b []byte) (Multiaddr, error)
- func (t *MultiaddrTranscoder) FromString(s string) (Multiaddr, error)
- func (t *MultiaddrTranscoder) ProtocolWithCode(c ProtocolCode) (Protocol, bool)
- func (t *MultiaddrTranscoder) ProtocolWithName(s ProtocolName) (Protocol, bool)
- func (t *MultiaddrTranscoder) ToBytes(m Multiaddr) ([]byte, error)
- func (t *MultiaddrTranscoder) ToString(m Multiaddr) (string, error)
- type Protocol
- type ProtocolCode
- type ProtocolName
- type Transcoder
Constants ¶
const ( P_IP4 = 4 P_TCP = 6 P_DNS = 53 // 4 or 6 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 // alias for backwards compatibility P_HTTP = 480 P_HTTP_PATH = 481 P_HTTPS = 443 // deprecated alias for /tls/http P_ONION = 444 // also for backwards compatibility P_ONION3 = 445 P_GARLIC64 = 446 P_GARLIC32 = 447 P_P2P_WEBRTC_DIRECT = 276 // Deprecated. use webrtc-direct instead P_TLS = 448 P_SNI = 449 P_NOISE = 454 P_WS = 477 P_WSS = 478 // deprecated alias for /tls/ws 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.
const (
LengthPrefixedVarSize = -1
)
These are special sizes
Variables ¶
var DefaultMultiaddrTranscoder = MultiaddrTranscoder{}
var Protocols = []Protocol{}
Protocols is the list of multiaddr protocols supported by this module.
var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, validateCertHash)
var TranscoderDns = NewTranscoderFromFunctions(dnsStB, dnsBtS, dnsVal)
var TranscoderGarlic32 = NewTranscoderFromFunctions(garlic32StB, garlic32BtS, garlic32Validate)
var TranscoderGarlic64 = NewTranscoderFromFunctions(garlic64StB, garlic64BtS, garlic64Validate)
var TranscoderHTTPPath = NewTranscoderFromFunctions(httpPathStB, httpPathBtS, validateHTTPPath)
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ip4BtS, nil)
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ip6BtS, nil)
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, ip6zoneVal)
var TranscoderIPCIDR = NewTranscoderFromFunctions(ipcidrStB, ipcidrBtS, ipcidrValidate)
var TranscoderMemory = NewTranscoderFromFunctions(memoryStB, memoryBtS, memoryValidate)
var TranscoderOnion = NewTranscoderFromFunctions(onionStB, onionBtS, onionValidate)
var TranscoderOnion3 = NewTranscoderFromFunctions(onion3StB, onion3BtS, onion3Validate)
var TranscoderP2P = NewTranscoderFromFunctions(p2pStB, p2pBtS, p2pVal)
var TranscoderPort = NewTranscoderFromFunctions(portStB, portBtS, nil)
var TranscoderUnix = NewTranscoderFromFunctions(unixStB, unixBtS, unixValidate)
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
func (Component) Code ¶
func (c Component) Code() ProtocolCode
func (Component) Name ¶
func (c Component) Name() ProtocolName
func (Component) StringValue ¶
type Multiaddr ¶
type Multiaddr []Component
func (Multiaddr) Bytes ¶
func (m Multiaddr) Bytes() (MultiaddrBytes, error)
type MultiaddrBytes ¶
type MultiaddrBytes struct {
Bytes []byte
}
MultiaddrBytes represents the binary form of a multiaddr
type MultiaddrTranscoder ¶
type MultiaddrTranscoder struct {
// contains filtered or unexported fields
}
MultiaddrTranscoder coverts between Strings/Bytes to Multiaddrs and back. A default MultiaddrTranscoder is provided with all configured protocols. Users are encouraged to build their own MultiaddrTranscoder and support only the protocols they are working with.
func (*MultiaddrTranscoder) AddProtocol ¶
func (t *MultiaddrTranscoder) AddProtocol(p Protocol) error
func (*MultiaddrTranscoder) AliasProtocolName ¶
func (t *MultiaddrTranscoder) AliasProtocolName(from ProtocolName, to ProtocolName) error
AliasProtocol aliases the "from" protocol name to use the same Protocol as the "to" ProtocolName.
the "to" Protocol should be Added first, otherwise this returns an error.
func (*MultiaddrTranscoder) Decode ¶
func (t *MultiaddrTranscoder) Decode(mab MultiaddrBytes) (Multiaddr, error)
func (*MultiaddrTranscoder) FromBytes ¶
func (t *MultiaddrTranscoder) FromBytes(b []byte) (Multiaddr, error)
func (*MultiaddrTranscoder) FromString ¶
func (t *MultiaddrTranscoder) FromString(s string) (Multiaddr, error)
func (*MultiaddrTranscoder) ProtocolWithCode ¶
func (t *MultiaddrTranscoder) ProtocolWithCode(c ProtocolCode) (Protocol, bool)
func (*MultiaddrTranscoder) ProtocolWithName ¶
func (t *MultiaddrTranscoder) ProtocolWithName(s ProtocolName) (Protocol, bool)
type Protocol ¶
type Protocol struct { // Name is the string representation of the protocol code. E.g., ip4, // ip6, tcp, udp, etc. Name ProtocolName // Code is the protocol's multicodec (a normal, non-varint number). Code ProtocolCode // VCode is a precomputed varint encoded version of Code. VCode []byte // Size is the size of the argument to this protocol. // // * Size == 0 means this protocol takes no argument. // * Size > 0 means this protocol takes a constant sized argument. // * Size < 0 means this protocol takes a variable length, varint // prefixed argument. Size int // a size of -1 indicates a length-prefixed variable size // Path indicates a path protocol (e.g., unix). When parsing multiaddr // strings, path protocols consume the remainder of the address instead // of stopping at the next forward slash. // // Size must be LengthPrefixedVarSize. Path bool // Transcoder converts between the byte representation and the string // representation of this protocol's argument (if any). // // This should only be non-nil if Size != 0 Transcoder Transcoder }
Protocol is a Multiaddr protocol description structure.
type ProtocolCode ¶
type ProtocolCode uint64
type ProtocolName ¶
type ProtocolName string
type Transcoder ¶
type Transcoder interface { // Validates and encodes to bytes a multiaddr that's in the string representation. StringToBytes(string) ([]byte, error) // Validates and decodes to a string a multiaddr that's in the bytes representation. BytesToString([]byte) (string, error) // Validates bytes when parsing a multiaddr that's already in the bytes representation. ValidateBytes([]byte) error }