Documentation ¶
Index ¶
- func DialContext(ctx context.Context, network, laddr, raddr string) (net.Conn, error)
- type Config
- type Dialer
- type Listener
- type ListenerMetrics
- type NamedMetric
- type Option
- func WithLogger(log *zap.Logger) Option
- func WithNPPBacklog(backlog int) Option
- func WithNPPBackoff(min, max time.Duration) Option
- func WithProtocol(protocol string) Option
- func WithRelay(cfg relay.Config, credentials *ecdsa.PrivateKey) Option
- func WithRendezvous(cfg rendezvous.Config, credentials *xgrpc.TransportCredentials) Option
- type Port
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Rendezvous rendezvous.Config `yaml:"rendezvous"` Relay relay.Config `yaml:"relay"` Backlog int `yaml:"backlog" default:"128"` MinBackoffInterval time.Duration `yaml:"min_backoff_interval" default:"500ms"` MaxBackoffInterval time.Duration `yaml:"max_backoff_interval" default:"8000ms"` }
Config represents an NPP (NAT punching protocol) module configuration.
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer represents an NPP dialer.
This structure acts like an usual dialer with an exception that the address must be an authenticated endpoint and the connection establishment process is done via NAT Punching Protocol.
func (*Dialer) Close ¶
Close closes the dialer.
Any blocked operations will be unblocked and return errors.
func (*Dialer) DialContext ¶
DialContext connects to the given verified address using NPP and the provided context.
The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener specifies a net.Listener wrapper that is aware of NAT Punching Protocol and can switch to it when it's required to establish a connection.
Options are: rendezvous server, private IPs usage, relay server(s) if any.
func NewListener ¶
NewListener constructs a new NPP listener that will listen the specified network address with TCP protocol, switching to the NPP when there is no pending connections available.
func (*Listener) Accept ¶
Accept waits for and returns the next connection to the listener.
This method will firstly check whether there are pending sockets in the listener, returning immediately if so. Then an attempt to communicate with the Rendezvous server occurs by publishing server's ID to check if there are someone wanted to connect with us. Simultaneously additional sockets are constructed after resolution to make punching mechanism work. This can consume a meaningful amount of file descriptors, so be prepared to enlarge your limits.
func (*Listener) AcceptContext ¶ added in v0.4.5
func (*Listener) Metrics ¶
func (m *Listener) Metrics() ListenerMetrics
type ListenerMetrics ¶
type NamedMetric ¶ added in v0.4.11
type NamedMetric struct { Name string Metric *prometheusIO.Metric }
type Option ¶
type Option func(o *options) error
Option is a function that configures the listener or dialer.
func WithLogger ¶
WithLogger is an option that specifies provided logger used for the internal logging. Nil value is supported and can be passed to deactivate the logging system entirely.
func WithNPPBacklog ¶
WithNPPBacklog is an option that specifies NPP backlog size.
func WithNPPBackoff ¶
WithNPPBackoff is an option that specifies NPP timeouts.
func WithProtocol ¶ added in v0.4.10
WithProtocol is an option that specifies application level protocol.
In case of servers it will publish itself with a connection ID "PROTOCOL://ETH_ADDRESS". In case of clients this option helps to distinguish whether the destination peer supports such protocol. For example this option is used for punching NAT for SSH connections.
func WithRelay ¶ added in v0.4.14
func WithRelay(cfg relay.Config, credentials *ecdsa.PrivateKey) Option
WithRelay is an option that activates Relay fallback on a NPP dialer and listener.
Without this option no intermediate server will be used for relaying TCP. One or more Relay TCP addresses must be specified in "cfg.Endpoints" argument. Hostname resolution is performed for each of them for environments with dynamic DNS addition/removal. Thus, a single Relay endpoint as a hostname should fit the best. The "credentials" argument is used both for extracting the ETH address of a server and for request signing to ensure that the published server actually owns the ETH address is publishes. When dialing this argument is currently ignored and can be "nil".
func WithRendezvous ¶
func WithRendezvous(cfg rendezvous.Config, credentials *xgrpc.TransportCredentials) Option
WithRendezvous is an option that specifies Rendezvous client settings and activates NAT punching protocol.
Without this option no intermediate server will be used for obtaining peer's endpoints and the entire connection establishment process will fall back to the old good plain TCP connection.