Documentation
¶
Overview ¶
Package forward contains a UDP packet forwarder.
Index ¶
- Constants
- type Forwarder
- type Logger
- type Option
- func WithAddr(src string) Option
- func WithBufferSize(size int) Option
- func WithConn(conn *net.UDPConn) Option
- func WithDestination(dest string) Option
- func WithLogger(logger Logger) Option
- func WithRouter(router Router) Option
- func WithRouterFunc(router func(*net.UDPAddr) *net.UDPAddr) Option
- func WithTimeout(timeout time.Duration) Option
- func WithoutLogger() Option
- type Router
Constants ¶
const DefaultTimeout = time.Minute * 5
DefaultTimeout is the default timeout period of inactivity for convenience sake. It is equivelant to 5 minutes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
Forwarder represents a UDP packet forwarder.
func Forward ¶
Forward forwards UDP packets from the src address to the dst address, with a timeout to "disconnect" clients after the timeout period of inactivity. It implements a reverse NAT and thus supports multiple seperate users. Forward is also asynchronous.
func (*Forwarder) OnConnect ¶
OnConnect can be called with a callback function to be called whenever a new client connects.
func (*Forwarder) OnDisconnect ¶
OnDisconnect can be called with a callback function to be called whenever a new client disconnects (after 5 minutes of inactivity).
type Option ¶
type Option func(*config) error
Option gives the way to customize the forwarder.
func WithBufferSize ¶
WithBufferSize sets the buffer size that is used by forwarding. Larger packet can be discarded.
func WithDestination ¶
WithDestination lets the new forwarder forward packets to the given address.
func WithRouter ¶
WithRouter lets the new forwarder forward packets according to the given router.
func WithRouterFunc ¶
WithRouterFunc does the same as WithRouter, but with a function.
func WithTimeout ¶
WithTimeout sets the timeout. No interaction more than the timeout will remove the connection from the NAT table.