2018-07-04 10:51:47 +00:00
|
|
|
package multiaddr
|
|
|
|
|
2019-06-09 07:24:20 +00:00
|
|
|
import (
|
|
|
|
"encoding"
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
2018-07-04 10:51:47 +00:00
|
|
|
/*
|
|
|
|
Multiaddr is a cross-protocol, cross-platform format for representing
|
|
|
|
internet addresses. It emphasizes explicitness and self-description.
|
|
|
|
Learn more here: https://github.com/multiformats/multiaddr
|
|
|
|
|
|
|
|
Multiaddrs have both a binary and string representation.
|
|
|
|
|
2022-11-04 13:57:20 +00:00
|
|
|
import ma "github.com/multiformats/go-multiaddr"
|
2018-07-04 10:51:47 +00:00
|
|
|
|
2022-11-04 13:57:20 +00:00
|
|
|
addr, err := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/80")
|
|
|
|
// err non-nil when parsing failed.
|
2018-07-04 10:51:47 +00:00
|
|
|
*/
|
|
|
|
type Multiaddr interface {
|
2019-06-09 07:24:20 +00:00
|
|
|
json.Marshaler
|
|
|
|
json.Unmarshaler
|
|
|
|
encoding.TextMarshaler
|
|
|
|
encoding.TextUnmarshaler
|
|
|
|
encoding.BinaryMarshaler
|
|
|
|
encoding.BinaryUnmarshaler
|
|
|
|
|
2018-07-04 10:51:47 +00:00
|
|
|
// Equal returns whether two Multiaddrs are exactly equal
|
|
|
|
Equal(Multiaddr) bool
|
|
|
|
|
|
|
|
// Bytes returns the []byte representation of this Multiaddr
|
2019-06-09 07:24:20 +00:00
|
|
|
//
|
|
|
|
// This function may expose immutable, internal state. Do not modify.
|
2018-07-04 10:51:47 +00:00
|
|
|
Bytes() []byte
|
|
|
|
|
|
|
|
// String returns the string representation of this Multiaddr
|
|
|
|
// (may panic if internal state is corrupted)
|
|
|
|
String() string
|
|
|
|
|
|
|
|
// Protocols returns the list of Protocols this Multiaddr includes
|
|
|
|
// will panic if protocol code incorrect (and bytes accessed incorrectly)
|
|
|
|
Protocols() []Protocol
|
|
|
|
|
|
|
|
// Encapsulate wraps this Multiaddr around another. For example:
|
|
|
|
//
|
|
|
|
// /ip4/1.2.3.4 encapsulate /tcp/80 = /ip4/1.2.3.4/tcp/80
|
|
|
|
//
|
|
|
|
Encapsulate(Multiaddr) Multiaddr
|
|
|
|
|
2022-11-04 13:57:20 +00:00
|
|
|
// Decapsulate removes a Multiaddr wrapping. For example:
|
2018-07-04 10:51:47 +00:00
|
|
|
//
|
2022-11-04 13:57:20 +00:00
|
|
|
// /ip4/1.2.3.4/tcp/80 decapsulate /tcp/80 = /ip4/1.2.3.4
|
|
|
|
// /ip4/1.2.3.4/tcp/80 decapsulate /udp/80 = /ip4/1.2.3.4/tcp/80
|
|
|
|
// /ip4/1.2.3.4/tcp/80 decapsulate /ip4/1.2.3.4 = nil
|
2018-07-04 10:51:47 +00:00
|
|
|
//
|
|
|
|
Decapsulate(Multiaddr) Multiaddr
|
|
|
|
|
|
|
|
// ValueForProtocol returns the value (if any) following the specified protocol
|
2019-06-09 07:24:20 +00:00
|
|
|
//
|
|
|
|
// Note: protocols can appear multiple times in a single multiaddr.
|
|
|
|
// Consider using `ForEach` to walk over the addr manually.
|
2018-07-04 10:51:47 +00:00
|
|
|
ValueForProtocol(code int) (string, error)
|
|
|
|
}
|