func trimPrefix(m, prem ma.Multiaddr) (ma.Multiaddr, bool) { s := m.String() pres := prem.String() if !strings.HasPrefix(s, pres) { return nil, false } return ma.StringCast(strings.TrimPrefix(s, pres)), true }
func (pi *PeerInfo) UnmarshalJSON(b []byte) error { var data map[string]interface{} err := json.Unmarshal(b, &data) if err != nil { return err } pid, err := IDB58Decode(data["ID"].(string)) if err != nil { return err } pi.ID = pid addrs, ok := data["Addrs"].([]interface{}) if ok { for _, a := range addrs { pi.Addrs = append(pi.Addrs, ma.StringCast(a.(string))) } } return nil }
func BuildAPIAddr(port int) ma.Multiaddr { return manet.IP4Loopback.Encapsulate( ma.StringCast(fmt.Sprint("/tcp/", port))) }
package manet import ( "bytes" ma "github.com/jbenet/go-multiaddr" ) // Loopback Addresses var ( // IP4Loopback is the ip4 loopback multiaddr IP4Loopback = ma.StringCast("/ip4/127.0.0.1") // IP6Loopback is the ip6 loopback multiaddr IP6Loopback = ma.StringCast("/ip6/::1") // IP6LinkLocalLoopback is the ip6 link-local loopback multiaddr IP6LinkLocalLoopback = ma.StringCast("/ip6/fe80::1") ) // Unspecified Addresses (used for ) var ( IP4Unspecified = ma.StringCast("/ip4/0.0.0.0") IP6Unspecified = ma.StringCast("/ip6/::") ) // IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols. // This means: /{IP4, IP6}[/{TCP, UDP}] func IsThinWaist(m ma.Multiaddr) bool { p := m.Protocols()