forward

package module
v0.0.0-...-e71a172 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2022 License: Unlicense Imports: 4 Imported by: 0

README

udp-forward

A dead simple Go (golang) package to forward UDP packets like a reverse NAT (i.e. it supports multiple users).

Usage

package main

import "github.com/1lann/udp-forward"

func main() {
	// Forward(src, dst). It's asynchronous.
	forwarder, err := forward.Forward("0.0.0.0:1000", "1.2.3.4:1023", forward.DefaultTimeout)
	if err != nil {
		panic(err)
	}

	// Do something...

	// Stop the forwarder
	forwarder.Close()
}

See the GoDoc for documentation.

License

There is no license.

Documentation

Overview

Package forward contains a UDP packet forwarder.

Index

Constants

View Source
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

func Forward(src, dst string, timeout time.Duration) (*Forwarder, error)

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) Close

func (f *Forwarder) Close()

Close stops the forwarder.

func (*Forwarder) Connected

func (f *Forwarder) Connected() []string

Connected returns the list of connected clients in IP:port form.

func (*Forwarder) OnConnect

func (f *Forwarder) OnConnect(callback func(addr string))

OnConnect can be called with a callback function to be called whenever a new client connects.

func (*Forwarder) OnDisconnect

func (f *Forwarder) OnDisconnect(callback func(addr string))

OnDisconnect can be called with a callback function to be called whenever a new client disconnects (after 5 minutes of inactivity).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL