tcpproxy

package module
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 12 Imported by: 0

README

tcpproxy

Simple TCP proxy written in Go

Build Status GoDoc Coverage Status Docker Image Version (latest semver)

Install

Build it yourself:

$ go get github.com/cenkalti/tcpproxy/cmd/tcpproxy

or download pre-compiled binary from releases page:

$ wget "https://github.com/cenkalti/tcpproxy/releases/download/v<VERSION>/tcpproxy"

or pull pre-built docker image:

$ docker pull cenkalti/tcpproxy

Usage

$ tcpproxy -h
usage: ./tcpproxy [options] listen_address remote_address
  -c duration
    	connect timeout (default 10s)
  -d	enable debug log
  -g duration
    	grace period in seconds before killing open connections (default 10s)
  -k duration
    	TCP keepalive period (default 1m0s)
  -m string
    	listen address for management interface
  -r duration
    	DNS resolve period (default 10s)
  -s string
    	file to save/load remote address to survive restarts
  -v	print version and exit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version string

Version that is defined in git tag. There should be a release in GitHub with this tag.

Functions

This section is empty.

Types

type ConnsResponse added in v1.2.0

type ConnsResponse struct {
	Conns      []MgmtConn `json:"conns"`
	Goroutines int        `json:"goroutines"`
}

type IPPort added in v1.2.0

type IPPort struct {
	IP   string `json:"ip"`
	Port int    `json:"port"`
}

type MgmtConn added in v1.2.0

type MgmtConn struct {
	ClientOut IPPort `json:"client_out"`
	ProxyIn   IPPort `json:"proxy_in"`
	ProxyOut  IPPort `json:"proxy_out"`
	ServerIn  IPPort `json:"server_in"`
}

type Proxy

type Proxy struct {
	// enable debug log
	DebugLog bool

	// save state in this file to survive restarts
	StatePath string

	// listen http on this address for management interface
	MgmtListenAddr string

	// seconds to wait before killing open connections on remote address switch
	GracePeriod time.Duration

	// time to wait when connecting the server
	ConnectTimeout time.Duration

	// tcp keepalive period
	Keepalive time.Duration

	// when should we resolve again?
	ResolvePeriod time.Duration

	// channel is closed when proxy is ready to accept connections
	Ready chan struct{}
	// contains filtered or unexported fields
}

Proxy is a TCP proxy that proxies all incoming connections to a remote address.

func NewProxy

func NewProxy(listenAddress, remoteAddress string) *Proxy

NewProxy returns a new Proxy server.

func (*Proxy) GetRemoteAddress

func (p *Proxy) GetRemoteAddress() string

GetRemoteAddress returns the current remote address.

func (*Proxy) Run

func (p *Proxy) Run()

Run the proxy by listening the address and accepting incoming connections.

func (*Proxy) SetRemoteAddress

func (p *Proxy) SetRemoteAddress(newAddr string)

SetRemoteAddress sets the remote address. When remote address has been changed, after p.GracePeriod duration, all previous connections are killed if they are still alive.

func (*Proxy) Shutdown

func (p *Proxy) Shutdown() error

Shutdown the proxy gracefully.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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