ceremonyclient/go-multiaddr
2025-09-18 21:43:06 -05:00
..
matest v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
multiaddr v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
net v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
testdata/fuzz detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
.gitignore detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
codec.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
codecov.yml detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
component.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
doc.go detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
filter_test.go detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
filter.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
go.mod v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
go.sum v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
LICENSE detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
multiaddr_test.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
multiaddr.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
package.json detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
protocol.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
protocols.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
README.md detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
transcoders.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
util_test.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
util.go v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00
varint.go detangling merge of main node for v2 (#293) 2024-10-12 11:55:17 -07:00
version.json v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete 2025-09-18 21:43:06 -05:00

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