multiaddr

package module
v2.0.0-...-252c939 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const (
	LengthPrefixedVarSize = -1
)

These are special sizes

Variables

View Source
var DefaultMultiaddrTranscoder = MultiaddrTranscoder{}
View Source
var Protocols = []Protocol{}

Protocols is the list of multiaddr protocols supported by this module.

View Source
var TranscoderCertHash = NewTranscoderFromFunctions(certHashStB, certHashBtS, validateCertHash)
View Source
var TranscoderDns = NewTranscoderFromFunctions(dnsStB, dnsBtS, dnsVal)
View Source
var TranscoderGarlic32 = NewTranscoderFromFunctions(garlic32StB, garlic32BtS, garlic32Validate)
View Source
var TranscoderGarlic64 = NewTranscoderFromFunctions(garlic64StB, garlic64BtS, garlic64Validate)
View Source
var TranscoderHTTPPath = NewTranscoderFromFunctions(httpPathStB, httpPathBtS, validateHTTPPath)
View Source
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ip4BtS, nil)
View Source
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ip6BtS, nil)
View Source
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, ip6zoneVal)
View Source
var TranscoderIPCIDR = NewTranscoderFromFunctions(ipcidrStB, ipcidrBtS, ipcidrValidate)
View Source
var TranscoderMemory = NewTranscoderFromFunctions(memoryStB, memoryBtS, memoryValidate)
View Source
var TranscoderOnion = NewTranscoderFromFunctions(onionStB, onionBtS, onionValidate)
View Source
var TranscoderOnion3 = NewTranscoderFromFunctions(onion3StB, onion3BtS, onion3Validate)
View Source
var TranscoderP2P = NewTranscoderFromFunctions(p2pStB, p2pBtS, p2pVal)
View Source
var TranscoderPort = NewTranscoderFromFunctions(portStB, portBtS, nil)
View Source
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) Protocol

func (c Component) Protocol() Protocol

func (Component) StringValue

func (c Component) StringValue() (string, error)

func (Component) Value

func (c Component) Value() []byte

type Multiaddr

type Multiaddr []Component

func (Multiaddr) Bytes

func (m Multiaddr) Bytes() (MultiaddrBytes, error)

func (Multiaddr) PopLast

func (m Multiaddr) PopLast() (Multiaddr, Component)

func (Multiaddr) String

func (m Multiaddr) String() string

String converts the multiaddr to its string form. If there is an error in conversion it returns an empty string.

func (Multiaddr) ToString

func (m Multiaddr) ToString() (string, 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 (*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)

func (*MultiaddrTranscoder) ToBytes

func (t *MultiaddrTranscoder) ToBytes(m Multiaddr) ([]byte, error)

func (*MultiaddrTranscoder) ToString

func (t *MultiaddrTranscoder) ToString(m Multiaddr) (string, error)

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
}

func NewTranscoderFromFunctions

func NewTranscoderFromFunctions(
	s2b func(string) ([]byte, error),
	b2s func([]byte) (string, error),
	val func([]byte) error,
) Transcoder

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL