项目作者: simkim

项目描述 :
A parking proxy for tcp connections
高级语言: Go
项目地址: git://github.com/simkim/tcpdam.git
创建时间: 2016-07-05T21:26:46Z
项目社区:https://github.com/simkim/tcpdam

开源协议:GNU General Public License v3.0

下载


tcpdam

Overview

tcpdam is a parking proxy for your tcp connection. When your upstream server is ready, send SIGUSR1 to flush connection to the server.

Compilation

  1. make

Usage

  1. tcpdam -l LISTEN-HOST:LISTEN-PORT -r REMOTE-HOST:REMOTE-PORT

will setup a listening tcp server, when something connect it is parked in a waiting list

  1. killall -USR1 tcpdam

will lookup REMOTE-HOST once, and open the dam : the parked and new connections are proxified to REMOTE-HOST.

  1. killall -USR2 tcpdam

will re-close the dam and start to park new connections,

Configuration

Env Command line Description
TCPDAM_LISTEN_ADDRESS -l Listen address for incoming connections
TCPDAM_REMOTE_ADDRESS -h Remote address where the connections will be flushed
TCPDAM_DEBUG -d Show all information
TCPDAM_VERBOSE -v Show some information
TCPDAM_PIDFILE -p File which will contain the pid of the dam
TCPDAM_CTRLSOCKET -ctrl-socket Unix socket to control the dam
TCPDAM_MAX_FLUSHING -max-flushing Max number of open remote connections
TCPDAM_MAX_PARKED -max-parked Max number of connections in the queue
TCPDAM_OPEN -open Start the dam open
-c command to send to a running dam

Remote Commands

Command Description
open open the dam unless already open
close close the dam unless already closed
set-remote HOST:PORT switch the remote address, will be used at the next open

Limits

Open file descriptors

You need to configure your maximum number of file descriptor to allow a high number of parked connections

  • debian : configure /etc/security/limits.conf
  • docker : docker run —ulimit nofile=100000:100000
  • compose : see docker-compose.yml

netfilter conntrack size

TODO

tcp TIME_WAIT

TODO

Docker

From the hub

To run the dam

  1. docker run -p 9999:9999 --rm -ti --name tcpdam_test simkim/tcpdam tcpdam -r google.com:80

To open the dam

  1. docker exec tcpdam_test killall -USR1 tcpdam

To open the dam, wait for connections to terminate and quit

  1. docker stop tcpdam_test

From local build

  1. Edit docker-compose.yml
  2. docker run -v `pwd`/build:/go/bin -v `pwd`:/go/src/github.com/simkim/tcpdam --rm golang go get github.com/simkim/tcpdam/...
  3. docker-compose build
  4. docker-compose up