Juan Batiz-Benet bd30912d08 Multiaddr.String no error
The error in String should not actually ocurr, as the multiaddr
should have been valid to be constructed successfully, and thus
should be encoded back to its string rep correctly.

This will be bolstered by creating an interface (to prevent messing
with the internal bytes)
2014-10-06 02:39:00 -07:00
2014-09-13 04:47:37 -07:00
2014-10-06 02:39:00 -07:00
2014-09-28 15:21:18 -07:00
2014-10-06 02:39:00 -07:00
2014-10-06 02:39:00 -07:00
2014-09-13 04:51:39 -07:00
2014-07-04 00:12:33 -07:00
2014-09-11 10:47:56 -07:00
2014-07-04 00:48:33 -07:00

go-multiaddr

multiaddr implementation in Go.

Example

Simple

import "github.com/jbenet/go-multiaddr"

m := multiaddr.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>
m.buffer
// <Buffer >
m.String()
// /ip4/127.0.0.1/udp/1234

// construct with Buffer
m = multiaddr.Multiaddr{ Bytes: m.Bytes }
// <Multiaddr /ip4/127.0.0.1/udp/1234>

Protocols

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

Other formats

// handles the stupid url version too
m = multiaddr.NewUrl("udp4://127.0.0.1:1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>
m.Url(buf)
// udp4://127.0.0.1:1234

En/decapsulate

m.Encapsulate(m.NewMultiaddr("/sctp/5678"))
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
m.Decapsulate(m.NewMultiaddr("/udp")) // up to + inc last occurrence of subaddr
// <Multiaddr /ip4/127.0.0.1>

Tunneling

Multiaddr allows expressing tunnels very nicely.

printer := multiaddr.NewMultiaddr("/ip4/192.168.0.13/tcp/80")
proxy := multiaddr.NewMultiaddr("/ip4/10.20.30.40/tcp/443")
printerOverProxy := proxy.Encapsulate(printer)
// <Multiaddr /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80>

proxyAgain := printerOverProxy.Decapsulate(multiaddr.NewMultiaddr("/ip4"))
// <Multiaddr /ip4/10.20.30.40/tcp/443>
Description
Composable and future-proof network addresses
https://github.com/multiformats/multiaddr
Readme MIT
Languages
Go 100%