Categorygithub.com/multiformats/go-multiaddr
modulepackage
0.15.0
Repository: https://github.com/multiformats/go-multiaddr.git
Documentation: pkg.go.dev

# README

go-multiaddr

GoDoc Travis CI codecov.io

multiaddr implementation in go

Multiaddr is a standard way to represent addresses that:

  • Support any standard network protocols.
  • Self-describe (include protocols).
  • Have a binary packed format.
  • Have a nice string representation.
  • Encapsulate well.

Table of Contents

Install

go get github.com/multiformats/go-multiaddr

Usage

Example

Simple

import 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)

Protocols

// get the multiaddr protocol description objects
m1.Protocols()
// []Protocol{
//   Protocol{ Code: 4, Name: 'ip4', Size: 32},
//   Protocol{ Code: 17, Name: 'udp', Size: 16},
// }

En/decapsulate

import ma "github.com/multiformats/go-multiaddr"

m, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>

sctpMA, err := ma.NewMultiaddr("/sctp/5678")

m.Encapsulate(sctpMA)
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>

udpMA, err := ma.NewMultiaddr("/udp/1234")

m.Decapsulate(udpMA) // up to + inc last occurrence of subaddr
// <Multiaddr /ip4/127.0.0.1>

Tunneling

Multiaddr allows expressing tunnels very nicely.

printer, _ := ma.NewMultiaddr("/ip4/192.168.0.13/tcp/80")
proxy, _ := ma.NewMultiaddr("/ip4/10.20.30.40/tcp/443")
printerOverProxy := proxy.Encapsulate(printer)
// /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80

proxyAgain := printerOverProxy.Decapsulate(printer)
// /ip4/10.20.30.40/tcp/443

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2014 Juan Batiz-Benet

# Packages

Package matest provides utilities for testing with multiaddrs.
No description provided by the author
Package manet provides Multiaddr (https://github.com/multiformats/go-multiaddr) specific versions of common functions in Go's standard `net` package.

# Functions

No description provided by the author
Cast re-casts a byte slice as a multiaddr.
CodeToVarint converts an integer to a varint-encoded []byte.
Contains reports whether addr is contained in addrs.
FilterAddrs is a filter that removes certain addresses, according to the given filters.
ForEach walks over the multiaddr, component by component.
Join returns a combination of addresses.
NewComponent constructs a new multiaddr component.
NewFilters constructs and returns a new set of net.IPNet filters.
NewMultiaddr parses and validates an input string, returning a *Multiaddr.
NewMultiaddrBytes initializes a Multiaddr from a byte representation.
No description provided by the author
ProtocolsWithString returns a slice of protocols matching given string.
ProtocolWithCode returns the Protocol description with given protocol code.
ProtocolWithName returns the Protocol description with given string name.
No description provided by the author
Split returns the sub-address portions of a multiaddr.
SplitFirst returns the first component and the rest of the multiaddr.
SplitFunc splits the multiaddr when the callback first returns true.
SplitLast returns the rest of the multiaddr and the last component.
StringCast like Cast, but parses a string.
Unique deduplicates addresses in place, leave only unique addresses.

# Constants

No description provided by the author
No description provided by the author
zero value.
These are special sizes.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
4 or 6.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
deprecated alias for /tls/http.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
alias for backwards compatibility.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
also for backwards compatibility.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
Deprecated.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
You **MUST** register your multicodecs with https://github.com/multiformats/multicodec before adding them here.
deprecated alias for /tls/ws.

# Variables

No description provided by the author
Protocols is the list of multiaddr protocols supported by this module.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Component is a single multiaddr Component.
Filters is a structure representing a collection of accept/deny net.IPNet filters, together with the DefaultAction flag, which represents the default filter policy.
Protocol is a Multiaddr protocol description structure.

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

Action is an enum modelling all possible filter actions.
Multiaddr is the data structure representing a Multiaddr.