udpp

package module
v0.0.0-...-938814e Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 13 Imported by: 0

README

udpp

A Point-to-Point UDP Tunnel.

Usage

Generate an example config file:

udpp new

A new file config.yml was created in current directory.

id: 1f0e4346-b633-4525-af3c-33f8f4aa841b
server: redis://127.0.0.1:6379
local: 127.0.0.1:9999

The server only supports redis for now.

Server

The following configuration exposes a service listening on udp port 9999.

id: 1f0e4346-b633-4525-af3c-33f8f4aa841b
server: redis://127.0.0.1:6379
local: 127.0.0.1:9999
Client

Access your server using peer config:

id: e5958a55-1c94-4368-82fa-86de1e1af24a
server: redis://127.0.0.1:6379
local: 127.0.0.1:5321
peer:
  id: 1f0e4346-b633-4525-af3c-33f8f4aa841b
  bind: 127.0.0.1:6565

The client listens on 127.0.0.1:6565 for incoming traffic and forwards to the target peer.

Note that 127.0.0.1:5321 is the source address of your local visitor client.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStreamExists = fmt.Errorf("stream already exists")
	ErrNodeInactive = fmt.Errorf("inactive node")
)
View Source
var ErrPeerNotFound = fmt.Errorf("peer not found")

Functions

func NewRedis

func NewRedis(uri string) (*redis.Client, error)

func Setup

func Setup(uri string) (err error)

Types

type Host

type Host struct {
	ID        string
	Endpoint  *net.UDPAddr        // Public network endpoint
	LocalAddr *net.UDPAddr        // Local network endpoint
	NAT       *nathole.NatFeature // NAT information of the host
	// contains filtered or unexported fields
}

func NewHost

func NewHost(ctx context.Context, id string, opts ...config.Option) (*Host, error)

NewHost maps a local address to a public address using STUN server.

func (*Host) Close

func (h *Host) Close() (err error)

func (*Host) Expired

func (h *Host) Expired() <-chan struct{}

func (*Host) NewStream

func (h *Host) NewStream(peer *Peer) (*Stream, error)

NewStream creates an udp connection to the given peer.

func (*Host) Serve

func (h *Host) Serve(addr *net.UDPAddr) error

Serve listens for new peer connection.

type NAT

type NAT struct {
	LocalAddr   *net.UDPAddr
	RemoteAddrs []*net.UDPAddr
	Feature     *nathole.NatFeature
}

func Discover

func Discover(server string) (*NAT, error)

type Peer

type Peer struct {
	ID       string
	Endpoint *net.UDPAddr
}

func FindPeer

func FindPeer(ctx context.Context, id string) (*Peer, error)

func NewPeer

func NewPeer(id string, endpoint *net.UDPAddr) *Peer

type Stream

type Stream struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewStream

func NewStream(conn net.Conn, hostId, peerId string, timeout int64) *Stream

func (*Stream) Expired

func (s *Stream) Expired() bool

Expired Checks if the connection is inactive.

func (*Stream) Join

func (s *Stream) Join(other net.Conn) (err error)

Join provides a method for bridging two connections and facilitating data transmission between them. Note that both connections are closed after the function returns.

func (*Stream) Ping

func (s *Stream) Ping(ctx context.Context) error

func (*Stream) Read

func (s *Stream) Read(p []byte) (n int, err error)

func (*Stream) Write

func (s *Stream) Write(p []byte) (n int, err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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