Documentation ¶
Index ¶
- Constants
- Variables
- func HttpRequestHeader(buffer *bytes.Buffer, req *http.Request)
- func HttpRespHeader(buffer *bytes.Buffer, resp *http.Response)
- func NegVersionServer(ctx context.Context, wsConn *websocket.Conn, enableStatusPage bool) error
- func NewWebSocketWriter(wsc *ConcurrentWebSocket, id ksuid.KSUID, ctx context.Context) *webSocketWriter
- func NewWebSocketWriterWithMutex(wsc *ConcurrentWebSocket, id ksuid.KSUID, ctx context.Context) *webSocketWriter
- func ProxyTypeStr(tp int) string
- type Base64WSBufferWriter
- type BufferedWR
- type ChanDone
- type Client
- type ClientData
- type ConcurrentWebSocket
- type ConcurrentWebSocketInterface
- type ConnRecord
- type ConnStatus
- type Connector
- type DefaultProxyEst
- type HeartBeat
- type HttpClient
- type HttpProxyEst
- type HttpsClient
- type Hub
- type HubCollection
- type ProxyClient
- type ProxyData
- type ProxyEstMessage
- type ProxyEstablish
- type ProxyInterface
- type ProxyRegister
- type ProxyServer
- type ServerData
- type ServerWS
- type Socks5Client
- type VersionNeg
- type WebSocketClient
- func (wsc *WebSocketClient) Close() error
- func (wsc *WebSocketClient) ConnSize() int
- func (wsc *WebSocketClient) GetProxyById(id ksuid.KSUID) *ProxyClient
- func (wsc *WebSocketClient) ListenIncomeMsg(readLimit int64) error
- func (wsc *WebSocketClient) NewProxy(onData func(ksuid.KSUID, ServerData), onClosed func(ksuid.KSUID, bool), ...) *ProxyClient
- func (wsc *WebSocketClient) RemoveProxy(id ksuid.KSUID)
- func (wsc *WebSocketClient) TellClose(id ksuid.KSUID) error
- type WebSocketMessage
- type WebsocksServerConfig
Constants ¶
const ( TagData = iota TagEstOk TagEstErr TagNoMore )
const ( ProxyTypeSocks5 = iota ProxyTypeHttp ProxyTypeHttps )
const ( WsTpVer = "version" WsTpBeats = "heart_beat" WsTpClose = "finish" WsTpData = "data" WsTpEst = "est" // establish )
const CompVersion = 0x003
const CoreVersion = "0.6.1"
const VersionCode = 0x004
version of protocol.
Variables ¶
var ConnCloseByClient = errors.New("conn closed by client")
var StoppedError = errors.New("listener stopped")
Functions ¶
func HttpRequestHeader ¶ added in v0.3.0
func HttpRespHeader ¶ added in v0.3.0
func NegVersionServer ¶
send version information to client from server
func NewWebSocketWriter ¶ added in v0.5.0
func NewWebSocketWriter(wsc *ConcurrentWebSocket, id ksuid.KSUID, ctx context.Context) *webSocketWriter
func NewWebSocketWriterWithMutex ¶ added in v0.5.0
func NewWebSocketWriterWithMutex(wsc *ConcurrentWebSocket, id ksuid.KSUID, ctx context.Context) *webSocketWriter
func ProxyTypeStr ¶ added in v0.3.0
Types ¶
type Base64WSBufferWriter ¶
type Base64WSBufferWriter struct {
// contains filtered or unexported fields
}
write data to WebSocket server or client
func (*Base64WSBufferWriter) Flush ¶
func (b *Base64WSBufferWriter) Flush(messageType int, id ksuid.KSUID, cws ConcurrentWebSocketInterface) (int, error)
flush all data in this buff into WebSocket.
type BufferedWR ¶ added in v0.3.0
type BufferedWR struct {
// contains filtered or unexported fields
}
func NewBufferWR ¶ added in v0.3.0
func NewBufferWR() *BufferedWR
func (*BufferedWR) Close ¶ added in v0.3.0
func (h *BufferedWR) Close() error
type ChanDone ¶ added in v0.5.0
type ChanDone struct {
// contains filtered or unexported fields
}
data type used in DefaultProxyEst to pass data to channel
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
client part of wssocks
func (*Client) Close ¶ added in v0.3.1
Close stops listening on the TCP address, But the active links are not closed and wait them to finish.
func (*Client) ListenAndServe ¶ added in v0.3.1
func (client *Client) ListenAndServe(record *ConnRecord, wsc *WebSocketClient, address string, enableHttp bool, onConnected func()) error
listen on local address:port and forward socks5 requests to wssocks server.
type ClientData ¶ added in v0.3.0
type ClientData ServerData
type ConcurrentWebSocket ¶
add lock to websocket connection to make sure only one goroutine can write this websocket.
func (*ConcurrentWebSocket) WSClose ¶
func (wsc *ConcurrentWebSocket) WSClose() error
close websocket connection
func (*ConcurrentWebSocket) WriteProxyMessage ¶
func (wsc *ConcurrentWebSocket) WriteProxyMessage(ctx context.Context, id ksuid.KSUID, tag int, data []byte) error
write message to websocket, the data is fixed format @ProxyData id: connection id data: data to be written
type ConnRecord ¶ added in v0.3.1
type ConnRecord struct { ConnSize uint // total size of current connections Addresses map[string]uint // current connections as well as its count Writer *io.Writer // terminal writer todo defer Flush OnChange func(status ConnStatus) Mutex *sync.Mutex }
struct record the connection size of each target host
func NewConnRecord ¶ added in v0.3.1
func NewConnRecord() *ConnRecord
func (*ConnRecord) Update ¶ added in v0.3.1
func (cr *ConnRecord) Update(status ConnStatus)
type ConnStatus ¶ added in v0.3.1
connection status when a connection is added or removed.
type Connector ¶
type Connector struct {
Conn io.ReadWriteCloser
}
type DefaultProxyEst ¶ added in v0.5.0
type DefaultProxyEst struct {
// contains filtered or unexported fields
}
interface implementation for socks5 and https proxy.
func (*DefaultProxyEst) Close ¶ added in v0.5.0
func (e *DefaultProxyEst) Close(tell bool) error
type HeartBeat ¶ added in v0.3.1
type HeartBeat struct {
// contains filtered or unexported fields
}
func NewHeartBeat ¶ added in v0.3.1
func NewHeartBeat(wsc *WebSocketClient) (*HeartBeat, context.Context)
type HttpClient ¶ added in v0.3.0
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpProxy ¶ added in v0.3.0
func NewHttpProxy(wsc *WebSocketClient, cr *ConnRecord) HttpClient
func (*HttpClient) ProxyType ¶ added in v0.3.0
func (client *HttpClient) ProxyType() int
func (*HttpClient) ServeHTTP ¶ added in v0.3.0
func (client *HttpClient) ServeHTTP(w http.ResponseWriter, req *http.Request)
type HttpProxyEst ¶ added in v0.5.0
type HttpProxyEst struct {
// contains filtered or unexported fields
}
func (*HttpProxyEst) Close ¶ added in v0.5.0
func (h *HttpProxyEst) Close(tell bool) error
type HttpsClient ¶ added in v0.3.0
type HttpsClient struct { }
func (*HttpsClient) EstablishData ¶ added in v0.3.0
func (client *HttpsClient) EstablishData(origin []byte) ([]byte, error)
func (*HttpsClient) ParseHeader ¶ added in v0.3.0
parsing https header, and return address and parsing error
func (*HttpsClient) ProxyType ¶ added in v0.3.0
func (client *HttpsClient) ProxyType() int
func (*HttpsClient) Trigger ¶ added in v0.3.0
func (client *HttpsClient) Trigger(data []byte) bool
type Hub ¶ added in v0.5.0
type Hub struct { ConcurrentWebSocket // contains filtered or unexported fields }
Hub maintains the set of active proxy clients in server side for a user
func (*Hub) CloseProxyConn ¶ added in v0.5.0
Close proxy connection with remote host. It can be called when receiving tell close message from client
func (*Hub) GetConnectorSize ¶ added in v0.5.0
return the proxies handled by this hub/websocket connetion
func (*Hub) GetProxyById ¶ added in v0.5.0
func (h *Hub) GetProxyById(id ksuid.KSUID) *ProxyServer
func (*Hub) RemoveProxy ¶ added in v0.5.0
type HubCollection ¶ added in v0.5.0
type HubCollection struct {
// contains filtered or unexported fields
}
HubCollection is a set of hubs. It handle several hubs. Each hub can map to a websocket connection, which also handle several proxies instance.
func NewHubCollection ¶ added in v0.5.0
func NewHubCollection() *HubCollection
func (*HubCollection) GetConnCount ¶ added in v0.5.0
func (hc *HubCollection) GetConnCount() (int, int)
count the client size and proxy connection size.
func (*HubCollection) NewHub ¶ added in v0.5.0
func (hc *HubCollection) NewHub(conn *websocket.Conn) *Hub
create a hub and add it to hub collection
func (*HubCollection) RemoveProxy ¶ added in v0.5.0
func (hc *HubCollection) RemoveProxy(id ksuid.KSUID)
remove a hub specified by its id.
type ProxyClient ¶
proxy client handle one connection, send data to proxy server vai websocket.
func (*ProxyClient) Establish ¶ added in v0.3.0
func (p *ProxyClient) Establish(wsc *WebSocketClient, firstSendData []byte, proxyType int, addr string) error
tell wssocks proxy server to establish a proxy connection by sending server proxy address, type, initial data.
type ProxyEstMessage ¶
type ProxyEstMessage struct { Type int `json:"proxy_type"` Addr string `json:"addr"` WithData bool `json:"with_data"` DataBase64 string `json:"base64"` // establish with initialized data. }
Proxy message for establishing connection
type ProxyEstablish ¶ added in v0.5.0
type ProxyEstablish interface { // close connection // tell: whether to send close message to proxy client Close(tell bool) error // contains filtered or unexported methods }
interface of establishing proxy connection with target
type ProxyInterface ¶ added in v0.3.0
type ProxyInterface interface { ProxyType() int // return a bool value to indicate whether it is the matched protocol. Trigger(data []byte) bool // parse protocol header bytes, return target host. ParseHeader(conn net.Conn, header []byte) (string, error) // return data transformed in connection establishing step. EstablishData(origin []byte) ([]byte, error) }
interface of proxy client, supported types: http/https/socks5
type ProxyRegister ¶ added in v0.5.0
type ProxyRegister struct {
// contains filtered or unexported fields
}
type ProxyServer ¶ added in v0.3.0
type ProxyServer struct { Id ksuid.KSUID // id of proxy connection ProxyIns ProxyEstablish }
type ServerData ¶ added in v0.3.0
type ServerWS ¶
type ServerWS struct {
// contains filtered or unexported fields
}
func NewServeWS ¶ added in v0.5.0
func NewServeWS(hc *HubCollection, config WebsocksServerConfig) *ServerWS
return a a function handling websocket requests from the peer.
type Socks5Client ¶ added in v0.3.0
type Socks5Client struct { }
func (*Socks5Client) EstablishData ¶ added in v0.3.0
func (client *Socks5Client) EstablishData(origin []byte) ([]byte, error)
func (*Socks5Client) ParseHeader ¶ added in v0.3.0
parsing socks5 header, and return address and parsing error
func (*Socks5Client) ProxyType ¶ added in v0.3.0
func (client *Socks5Client) ProxyType() int
func (*Socks5Client) Trigger ¶ added in v0.3.0
func (client *Socks5Client) Trigger(data []byte) bool
type VersionNeg ¶
type VersionNeg struct { Version string `json:"version"` CompVersion uint `json:"comp_version"` // Compatible version code VersionCode uint `json:"version_code"` EnableStatusPage bool `json:"status_page"` }
func ExchangeVersion ¶
negotiate client and server version after websocket connection is established, client can receive a message from server with server version number.
type WebSocketClient ¶
type WebSocketClient struct { ConcurrentWebSocket // contains filtered or unexported fields }
WebSocketClient is a collection of proxy clients. It can add/remove proxy clients from this collection, and dispatch web socket message to a specific proxy client.
func NewWebSocketClient ¶
func NewWebSocketClient(ctx context.Context, addr string, hc *http.Client, header http.Header) (*WebSocketClient, error)
Establish websocket connection. And initialize proxies container.
func (*WebSocketClient) Close ¶
func (wsc *WebSocketClient) Close() error
func (*WebSocketClient) ConnSize ¶
func (wsc *WebSocketClient) ConnSize() int
get the connection size
func (*WebSocketClient) GetProxyById ¶
func (wsc *WebSocketClient) GetProxyById(id ksuid.KSUID) *ProxyClient
func (*WebSocketClient) ListenIncomeMsg ¶
func (wsc *WebSocketClient) ListenIncomeMsg(readLimit int64) error
listen income websocket messages and dispatch to different proxies.
func (*WebSocketClient) NewProxy ¶
func (wsc *WebSocketClient) NewProxy(onData func(ksuid.KSUID, ServerData), onClosed func(ksuid.KSUID, bool), onError func(ksuid.KSUID, error)) *ProxyClient
create a new proxy with unique id
func (*WebSocketClient) RemoveProxy ¶ added in v0.3.0
func (wsc *WebSocketClient) RemoveProxy(id ksuid.KSUID)
remove current proxy by id
type WebSocketMessage ¶
Source Files ¶
- buffered_reader_writer.go
- concurrent_websocket.go
- conn_records.go
- heart_beat.go
- http_utils.go
- hub.go
- hub_collection.go
- proxy_client.go
- proxy_client_http.go
- proxy_client_https.go
- proxy_client_interface.go
- proxy_client_socks5.go
- proxy_server.go
- version.go
- websocket_client.go
- ws_datatypes.go
- wssocks_client.go
- wssocks_server.go