cs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//CmdConnDial is cs protocol command for dial connection
	CmdConnDial = 0x10
	//CmdConnBack is cs protocol command for dial connection back
	CmdConnBack = 0x20
	//CmdConnData is cs protocol command for transfer data
	CmdConnData = 0x30
	//CmdConnClose is cs protocol command for connection close
	CmdConnClose = 0x40
)
View Source
const (
	//LogLevelDebug is debug log level
	LogLevelDebug = 40
	//LogLevelInfo is info log level
	LogLevelInfo = 30
	//LogLevelWarn is warn log level
	LogLevelWarn = 20
	//LogLevelError is error log level
	LogLevelError = 10
)
View Source
const (
	//DefaultBufferSize is default buffer size
	DefaultBufferSize = 64 * 1024
)

Variables

View Source
var BasePipe = os.Pipe

BasePipe is func to create os pipe

Functions

func DebugLog

func DebugLog(format string, args ...interface{})

DebugLog is the debug level log

func ErrorLog

func ErrorLog(format string, args ...interface{})

ErrorLog is the error level log

func InfoLog

func InfoLog(format string, args ...interface{})

InfoLog is the info level log

func Now

func Now() int64

Now get current timestamp

func ReadJSON

func ReadJSON(filename string, v interface{}) (err error)

ReadJSON will read file and unmarshal to value

func SHA1

func SHA1(data []byte) string

SHA1 will get sha1 hash of data

func SetLogLevel

func SetLogLevel(l int)

SetLogLevel is set log level to l

func WarnLog

func WarnLog(format string, args ...interface{})

WarnLog is the warn level log

func WriteJSON

func WriteJSON(filename string, v interface{}) (err error)

WriteJSON will marshal value to json and write to file

Types

type BaseConn

type BaseConn struct {
	Err error
	// contains filtered or unexported fields
}

BaseConn imple read/write raw connection by command mode

func NewBaseConn

func NewBaseConn(raw io.ReadWriter, bufferSize int) (conn *BaseConn)

NewBaseConn will create new Conn by raw reader/writer and buffer size

func (*BaseConn) Close

func (b *BaseConn) Close() (err error)

Close will check raw if io.Closer and close it

func (*BaseConn) ID

func (b *BaseConn) ID() uint64

ID will reture connection id

func (*BaseConn) PreErr

func (b *BaseConn) PreErr() (err error)

PreErr will get prefix error

func (*BaseConn) ReadCmd

func (b *BaseConn) ReadCmd() (cmd []byte, err error)

ReadCmd will read raw reader as command mode. the commad protocol is:lenght(4 byte)+data

func (*BaseConn) SetErr

func (b *BaseConn) SetErr(err error)

SetErr will mark error

func (*BaseConn) String

func (b *BaseConn) String() string

func (*BaseConn) WriteCmd

func (b *BaseConn) WriteCmd(cmd []byte) (w int, err error)

WriteCmd will write data by command mode

type Client

