proxy

package
v0.0.0-...-bf25629 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 16 Imported by: 8

Documentation

Overview

docker-proxy provides a network Proxy interface and implementations for TCP and UDP.

Package proxy is used to create and register proxies that forward traffic from a port/ip combination, address, to a set of backends

Index

Constants

View Source
const (
	// UDPConnTrackTimeout is the timeout used for UDP connection tracking
	UDPConnTrackTimeout = 90 * time.Second
	// UDPBufSize is the buffer size for the UDP proxy
	UDPBufSize = 65507
)

Variables

View Source
var (
	// command to generate: openssl req -x509 -sha256 -nodes -days 1826 -newkey rsa:2048 -keyout NEW_SERVER_KEY.key -out NEW_SERVER_CERT.crt
	InsecureCertPEM = `` /* 1443-byte string literal not displayed */

	InsecureKeyPEM = `` /* 1703-byte string literal not displayed */

)

Functions

func GetKeyPairs

func GetKeyPairs(certPEMFile, keyPEMFile string) (certPEM, keyPEM []byte, err error)

func ProxyLoop

func ProxyLoop(client net.Conn, backend net.Conn, quit chan bool)

func TempCertFile

func TempCertFile() (string, error)

TempCertFile creates a temp file with the contents set to proxyCertPEM and returns the temp file path.

func TempKeyFile

func TempKeyFile() (string, error)

TempKeyFile creates a temp file with the contents set to proxyCertPEM and returns the temp file path.

Types

type DockerProxy

type DockerProxy interface {
	// Run starts forwarding traffic back and forth between the front
	// and back-end addresses.
	Run()
	// Close stops forwarding traffic and close both ends of the DockerProxy.
	Close()
	// FrontendAddr returns the address on which the proxy is listening.
	FrontendAddr() net.Addr
	// BackendAddr returns the proxied address.
	BackendAddr() net.Addr
}

DockerProxy defines the behavior of a proxy. It forwards traffic back and forth between two endpoints : the frontend and the backend. It can be used to do software port-mapping between two addresses. e.g. forward all traffic between the frontend (host) 127.0.0.1:3000 to the backend (container) at 172.17.42.108:4000.

func NewProxy

func NewProxy(frontendAddr, backendAddr net.Addr) (DockerProxy, error)

NewProxy creates a DockerProxy according to the specified frontendAddr and backendAddr.

type Proxy

type Proxy interface {
	Run() error
	Close() error
}

Proxy is the interface of a proxy.

type ProxyAddress

type ProxyAddress struct {
	IP   string
	Port uint16
}

ProxyAddress is a IP and port grouping

type ProxyFactory

type ProxyFactory func(protocol string, frontend ProxyAddress, backEnds ...ProxyAddress) (Proxy, error)

ProxyFactory is a function declaration for a proxy factory.

type ProxyRegistry

type ProxyRegistry interface {
	//CreateProxy create, registers and starts a proxy identified by key
	//protocol is TCP or UDP
	//frontEnd is the IP/Port to listen on
	//backends are the what is being proxied, It is up to the proxy implementation on how it distributes requests to the backends
	CreateProxy(key string, protocol string, frontend ProxyAddress, backEnds ...ProxyAddress) error

	//RemoveProxy stops and removes proxy.
	RemoveProxy(key string) (Proxy, error)
}

ProxyRegistry is an interface of a proxy registration service

func NewDefaultProxyRegistry

func NewDefaultProxyRegistry() ProxyRegistry

NewDefaultProxyRegistry Create a new ProxyRegistry

func NewProxyRegistry

func NewProxyRegistry(factory ProxyFactory) ProxyRegistry

NewProxyRegistry Create a new ProxyRegistry using the supplied ProxyFactory

type SCTPProxy

type SCTPProxy struct {
	// contains filtered or unexported fields
}

SCTPProxy is a proxy for SCTP connections. It implements the Proxy interface to handle SCTP traffic forwarding between the frontend and backend addresses.

func NewSCTPProxy

func NewSCTPProxy(frontendAddr, backendAddr *sctp.SCTPAddr) (*SCTPProxy, error)

NewSCTPProxy creates a new SCTPProxy.

func (*SCTPProxy) BackendAddr

func (proxy *SCTPProxy) BackendAddr() net.Addr

BackendAddr returns the SCTP proxied address.

func (*SCTPProxy) Close

func (proxy *SCTPProxy) Close()

Close stops forwarding the traffic.

func (*SCTPProxy) FrontendAddr

func (proxy *SCTPProxy) FrontendAddr() net.Addr

FrontendAddr returns the SCTP address on which the proxy is listening.

func (*SCTPProxy) Run

func (proxy *SCTPProxy) Run()

Run starts forwarding the traffic using SCTP.

type TCPMux

type TCPMux struct {
	// contains filtered or unexported fields
}

TCPMux is an implementation of tcp muxing RFC 1078.

func NewTCPMux

func NewTCPMux(listener net.Listener) (mux *TCPMux, err error)

NewTCPMux creates a new tcp mux with the given listener. If it succees, it is expected that this object is the owner of the listener and will close it when Close() is called on the TCPMux.

func (*TCPMux) Close

func (mux *TCPMux) Close()

type TCPProxy

type TCPProxy struct {
	// contains filtered or unexported fields
}

TCPProxy is a proxy for TCP connections. It implements the Proxy interface to handle TCP traffic forwarding between the frontend and backend addresses.

func NewTCPProxy

func NewTCPProxy(frontendAddr, backendAddr *net.TCPAddr) (*TCPProxy, error)

NewTCPProxy creates a new TCPProxy.

func (*TCPProxy) BackendAddr

func (proxy *TCPProxy) BackendAddr() net.Addr

BackendAddr returns the TCP proxied address.

func (*TCPProxy) Close

func (proxy *TCPProxy) Close()

Close stops forwarding the traffic.

func (*TCPProxy) FrontendAddr

func (proxy *TCPProxy) FrontendAddr() net.Addr

FrontendAddr returns the TCP address on which the proxy is listening.

func (*TCPProxy) Run

func (proxy *TCPProxy) Run()

Run starts forwarding the traffic using TCP.

type UDPProxy

type UDPProxy struct {
	// contains filtered or unexported fields
}

UDPProxy is proxy for which handles UDP datagrams. It implements the Proxy interface to handle UDP traffic forwarding between the frontend and backend addresses.

func NewUDPProxy

func NewUDPProxy(frontendAddr, backendAddr *net.UDPAddr) (*UDPProxy, error)

NewUDPProxy creates a new UDPProxy.

func (*UDPProxy) BackendAddr

func (proxy *UDPProxy) BackendAddr() net.Addr

BackendAddr returns the proxied UDP address.

func (*UDPProxy) Close

func (proxy *UDPProxy) Close()

Close stops forwarding the traffic.

func (*UDPProxy) FrontendAddr

func (proxy *UDPProxy) FrontendAddr() net.Addr

FrontendAddr returns the UDP address on which the proxy is listening.

func (*UDPProxy) Run

func (proxy *UDPProxy) Run()

Run starts forwarding the traffic using UDP.

Jump to

Keyboard shortcuts

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