Documentation
¶
Overview ¶
Package portmap keeps the listening port reachable from the internet through the router (UPnP IGD, NAT-PMP). Unlike fire-and-forget mapping it renews the lease, verifies that the mapping still exists and re-creates it after a router reboot or an IP change, which is the usual reason a forwarded port "breaks after a while".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the mapping loop.
type Mapper ¶
type Mapper interface {
Name() string
// Map creates or refreshes a mapping and returns the external IP.
Map(ctx context.Context, proto string, port int, lease time.Duration) (extIP string, err error)
// Exists reports whether the mapping is still present on the router. Protocols that
// cannot be queried return (true, nil) and rely on regular renewal.
Exists(ctx context.Context, proto string, port int) (bool, error)
Unmap(ctx context.Context, proto string, port int) error
}
Mapper is one port-forwarding protocol.
type NATPMP ¶
type NATPMP struct {
// contains filtered or unexported fields
}
NATPMP implements Mapper on top of NAT-PMP (also answered by PCP-capable routers).
func NewNATPMPWith ¶ added in v1.1.0
NewNATPMPWith asks the router at the address router returns first (read each time, so a change in the settings applies at once); with "" it finds the router itself.
func (*NATPMP) Exists ¶
NAT-PMP has no query operation; regular lease renewal keeps the mapping alive.
type Options ¶
type Options struct {
Lease time.Duration // requested lease, default 1h
CheckInterval time.Duration // verify/renew period, default 5m
MinBackoff time.Duration // after a failure, default 15s
MaxBackoff time.Duration // default 5m
// Router returns the router's address given in the settings ("" = find it), for NAT-PMP where the default
// gateway is not the router (a container). Nil is the same as "".
Router func() string
}
Options tune timings; zero values pick defaults.
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
Mapped bool `json:"mapped"`
Method string `json:"method,omitempty"`
Port int `json:"port"`
ExternalIP string `json:"externalIP,omitempty"`
LastOK time.Time `json:"lastOk,omitempty"`
LastError string `json:"lastError,omitempty"`
Failures int `json:"failures"` // consecutive failed cycles
Remaps int `json:"remaps"` // times a lost mapping had to be recreated
}
Status describes the current state for the UI.