mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-02 13:03:11 +00:00
This commit changes the struct to a new Multiaddr interface:
```Go
type Multiaddr interface {
Equal(Multiaddr) bool
Bytes() []byte
String() string
Protocols() []*Protocol
Encapsulate(Multiaddr) Multiaddr
Decapsulate(Multiaddr) Multiaddr
}
```
This means a few things have changed:
- use Multiaddr interface, struct not exported
- Bytes returns a copy of the internal bytes
- Some methods no longer return errors (catch errors in NewMultiaddr)
- String (panics if malformed)
- Protocols (panics if malformed)
- Decapsulate (no-op if not prefix)
- Moved net-specific functions to package
- Multiaddr.DialArgs() -> DialArgs(Multiaddr)
- Multiaddr.IsThinWaist() -> IsThinWaist(Multiaddr)
cc @whyrusleeping @perfmode
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package multiaddr
|
|
|
|
/*
|
|
Multiaddr is a cross-protocol, cross-platform format for representing
|
|
internet addresses. It emphasizes explicitness and self-description.
|
|
Learn more here: https://github.com/jbenet/multiaddr
|
|
|
|
Multiaddrs have both a binary and string representation.
|
|
|
|
import ma "github.com/jbenet/go-multiaddr"
|
|
|
|
addr, err := ma.NewMultiaddr("/ip4/1.2.3.4/tcp/80")
|
|
// err non-nil when parsing failed.
|
|
|
|
*/
|
|
type Multiaddr interface {
|
|
// Equal returns whether two Multiaddrs are exactly equal
|
|
Equal(Multiaddr) bool
|
|
|
|
// Bytes returns the []byte representation of this Multiaddr
|
|
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
|
|
|
|
// Decapsultate removes a Multiaddr wrapping. For example:
|
|
//
|
|
// /ip4/1.2.3.4/tcp/80 decapsulate /ip4/1.2.3.4 = /tcp/80
|
|
//
|
|
Decapsulate(Multiaddr) Multiaddr
|
|
}
|