Composable and future-proof network addresses https://github.com/multiformats/multiaddr
Go to file
Juan Batiz-Benet 5b8fc748ca IP unspecified addrs 2014-11-05 02:06:28 -08:00
multiaddr hide-loopback in tool 2014-11-05 01:47:13 -08:00
net IP unspecified addrs 2014-11-05 02:06:28 -08:00
.travis.yml added travis.yml 2014-10-11 02:30:03 -07:00
LICENSE MIT license 2014-09-28 15:21:18 -07:00
README.md removed url from readme 2014-10-11 03:30:15 -07:00
codec.go Split: added split method 2014-11-04 23:20:17 -08:00
doc.go docs 2014-10-06 04:05:20 -07:00
interface.go Split: added split method 2014-11-04 23:20:17 -08:00
multiaddr.go Cast and Loopback 2014-11-05 00:04:30 -08:00
multiaddr_test.go Split: added split method 2014-11-04 23:20:17 -08:00
protocols.csv protocols 2014-07-04 00:12:33 -07:00
protocols.go go lint + unexporting some funcs 2014-09-11 10:47:56 -07:00

README.md

go-multiaddr

multiaddr implementation in Go.

Example

Simple

import ma "github.com/jbenet/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
addr.Protocols()
// []*Protocol{
//   &Protocol{ Code: 4, Name: 'ip4', Size: 32},
//   &Protocol{ Code: 17, Name: 'udp', Size: 16},
// }

En/decapsulate

m.Encapsulate(ma.NewMultiaddr("/sctp/5678"))
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
m.Decapsulate(ma.NewMultiaddr("/udp")) // 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