Documentation ¶
Overview ¶
Package manet provides Multiaddr specific versions of common functions in stdlib's net package. This means wrappers of standard net symbols like net.Dial and net.Listen, as well as conversion to/from net.Addr.
Index ¶
- Variables
- func AddrMatch(match ma.Multiaddr, addrs []ma.Multiaddr) []ma.Multiaddr
- func DialArgs(m ma.Multiaddr) (string, string, error)
- func FromIP(ip net.IP) (ma.Multiaddr, error)
- func FromNetAddr(a net.Addr) (ma.Multiaddr, error)
- func InterfaceMultiaddrs() ([]ma.Multiaddr, error)
- func IsIP6LinkLocal(m ma.Multiaddr) bool
- func IsIPLoopback(m ma.Multiaddr) bool
- func IsIPUnspecified(m ma.Multiaddr) bool
- func IsThinWaist(m ma.Multiaddr) bool
- func ToNetAddr(maddr ma.Multiaddr) (net.Addr, error)
- type Conn
- type Dialer
- type Listener
Constants ¶
This section is empty.
Variables ¶
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") )
Loopback Addresses
var ( IP4Unspecified = ma.StringCast("/ip4/0.0.0.0") IP6Unspecified = ma.StringCast("/ip6/::") )
Unspecified Addresses (used for )
Functions ¶
func FromNetAddr ¶
FromNetAddr converts a net.Addr type to a Multiaddr.
func InterfaceMultiaddrs ¶
InterfaceMultiaddrs will return the addresses matching net.InterfaceAddrs
func IsIP6LinkLocal ¶
IP6 Link Local addresses are non routable. The prefix is technically fe80::/10, but we test fe80::/16 for simplicity (no need to mask). So far, no hardware interfaces exist long enough to use those 2 bits. Send a PR if there is.
func IsIPLoopback ¶
IsIPLoopback returns whether a Multiaddr is a "Loopback" IP address This means either /ip4/127.0.0.1 or /ip6/::1
func IsIPUnspecified ¶
IsIPUnspecified returns whether a Multiaddr is am Unspecified IP address This means either /ip4/0.0.0.0 or /ip6/::
func IsThinWaist ¶
IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols. This means: /{IP4, IP6}[/{TCP, UDP}]
Types ¶
type Conn ¶
type Conn interface { net.Conn // LocalMultiaddr returns the local Multiaddr associated // with this connection LocalMultiaddr() ma.Multiaddr // RemoteMultiaddr returns the remote Multiaddr associated // with this connection RemoteMultiaddr() ma.Multiaddr }
Conn is the equivalent of a net.Conn object. It is the result of calling the Dial or Listen functions in this package, with associated local and remote Multiaddrs.
type Dialer ¶
type Dialer struct { // Dialer is just an embedded net.Dialer, with all its options. net.Dialer // LocalAddr is the local address to use when dialing an // address. The address must be of a compatible type for the // network being dialed. // If nil, a local address is automatically chosen. LocalAddr ma.Multiaddr }
Dialer contains options for connecting to an address. It is effectively the same as net.Dialer, but its LocalAddr and RemoteAddr options are Multiaddrs, instead of net.Addrs.
type Listener ¶
type Listener interface { // NetListener returns the embedded net.Listener. Use with caution. NetListener() net.Listener // Accept waits for and returns the next connection to the listener. // Returns a Multiaddr friendly Conn Accept() (Conn, error) // Close closes the listener. // Any blocked Accept operations will be unblocked and return errors. Close() error // Multiaddr returns the listener's (local) Multiaddr. Multiaddr() ma.Multiaddr // Addr returns the net.Listener's network address. Addr() net.Addr }
A Listener is a generic network listener for stream-oriented protocols. it uses an embedded net.Listener, overriding net.Listener.Accept to return a Conn and providing Multiaddr.