Composable and future-proof network addresses
https://github.com/multiformats/multiaddr
26c0624fc0 | ||
---|---|---|
.gx | ||
.travis.yml | ||
LICENSE | ||
README.md | ||
codec.go | ||
doc.go | ||
interface.go | ||
multiaddr.go | ||
multiaddr_test.go | ||
package.json | ||
protocols.csv | ||
protocols.go | ||
util.go |
README.md
go-multiaddr
multiaddr implementation in go
This is a multiaddr implementation in Go.
Table of Contents
Install
go get multiformats/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
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
Maintainers
Captain: @whyrusleeping.
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 © Juan Batiz-Benet