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.
Package manet provides Multiaddr (https://github.com/multiformats/go-multiaddr) specific versions of common functions in Go's standard `net` package. This means wrappers of standard net symbols like `net.Dial` and `net.Listen`, as well as conversion to and 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 FromIPAndZone(ip net.IP, zone string) (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 IsNAT64IPv4ConvertedIPv6Addr(addr ma.Multiaddr) bool
- func IsPrivateAddr(a ma.Multiaddr) bool
- func IsPublicAddr(a ma.Multiaddr) bool
- func IsThinWaist(m ma.Multiaddr) bool
- func MultiaddrToIPNet(m ma.Multiaddr) (*net.IPNet, error)
- func NetListener(l Listener) net.Listener
- func RegisterFromNetAddr(from FromNetAddrFunc, networks ...string)
- func RegisterToNetAddr(to ToNetAddrFunc, protocols ...string)
- func ResolveUnspecifiedAddress(resolve ma.Multiaddr, ifaceAddrs []ma.Multiaddr) ([]ma.Multiaddr, error)
- func ResolveUnspecifiedAddresses(unspecAddrs, ifaceAddrs []ma.Multiaddr) ([]ma.Multiaddr, error)
- func ToIP(addr ma.Multiaddr) (net.IP, error)
- func ToNetAddr(maddr ma.Multiaddr) (net.Addr, error)
- type CodecMap
- type Conn
- type Dialer
- type FromNetAddrFunc
- type Listener
- type PacketConn
- type ToNetAddrFunc
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") // IP4MappedIP6Loopback is the IPv4 Mapped IPv6 loopback address. IP4MappedIP6Loopback = ma.StringCast("/ip6/::ffff:127.0.0.1") )
Loopback Addresses
var ( IP4Unspecified = ma.StringCast("/ip4/0.0.0.0") IP6Unspecified = ma.StringCast("/ip6/::") )
Unspecified Addresses (used for )
var Private4, Private6 []*net.IPNet
Private4 and Private6 are well-known private networks
var Unroutable4, Unroutable6 []*net.IPNet
Unroutable4 and Unroutable6 are well known unroutable address ranges
Functions ¶
func DialArgs ¶
DialArgs is a convenience function that returns network and address as expected by net.Dial. See https://godoc.org/net#Dial for an overview of possible return values (we do not support the unixpacket ones yet). Unix addresses do not, at present, compose.
func FromNetAddr ¶
FromNetAddr converts a net.Addr type to a Multiaddr.
func InterfaceMultiaddrs ¶
InterfaceMultiaddrs will return the addresses matching net.InterfaceAddrs
func IsIP6LinkLocal ¶
IsIP6LinkLocal returns whether a Multiaddr starts with an IPv6 link-local multiaddress (with zero or one leading zone). These addresses are non routable.
func IsIPLoopback ¶
IsIPLoopback returns whether a Multiaddr starts with a "Loopback" IP address This means either /ip4/127.*.*.*/*, /ip6/::1/*, or /ip6/::ffff:127.*.*.*.*/*, or /ip6zone/<any value>/ip6/<one of the preceding ip6 values>/*
func IsIPUnspecified ¶
IsIPUnspecified returns whether a Multiaddr starts with an Unspecified IP address This means either /ip4/0.0.0.0/* or /ip6/::/*
func IsNAT64IPv4ConvertedIPv6Addr ¶ added in v0.10.0
IsNAT64IPv4ConvertedIPv6Addr returns whether addr is a well-known prefix "64:ff9b::/96" addr used for NAT64 Translation. See RFC 6052
func IsPrivateAddr ¶
IsPrivateAddr returns true if the IP part of the mutiaddr is in a private network
func IsPublicAddr ¶
IsPublicAddr returns true if the IP part of the multiaddr is a publicly routable address or if it's a dns address without a special use domain e.g. .local.
func IsThinWaist ¶
IsThinWaist returns whether a Multiaddr starts with "Thin Waist" Protocols. This means: /{IP4, IP6}[/{TCP, UDP}]
func MultiaddrToIPNet ¶ added in v0.6.0
MultiaddrToIPNet converts a multiaddr to an IPNet. Useful for seeing if another IP address is contained within this multiaddr network+mask
func NetListener ¶
NetListener turns this Listener into a net.Listener.
- Connections returned from Accept implement multiaddr/net Conn.
- Calling WrapNetListener on the net.Listener returned by this function will return the original (underlying) multiaddr/net Listener.
func RegisterFromNetAddr ¶ added in v0.3.2
func RegisterFromNetAddr(from FromNetAddrFunc, networks ...string)
RegisterFromNetAddr registers a conversion from net.Addr instances to multiaddrs.
func RegisterToNetAddr ¶ added in v0.3.2
func RegisterToNetAddr(to ToNetAddrFunc, protocols ...string)
RegisterToNetAddr registers a conversion from multiaddrs to net.Addr instances.
func ResolveUnspecifiedAddress ¶ added in v0.5.0
func ResolveUnspecifiedAddress(resolve ma.Multiaddr, ifaceAddrs []ma.Multiaddr) ([]ma.Multiaddr, error)
ResolveUnspecifiedAddress expands an unspecified ip addresses (/ip4/0.0.0.0, /ip6/::) to use the known local interfaces. If ifaceAddr is nil, we request interface addresses from the network stack. (this is so you can provide a cached value if resolving many addrs)
func ResolveUnspecifiedAddresses ¶ added in v0.5.0
ResolveUnspecifiedAddresses expands unspecified ip addresses (/ip4/0.0.0.0, /ip6/::) to use the known local interfaces.
Types ¶
type CodecMap ¶
type CodecMap struct {
// contains filtered or unexported fields
}
CodecMap holds a map of NetCodecs indexed by their Protocol ID along with parsers for the addresses they use. It is used to keep a list of supported network address codecs (protocols which addresses can be converted to and from multiaddresses).
func NewCodecMap ¶
func NewCodecMap() *CodecMap
NewCodecMap initializes and returns a CodecMap object.
func (*CodecMap) FromNetAddr ¶
FromNetAddr converts a net.Addr to Multiaddress.
func (*CodecMap) RegisterFromNetAddr ¶
func (cm *CodecMap) RegisterFromNetAddr(from FromNetAddrFunc, networks ...string)
RegisterFromNetAddr registers a conversion from net.Addr instances to multiaddrs
func (*CodecMap) RegisterToNetAddr ¶
func (cm *CodecMap) RegisterToNetAddr(to ToNetAddrFunc, protocols ...string)
RegisterToNetAddr registers a conversion from multiaddrs to net.Addr instances
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.
func Dial ¶
Dial connects to a remote address. It uses an underlying net.Conn, then wraps it in a Conn object (with local and remote Multiaddrs).
func WrapNetConn ¶
WrapNetConn wraps a net.Conn object with a Multiaddr friendly Conn.
This function does it's best to avoid "hiding" methods exposed by the wrapped type. Guarantees:
- If the wrapped connection exposes the "half-open" closer methods (CloseWrite, CloseRead), these will be available on the wrapped connection via type assertions.
- If the wrapped connection is a UnixConn, IPConn, TCPConn, or UDPConn, all methods on these wrapped connections will be available via type assertions.
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 FromNetAddrFunc ¶
FromNetAddrFunc is a generic function which converts a net.Addr to Multiaddress
type Listener ¶
type Listener interface { // 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.
type PacketConn ¶
type PacketConn interface { net.PacketConn LocalMultiaddr() ma.Multiaddr ReadFromMultiaddr(b []byte) (int, ma.Multiaddr, error) WriteToMultiaddr(b []byte, maddr ma.Multiaddr) (int, error) }
A PacketConn is a generic packet oriented network connection which uses an underlying net.PacketConn, wrapped with the locally bound Multiaddr.
func ListenPacket ¶
func ListenPacket(laddr ma.Multiaddr) (PacketConn, error)
ListenPacket announces on the local network address laddr. The Multiaddr must be a packet driven network, like udp4 or udp6. See Dial for the syntax of laddr.
func WrapPacketConn ¶
func WrapPacketConn(pc net.PacketConn) (PacketConn, error)
WrapPacketConn wraps a net.PacketConn with a manet.PacketConn.