type Client struct {
	BufferSize int
	Dialer     Dialer
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client is normal client for implement dark socket protocl

func NewClient

func NewClient(bufferSize int, dialer Dialer) (client *Client)

NewClient will create client by buffer size and dialer

func (*Client) Close

func (c *Client) Close() (err error)

Close will close all proc connection

func (*Client) HTTPGet

func (c *Client) HTTPGet(uri string) (data []byte, err error)

HTTPGet will do http get request by proxy

func (*Client) ProcConn

func (c *Client) ProcConn(raw io.ReadWriteCloser, target string) (err error)

ProcConn will start process proxy connection

type Conn

type Conn interface {
	ID() uint64
	ReadCmd() (cmd []byte, err error)
	WriteCmd(cmd []byte) (w int, err error)
	Close() (err error)
	SetErr(err error)
	PreErr() (err error)
}

Conn is interface for read/write raw connection by command mode

type Dialer

type Dialer interface {
	Dial(remote string) (raw io.ReadWriteCloser, err error)
}

Dialer is interface for dial raw connect by string

type DialerF

type DialerF func(remote string) (raw io.ReadWriteCloser, err error)

DialerF is an the implementation of Dialer by func

func (DialerF) Dial

func (d DialerF) Dial(remote string) (raw io.ReadWriteCloser, err error)

Dial dial to remote by func

type JSONFileAuth

type JSONFileAuth struct {
	FileName string
	// contains filtered or unexported fields
}

JSONFileAuth is the basic auth impl

func NewJSONFileAuth

func NewJSONFileAuth(adimUser map[string]string, filename string) (auth *JSONFileAuth)

NewJSONFileAuth return new JSONFileAuth, it will read the users from json file

func (*JSONFileAuth) AddUser

func (j *JSONFileAuth) AddUser(res http.ResponseWriter, req *http.Request)

AddUser will add user to json file

func (*JSONFileAuth) BasicAuth

func (j *JSONFileAuth) BasicAuth(req *http.Request) (ok bool, err error)

BasicAuth will auth by http basic auth

func (*JSONFileAuth) ListUser

func (j *JSONFileAuth) ListUser(res http.ResponseWriter, req *http.Request)

ListUser will list user as html page

func (*JSONFileAuth) RemoveUser

func (j *JSONFileAuth) RemoveUser(res http.ResponseWriter, req *http.Request)

RemoveUser will remove user to json file

type NetDialer

type NetDialer string

NetDialer is an implementation of Dialer by net

func (NetDialer) Dial

func (t NetDialer) Dial(remote string) (raw io.ReadWriteCloser, err error)

Dial dial to remote by net

type PipedConn

type PipedConn struct {
	io.Reader

	io.Writer

	Alias string
	// contains filtered or unexported fields
}

PipedConn is connection piped read and write

func CreatePipeConn

func CreatePipeConn() (a, b *PipedConn, err error)

CreatePipeConn will create pipe connection

func (*PipedConn) Close

func (p *PipedConn) Close() (err error)

Close will close Reaer/Writer

func (*PipedConn) LocalAddr

func (p *PipedConn) LocalAddr() net.Addr

LocalAddr is net.Conn impl

func (*PipedConn) Network

func (p *PipedConn) Network() string

Network is net.Addr impl

func (*PipedConn) RemoteAddr

func (p *PipedConn) RemoteAddr() net.Addr

RemoteAddr is net.Conn impl

func (*PipedConn) SetDeadline

func (p *PipedConn) SetDeadline(t time.Time) error

SetDeadline is net.Conn impl

func (*PipedConn) SetReadDeadline

func (p *PipedConn) SetReadDeadline(t time.Time) error

SetReadDeadline is net.Conn impl

func (*PipedConn) SetWriteDeadline

func (p *PipedConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline is net.Conn impl

func (*PipedConn) String

func (p *PipedConn) String() string

type Server

type Server struct {
	BufferSize int
	Dialer     Dialer
}

Server is the main implementation for dark socks

func NewServer

func NewServer(bufferSize int, dialer Dialer) (server *Server)

NewServer will create Server by buffer size and dialer

func (*Server) ProcConn

func (s *Server) ProcConn(conn Conn) (err error)

ProcConn will start process proxy connection

type SocksProxy

type SocksProxy struct {
	net.Listener
	Dialer       func(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
	HTTPUpstream string
}

SocksProxy is an implementation of socks5 proxy

func NewSocksProxy

func NewSocksProxy() (socks *SocksProxy)

NewSocksProxy will return new SocksProxy

func (*SocksProxy) Listen

func (s *SocksProxy) Listen(addr string) (err error)

Listen the address

func (*SocksProxy) Run

func (s *SocksProxy) Run() (err error)

Run proxy listener

type SortedDialer

type SortedDialer struct {
	RateTolerance float32
	SortDelay     int64
	// contains filtered or unexported fields
}

SortedDialer will auto sort the dialer by used time/error rate

func NewSortedDialer

func NewSortedDialer(dialers ...Dialer) (dialer *SortedDialer)

NewSortedDialer will new sorted dialer by sub dialer

func (*SortedDialer) Dial

func (s *SortedDialer) Dial(remote string) (raw io.ReadWriteCloser, err error)

Dial impl the Dialer

func (*SortedDialer) Len

func (s *SortedDialer) Len() int

Len is the number of elements in the collection.

func (*SortedDialer) Less

func (s *SortedDialer) Less(i, j int) (r bool)

Less reports whether the element with index i should sort before the element with index j.

func (*SortedDialer) State

func (s *SortedDialer) State() interface{}

State will return current dialer state

func (*SortedDialer) Swap

func (s *SortedDialer) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type Statable

type Statable interface {
	State() interface{}
}

Statable is interface for load object state

type StringConn

type StringConn struct {
	Name string
	io.ReadWriteCloser
}

StringConn is an ReadWriteCloser for return remote address info

func NewStringConn

func NewStringConn(raw io.ReadWriteCloser) *StringConn

NewStringConn will return new StringConn

func (*StringConn) String

func (s *StringConn) String() string

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
}

TCPKeepAliveListener is normal tcp listner for set tcp connection keep alive

func (TCPKeepAliveListener) Accept

func (ln TCPKeepAliveListener) Accept() (net.Conn, error)

Accept will accept one connection

type WebsocketDialer

type WebsocketDialer string

WebsocketDialer is an implementation of Dialer by websocket

func (WebsocketDialer) Dial

func (w WebsocketDialer) Dial(remote string) (raw io.ReadWriteCloser, err error)

Dial dial to remote by websocket

Jump to

Keyboard shortcuts

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