Composable and future-proof network addresses https://github.com/multiformats/multiaddr
Go to file
Marten Seemann 0fcbe89380
Merge pull request #153 from carpawell/feature/add-TLS-protocol
Add TLS protocol
2021-07-01 15:09:03 -07:00
.github/workflows sync: update CI config files (#154) 2021-06-01 17:01:00 +00:00
.gx gx publish 1.4.1 2019-02-26 19:41:46 +00:00
internal/codependencies fix use of deprecated go-multiaddr/net 2021-03-30 17:08:36 +07:00
multiaddr fix ineffectual assignment of error 2021-03-30 17:08:37 +07:00
net Merge pull request #155 from marten-seemann/guard-against-nil-addrs 2021-06-23 18:47:21 -07:00
.gitignore Add conformance testing 2019-04-19 05:15:55 +02:00
LICENSE MIT license 2014-09-28 15:21:18 -07:00
Makefile absorb go-maddr-filter; rm stale Makefile targets; upgrade deps (#124) 2020-05-14 16:34:54 +01:00
README.md Merge pull request #89 from multiformats/fix/captain 2019-02-20 15:20:57 +01:00
codec.go remove unused bytesSplit function 2021-03-30 15:53:29 +07:00
codecov.yml Add conformance testing 2019-04-19 05:15:55 +02:00
component.go fix: minimal varint decoding 2019-09-19 14:43:22 -07:00
doc.go Changed jbenet to multiformats 2016-10-20 20:48:40 -04:00
filter.go absorb go-maddr-filter; rm stale Makefile targets; upgrade deps (#124) 2020-05-14 16:34:54 +01:00
filter_test.go absorb go-maddr-filter; rm stale Makefile targets; upgrade deps (#124) 2020-05-14 16:34:54 +01:00
go.mod sync: run go mod tidy (and set Go 1.15) and gofmt -s in copy workflow (#146) 2021-04-01 14:44:26 +00:00
go.sum fix use of deprecated go-multiaddr/net 2021-03-30 17:08:36 +07:00
interface.go Let Multiaddr implement marshalers: binary, text, json 2019-02-25 22:48:24 +00:00
multiaddr.go forbid empty multiaddrs 2019-05-20 12:23:28 -07:00
multiaddr_test.go test: fix tls proto order 2021-06-29 17:48:19 -07:00
package.json gx publish 1.4.1 2019-02-26 19:41:46 +00:00
protocol.go feat: switch to /p2p multiaddrs by default 2019-11-01 14:22:21 -07:00
protocols.go feat: add TLS protocol 2021-05-26 16:04:06 +03:00
transcoders.go fix error strings 2021-03-30 15:54:55 +07:00
util.go Let Multiaddr implement marshalers: binary, text, json 2019-02-25 22:48:24 +00:00
util_test.go sync: run go mod tidy (and set Go 1.15) and gofmt -s in copy workflow (#146) 2021-04-01 14:44:26 +00:00
varint.go fix: minimal varint decoding 2019-09-19 14:43:22 -07:00

README.md

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