proxy

package module
v0.0.0-...-783a48b Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2016 License: MIT Imports: 24 Imported by: 0

README

localproxy

Usage

./server -port=18001 -v=2 -log_dir="/data/logs" -alsotostderr=true

See ./server -h for the details.

HTTP API

/api/get-proxy-conn get a dynamic proxy address.

POST data :

{
    "PID":"nsq-12",
    "RemoteAddr":"10.10.1.100:12345",
    "Protocol":"unix",
    "InitSendData":""
}

Note: PID is used to separate the different client to the same service, basically, we can use the same pid for all clients. However, we can separate it to avoid some contention. InitSendData: this can be used to init the connection after the success connect. (such as the auth or identify client.)

/api/close-proxy-conn close the remote immediately.

POST data:

{
    "PID":"nsq-12",
    "RemoteAddr":"10.10.1.100:12345",
    "Protocol":"unix",
    "InitSendData":""
}

Note: This will close all the connections to the remote associated with PID.

/api/destroy-proxy close all the remote and stop the dynamic proxy listener associated with the specific remote address and PID.

POST data:

{
    "PID":"nsq-12",
    "RemoteAddr":"10.10.1.100:12345",
    "Protocol":"unix",
    "InitSendData":""
}

Note: If this dynamic proxy is not used anymore, the client can destroy it using this API. Basically, this is not necessary since the proxy can handle this situation.

/api/destroy-all close and stop all the dynamic proxy listener associated with the specific PID.

{
    "PID":"nsq-12",
}

Note: Destroy all the proxy used by the PID. Basically, this is not necessary since the proxy can handle this situation.

/api/status see the current status for the proxy connections.

/api/debug-status see the current status for the proxy connections and print the debug info for details.

Graceful restart/upgrade

Kill with signal SIGUSR2 will trigger a graceful restart and this can be used to upgrade the proxy binary without affecting the services.

Configuration for the static proxy

[
{
    "ModuleName":"nsqlookup",
    "ProxyType":"HTTP",
    "LocalProxyAddr":"127.0.0.1:18003",
    "RemoteAddrList":[
        "192.168.66.202:4161"
    ]
}
]

Note: the static proxy configure can be used to start some proxy server without calling the dynamic API.

NSQ lookup HTTP proxy

The proxy can be configured in the static configure file. Currently only lookup is supported on the nsq.The API is the same without proxy. With proxy, all returned nsqd ip:port will be converted to local proxy address. If you do need the orig, you can add query param with "?disableconvert=true", and the cache is enabled by default. By using "?disablecache=true" you can disable the cache.

Documentation

Index

Constants

View Source
const (
	RSP_BUF_SIZE     = 1024
	BUF_MAX_NUM      = 200
	MAX_CONN_NUM     = 100
	SHRINK_THRESHOLD = 10
	SHRINK_NUM       = 2
	CONN_TIMEOUT     = 3
)
View Source
const (
	TMP_PROXY_PARAM_PATH = "/tmp/proxyparams.tmp"
)

Variables

This section is empty.

Functions

func GetUnixDomainPath

func GetUnixDomainPath(param *ProxyParam) string

Types

type LocalProxy

type LocalProxy struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewLocalProxy

func NewLocalProxy() *LocalProxy

func (*LocalProxy) GetProxy

func (self *LocalProxy) GetProxy(pid, protocol, remote, initData string) (string, error)

func (*LocalProxy) HandleCloseProxyConn

func (self *LocalProxy) HandleCloseProxyConn(w http.ResponseWriter, r *http.Request)

proxy client could call the close to avoid the connection data mismatch. If any timeout or error on the client the connection should be closed. If the client finished normally, the client can just close the socket and the connection

on the remote will be reused.

func (*LocalProxy) HandleDebugStatus

func (self *LocalProxy) HandleDebugStatus(w http.ResponseWriter, r *http.Request)

func (*LocalProxy) HandleDestroyAll

func (self *LocalProxy) HandleDestroyAll(w http.ResponseWriter, r *http.Request)

func (*LocalProxy) HandleDestroyProxyConn

func (self *LocalProxy) HandleDestroyProxyConn(w http.ResponseWriter, r *http.Request)

If the remote will be not used anymore, the local listener can be deleted.

func (*LocalProxy) HandleGetProxyConn

func (self *LocalProxy) HandleGetProxyConn(w http.ResponseWriter, r *http.Request)

func (*LocalProxy) HandleSetLogLevel

func (self *LocalProxy) HandleSetLogLevel(w http.ResponseWriter, r *http.Request)

func (*LocalProxy) HandleStatus

func (self *LocalProxy) HandleStatus(w http.ResponseWriter, r *http.Request)

func (*LocalProxy) Restart

func (self *LocalProxy) Restart()

func (*LocalProxy) StartInheritedProxy

func (self *LocalProxy) StartInheritedProxy() error

func (*LocalProxy) StartLocalProxy

func (self *LocalProxy) StartLocalProxy(port uint16) error

func (*LocalProxy) Stop

func (self *LocalProxy) Stop()

type ProxyConnData

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

func NewProxyConnData

func NewProxyConnData(c *net.TCPConn) *ProxyConnData

func (*ProxyConnData) Close

func (self *ProxyConnData) Close()

type ProxyListenerData

type ProxyListenerData struct {
	ProxyParam
	LastUsed  time.Time
	AutoClean bool
}

type ProxyManager

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

func NewProxyManager

func NewProxyManager(c []common.ProxyConf) *ProxyManager

func (*ProxyManager) StartAll

func (self *ProxyManager) StartAll(lp *LocalProxy) error

func (*ProxyManager) StopAll

func (self *ProxyManager) StopAll()

type ProxyParam

type ProxyParam struct {
	PID        string
	RemoteAddr string
	Protocol   string
	ProxyAddr  string

	InitSendData string
}

type TCPConnPool

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

func NewTCPConnPool

func NewTCPConnPool(userspbuf bool, pid, address string, p *util.FixedBufferPool) *TCPConnPool

if use response buffer, the pool will manager the read from remote and the client should read from the buffer. Otherwise, the client can read from remote directly.

func (*TCPConnPool) AcquireConn

func (self *TCPConnPool) AcquireConn() (bool, *ProxyConnData, error)

func (*TCPConnPool) CleanPool

func (self *TCPConnPool) CleanPool()

func (*TCPConnPool) DestroyRemoteConn

func (self *TCPConnPool) DestroyRemoteConn(proxyconn *ProxyConnData)

func (*TCPConnPool) IsEmpty

func (self *TCPConnPool) IsEmpty() bool

func (*TCPConnPool) IsUnusedSince

func (self *TCPConnPool) IsUnusedSince(t time.Time) bool

func (*TCPConnPool) ReleaseConn

func (self *TCPConnPool) ReleaseConn(p *ProxyConnData)

func (*TCPConnPool) ShrinkPool

func (self *TCPConnPool) ShrinkPool()

func (*TCPConnPool) StatusString

func (self *TCPConnPool) StatusString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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