udpproxy

package
v0.0.0-...-4748651 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package udpproxy provides an API for proxying UDP messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	Name             string
	Addr             *net.UDPAddr
	MessageSentCount uint
	MessageRecvCount uint
	Responder        chan []byte
	Touched          bool
}

Backend is the UDP backend

func NewBackend

func NewBackend(name string, addr string, scheduler Scheduler) (*Backend, error)

NewBackend spawns a new UDP backend.

func (*Backend) CreateConnection

func (be *Backend) CreateConnection() (*net.UDPConn, error)

CreateConnection spawnes a new UDP connection for given Backend.

func (*Backend) Send

func (be *Backend) Send(msg []byte, sender *net.UDPAddr, fe *Frontend) error

Send sends a single UDP message to this backend.

func (Backend) String

func (be Backend) String() string

func (*Backend) Touch

func (be *Backend) Touch()

Touch touches the given backend.

type Frontend

type Frontend struct {
	Name            string
	Conn            *net.UDPConn
	Scheduler       Scheduler
	Backends        []*Backend
	ResponseTimeout time.Duration
}

Frontend represents a UDP frontend

func NewFrontend

func NewFrontend(name, addr string, sched Scheduler) (*Frontend, error)

NewFrontend spawns a new UDP frontend.

func (*Frontend) AddBackend

func (fe *Frontend) AddBackend(name, addr string) (*Backend, error)

AddBackend extends given UDP Frontend with a new backend.

func (*Frontend) ClearTouch

func (fe *Frontend) ClearTouch()

ClearTouch clears out any touch-flags on all backends to this frontend.

func (*Frontend) Close

func (fe *Frontend) Close()

Close releases underlying sockets to given UDP frontend.

func (*Frontend) Multicast

func (fe *Frontend) Multicast(msg []byte, sender *net.UDPAddr)

Multicast sends the given message to this fronend to all backends.

func (*Frontend) RemoveUntouched

func (fe *Frontend) RemoveUntouched()

RemoveUntouched kills all backends that haven't been touched with Touch().

func (*Frontend) RoundRobin

func (fe *Frontend) RoundRobin(msg []byte, sender *net.UDPAddr)

RoundRobin sends the given message in round-robin fasion to exactly one backend.

func (*Frontend) Serve

func (fe *Frontend) Serve()

Serve serves given UDP frontend on current thread. Blocking.

func (*Frontend) String

func (fe *Frontend) String() string

String high-level view of this object as string.

type Proxy

type Proxy struct {
	// listen on downstreams and pass them upstream
	Frontends map[string]*Frontend
	// contains filtered or unexported fields
}

Proxy represents a generic UDP proxy for many UDP frontends

func NewProxy

func NewProxy() *Proxy

NewProxy spawns a new UDP proxy.

func (*Proxy) AddFrontend

func (proxy *Proxy) AddFrontend(name, addr string, sched Scheduler) (*Frontend, error)

AddFrontend does what it says ;-)

func (*Proxy) AddOrReplaceFrontend

func (proxy *Proxy) AddOrReplaceFrontend(name, addr string, sched Scheduler) (*Frontend, error)

AddOrReplaceFrontend does what it says. ;-)

func (*Proxy) Dump

func (proxy *Proxy) Dump()

Dump dumps the UDP proxy to stdout.

func (*Proxy) Quit

func (proxy *Proxy) Quit()

Quit triggers a termination of Serve()

func (*Proxy) Serve

func (proxy *Proxy) Serve()

Serve serves all frontends in backend and waits for them to terminate.

type Scheduler

type Scheduler int

Scheduler algorithm to use for proxying the UDP message.

const (
	// RoundRobin is the round-robin scheduler
	RoundRobin Scheduler = 1

	// Multicast (aka. fanout) scheduler. sends message to *all* backends.
	Multicast Scheduler = 2
)

func (Scheduler) String

func (s Scheduler) String() string

type Session

type Session struct {
	LastActive  time.Time
	Backend     *Backend
	RequestBuf  string
	ResponseBuf string
}

Session represents a UDP communication session

Jump to

Keyboard shortcuts

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