...

Package proxy

import "github.com/docker/go-connections/proxy"
Overview
Index

Overview ▾

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

Constants

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
)

type Proxy

Proxy 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.

type Proxy 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 Proxy.
    Close()
    // FrontendAddr returns the address on which the proxy is listening.
    FrontendAddr() net.Addr
    // BackendAddr returns the proxied address.
    BackendAddr() net.Addr
}

func NewProxy

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

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

func NewStubProxy

func NewStubProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)

NewStubProxy creates a new StubProxy

type StubProxy

StubProxy is a proxy that is a stub (does nothing).

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

func (*StubProxy) BackendAddr

func (p *StubProxy) BackendAddr() net.Addr

BackendAddr returns the backend address.

func (*StubProxy) Close

func (p *StubProxy) Close()

Close does nothing.

func (*StubProxy) FrontendAddr

func (p *StubProxy) FrontendAddr() net.Addr

FrontendAddr returns the frontend address.

func (*StubProxy) Run

func (p *StubProxy) Run()

Run does nothing.

type TCPProxy

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

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

func NewTCPProxy

func NewTCPProxy(frontendAddr, backendAddr *net.TCPAddr, ops ...func(*TCPProxy)) (*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

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

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

func NewUDPProxy

func NewUDPProxy(frontendAddr, backendAddr *net.UDPAddr, ops ...func(*UDPProxy)) (*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.