portmapper
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package portmapper is a UDP port mapping client. It currently allows for mapping overNAT-PMP, UPnP, and PCP.
Index¶
- Variables
- func IsNoMappingError(err error) bool
- type Client
- func (c *Client) Close() error
- func (c *Client) GetCachedMappingOrStartCreatingOne() (external netip.AddrPort, ok bool)
- func (c *Client) HaveMapping() bool
- func (c *Client) NoteNetworkDown()
- func (c *Client) Probe(ctx context.Context) (res portmappertype.ProbeResult, err error)
- func (c *Client) SetGatewayLookupFunc(f func() (gw, myIP netip.Addr, ok bool))
- func (c *Client) SetLocalPort(localPort uint16)
- type Config
- type DebugKnobs
- type NoMappingError
Constants¶
This section is empty.
Variables¶
var (ErrNoPortMappingServices =portmappertype.ErrNoPortMappingServicesErrGatewayRange =portmappertype.ErrGatewayRangeErrGatewayIPv6 =portmappertype.ErrGatewayIPv6ErrPortMappingDisabled =portmappertype.ErrPortMappingDisabled)
Functions¶
funcIsNoMappingError¶
IsNoMappingError reports whether err is of type NoMappingError.
Types¶
typeClient¶
type Client struct {// contains filtered or unexported fields}Client is a port mapping client.
funcNewClient¶
NewClient constructs a new portmappingClient from c. It will panic if anyrequired parameters are omitted.
func (*Client)GetCachedMappingOrStartCreatingOne¶added inv1.12.0
GetCachedMappingOrStartCreatingOne quickly returns with our current cached portmapping, if any.If there's not one, it starts up a background goroutine to create one.If the background goroutine ends up creating one, the onChange hook registered with theNewClient constructor (if any) will fire.
func (*Client)HaveMapping¶
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 offtheir wifi), but we can make sure we invalidate mappings for later when the networkcomes back.
func (*Client)Probe¶
func (c *Client) Probe(ctxcontext.Context) (resportmappertype.ProbeResult, errerror)
Probe returns a summary of which port mapping services areavailable 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, withoutsending any network traffic.
func (*Client)SetGatewayLookupFunc¶
SetGatewayLookupFunc set the func that returns the machine's default gateway IP, andthe 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 portmap UDP traffic.
typeConfig¶added inv1.84.0
type Config struct {// EventBus, which must be non-nil, is used for event publication and// subscription by portmapper clients created from this config.EventBus *eventbus.Bus// Logf is called to generate text logs for the client. If nil, logger.Discard is used.Logflogger.Logf// NetMon is the network monitor used by the client. It must be non-nil.NetMon *netmon.Monitor// DebugKnobs, if non-nil, configure the behaviour of the portmapper for// debugging. If nil, a sensible set of defaults will be used.DebugKnobs *DebugKnobs// OnChange is called to run in a new goroutine whenever the port mapping// status has changed. If nil, no callback is issued.OnChange func()}Config carries the settings for aClient.
typeDebugKnobs¶added inv1.38.0
type DebugKnobs struct {// VerboseLogs tells the Client to print additional debug information// to its logger.VerboseLogsbool// LogHTTP tells the Client to print the raw HTTP logs (from UPnP) to// its logger. This is useful when debugging buggy UPnP// implementations.LogHTTPbool// Disable* disables a specific service from mapping.// If the funcs are nil or return false, the service is not disabled.// Use the corresponding accessor methods without the "Func" suffix// to check whether a service is disabled.DisableUPnPFunc func()boolDisablePMPFunc func()boolDisablePCPFunc func()bool// DisableAll, if non-nil, is a func that reports whether all port// mapping attempts should be disabled.DisableAll func()bool}DebugKnobs contains debug configuration that can be provided when creating aClient. The zero value is valid for use.
func (*DebugKnobs)DisablePCP¶added inv1.38.0
func (k *DebugKnobs) DisablePCP()bool
DisablePCP reports whether PCP is disabled.
func (*DebugKnobs)DisablePMP¶added inv1.38.0
func (k *DebugKnobs) DisablePMP()bool
DisablePMP reports whether NAT-PMP is disabled.
func (*DebugKnobs)DisableUPnP¶added inv1.38.0
func (k *DebugKnobs) DisableUPnP()bool
DisableUPnP reports whether UPnP is disabled.
typeNoMappingError¶
type NoMappingError struct {// contains filtered or unexported fields}NoMappingError is returned when no NAT mapping could be done.
func (NoMappingError)Error¶
func (nmeNoMappingError) Error()string
func (NoMappingError)Unwrap¶
func (nmeNoMappingError) Unwrap()error
Source Files¶
Directories¶
| Path | Synopsis |
|---|---|
Package portmappertype defines the net/portmapper interface, which may or may not be linked into the binary. | Package portmappertype defines the net/portmapper interface, which may or may not be linked into the binary. |