destructive_socks5_proxy

package module
v0.0.0-...-1b661fe Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: MIT Imports: 9 Imported by: 0

README

##Destructive Proxy

Utilizes the Socks5 proxy protocol to proxy all socket traffic.

In addition to providing proxy functionality, the destructive proxy is able to inject latency around network calls and shutdown connections by hostname.

How Build From Source

  • Install latest GO version (https://golang.org/dl).
    • The following steps assume GO is installed to /usr/local/go (refer to GO_HOME below)
  • edit .bash_profile and add these lines:
export GOPATH=~/GOWorkspace
export GO_HOME=/usr/local/go 
export PATH=$PATH:$GO_HOME/bin:$GOPATH/bin
  • Run these commands:
go get github.com/intuit/destructive_socks5_proxy
go get -u golang.org/x/net/proxy
go get github.com/Unknwon/macaron
cd ~/GOWorkspace/src/github.com/intuit/destructive_socks5_proxy
./test_with_coverage.sh
  • Expected output:
....
PASS
coverage: 93.6% of statements
ok      github.com/intuit/destructive_socks5_proxy  
  • Now run these commands:
   cd destructive_socks5_proxy
   ./build.sh
   ls *
  • Expected output:
.... 
destructive_socks5_proxy_darwin_amd64
destructive_socks5_proxy_linux_amd64
destructive_socks5_proxy_windows_amd64.exe

Usage

Default
$PORT=4000 ./destructive_socks5_proxy

##### Commandline Options

Linux

$ ./destructive_socks5_proxy_linux_amd64 -help
Usage of ./destructive_socks5_proxy:
  -addr="0.0.0.0:9000": address to listen on
  -blacklist="": csv list of hosts to blacklist
  -config="todo": optional json config file of host:latency:type
  -whitelist="": csv list of hosts to whitelist.

Mac

$ ./destructive_socks5_proxy_darwin_amd64 -help
Usage of ./destructive_socks5_proxy:
  -addr="0.0.0.0:9000": address to listen on
  -blacklist="": csv list of hosts to blacklist
  -config="todo": optional json config file of host:latency:type
  -whitelist="": csv list of hosts to whitelist.

Note that the included binaries are located in the destructive_socks5_proxy subdirectory.

Java Parameters

# For example:
java  -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=9000 ...

API

/set_latency/:host/per_remote_write?latency=100ms[&count=1]
  • Set the per_remote_write latency for the :host parameter
    • Adds latency for every network write to the remote host. One connection can make many network writes, even for a single request.
    • Optionally, specify a count value to limit the number of times the latency value is applied. For instance, count=1 means the only 1 remote write will have the latency added. Note that count < 0, indicates means to continue to add latency to all remote writes until latency is explicitly removed. This is the default behavior.
  • The latency parameter parses a duration string (e.g., 60000ms, 60s, 1m).
/set_latency/:host/per_remote_read?latency=100ms[&count=1]
  • Set the per_remote_read latency for the :host parameter
    • Adds latency for every network read from the remote host. One connection can make many network reads, even for a single request.
    • Optionally, specify a count value to limit the number of times the latency value is applied. For instance, count=1 means the only 1 remote read will have the latency added. Note that count < 0, indicates means to continue to add latency to all remote reads until latency is explicitly removed. This is the default behavior.
  • The latency parameter parses a duration string (e.g., 60000ms, 60s, 1m).
/set_latency/:host/per_remote_connect?latency=100ms[&count=1]
  • Set the per_remote_connect latency for the :host parameter

    • Adds latency for each network connect to the remote host. Does not work very well for long lived connections (e.g., JMS, JDBC)
    • Optionally, specify a count value to limit the number of times the latency value is applied. For instance, count=1 means the only 1 remote write will have the latency added. Note that count < 0, indicates means to continue to add latency to all remote writes until latency is explicitly removed. This is the default behavior.
  • The latency parameter parses a duration string (e.g., 60000ms, 60s, 1m).

/get_latancy/:host/per_remote_write
  • Lists hostname and latency for the :host parameter if latency has been set with per_remote_write parameter
/get_latancy/:host/per_remote_connect
  • Lists hostname and latency for the :host parameter if latency has been set with per_remote_connect parameter
/get_latancy/all/per_remote_write
  • Lists hostname and latency for all hosts that have had latency set using the per_remote_write parameter
/get_latancy/all/per_remote_connect
  • Lists hostname and latency for all hosts that have had latency set using the per_remote_connect parameter
/counters
  • Lists counts and metrics on which hosts have been seen, bytes, total latency, etc
/counters/reset
  • Resets counters
/dependencies
  • Lists dependencies
/whitelist/:host/:add_or_remove
  • Add or remote a host to the whitelist.
    • Requires the server to be started with the -whitelist option.
    • Note: blacklist and whitelist can't be used at the same time.
/whitelisted
  • Lists hosts that have been added to the whitelist
/blacklist/:host/:add_or_remove
  • Add or remote a host to the blacklist.
    • Requires the server to be started with the -blacklist option.
    • Note: blacklist and whitelist can't be used at the same time.
/blacklisted
  • Lists hosts that have been added to the whitelist

Documentation

Index

Constants

View Source
const (
	PER_REMOTE_READ    = "per_remote_read"
	PER_REMOTE_WRITE   = "per_remote_write"
	PER_REMOTE_CONNECT = "per_remote_connect"
	ACTIVE_CONNS       = "conns;Active:All"
	TOTAL_CONNS        = "conns;Total;All"
	TOTAL_BYTES_IN     = "bytes;Total;In"
	TOTAL_BYTES_OUT    = "bytes;Total;Out"
)

core

Variables

View Source
var (
	Counters     = make(map[string]float64)
	CountersSync sync.RWMutex
)
View Source
var (
	HostToSleepPerRemoteWrite       = make(map[string]LatencyAndCountStruct)
	HostToSleepPerRemoteWriteSync   sync.RWMutex
	HostToSleepPerRemoteRead        = make(map[string]LatencyAndCountStruct)
	HostToSleepPerRemoteReadSync    sync.RWMutex
	HostToSleepPerRemoteConnect     = make(map[string]LatencyAndCountStruct)
	HostToSleepPerRemoteConnectSync sync.RWMutex
	Blacklist                       = false
	HostToClose                     = make(map[string]interface{})

	Whitelist   = false
	HostToAllow = make(map[string]interface{})
)

Destructive behaviors

Functions

func NewListenerForTcpCopyingProxy

func NewListenerForTcpCopyingProxy(addr string)

func RW_Locker

func RW_Locker(locker sync.RWMutex, fn func())

func SetBlacklistForHost

func SetBlacklistForHost(host string, add bool) (string, error)

func SetLatencyForHost

func SetLatencyForHost(host, _type string, latency time.Duration, count int) (string, error)

func SetWhitelistForHost

func SetWhitelistForHost(host string, add bool) (string, error)

Types

type Counter

type Counter string

metrics

func (Counter) Add

func (c Counter) Add(v float64)

func (Counter) Dec

func (c Counter) Dec()

func (Counter) Inc

func (c Counter) Inc()

type LatencyAndCountStruct

type LatencyAndCountStruct struct {
	Latency time.Duration
	Count   int
}

func GetLatencyForHost

func GetLatencyForHost(host, _type string) (string, LatencyAndCountStruct, bool, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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