Documentation ¶
Overview ¶
Package portmapper is a UDP port mapping client. It currently only does NAT-PMP, but will likely do UPnP and perhaps PCP later.
Index ¶
- Variables
- func IsNoMappingError(err error) bool
- type Client
- func (c *Client) Close() error
- func (c *Client) CreateOrGetMapping(ctx context.Context) (external netaddr.IPPort, err error)
- func (c *Client) HaveMapping() bool
- func (c *Client) NoteNetworkDown()
- func (c *Client) Probe(ctx context.Context) (res ProbeResult, err error)
- func (c *Client) SetGatewayLookupFunc(f func() (gw, myIP netaddr.IP, ok bool))
- func (c *Client) SetLocalPort(localPort uint16)
- type NoMappingError
- type ProbeResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPortMappingServices = errors.New("no port mapping services were found") ErrGatewayNotFound = errors.New("failed to look up gateway address") )
Functions ¶
func IsNoMappingError ¶
IsNoMappingError reports whether err is of type NoMappingError.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a port mapping client.
func (*Client) CreateOrGetMapping ¶
CreateOrGetMapping either creates a new mapping or returns a cached valid one.
If no mapping is available, the error will be of type NoMappingError; see IsNoMappingError.
func (*Client) HaveMapping ¶
HaveMapping reports whether we have a current valid mapping.
func (*Client) NoteNetworkDown ¶
func (c *Client) NoteNetworkDown()
NoteNetworkDown should be called when the network has transitioned to a down state. It's too late to release port mappings at this point (the user might've just turned off their wifi), but we can make sure we invalidate mappings for later when the network comes back.
func (*Client) Probe ¶
func (c *Client) Probe(ctx context.Context) (res ProbeResult, err error)
Probe returns a summary of which port mapping services are available on the network.
If a probe has run recently and there haven't been any network changes since, the returned result might be server from the Client's cache, without sending any network traffic.
func (*Client) SetGatewayLookupFunc ¶
SetGatewayLookupFunc set the func that returns the machine's default gateway IP, and the primary IP address for that gateway. It must be called before the client is used. If not called, interfaces.LikelyHomeRouterIP is used.
func (*Client) SetLocalPort ¶
SetLocalPort updates the local port number to which we want to port map UDP traffic.
type NoMappingError ¶
type NoMappingError struct {
// contains filtered or unexported fields
}
NoMappingError is returned by CreateOrGetMapping when no NAT mapping could be returned.
func (NoMappingError) Error ¶
func (nme NoMappingError) Error() string
func (NoMappingError) Unwrap ¶
func (nme NoMappingError) Unwrap() error