Documentation ¶
Index ¶
- Constants
- Variables
- func ForwardUDPConn(serverIn net.PacketConn, src net.Addr, payload []byte) error
- func GetRequest(ss net.Conn) (host string, err error)
- func GetUDPRequest(req []byte) (dst string, length int, err error)
- func HmacSha1(key []byte, data []byte) []byte
- func IsFileExists(path string) (bool, error)
- func NewSecureConn(c net.Conn, cipher encrypt.Cipher, timeout int) net.Conn
- func NewSecurePacketConn(c net.PacketConn, cipher encrypt.Cipher, timeout int) net.PacketConn
- func PipeThenClose(src, dst NetConnection, done func())
- func PipeThenCloseFromUDP(src net.PacketConn, dst net.Conn, timeout int)
- func PipeUDPThenClose(src net.Conn, dst net.PacketConn, dstaddr string, timeout int)
- func PrintVersion()
- func SecureListen(network, laddr string, cipher encrypt.Cipher, timeout int) (net.Listener, error)
- func SecureListenPacket(network, laddr string, cipher encrypt.Cipher, timeout int) (net.PacketConn, error)
- func SetLogger()
- func UDPGetRequest(buf []byte) (host string, headerLen int, err error)
- type BackwardInfo
- type ConfOption
- func WithDNSServer(server string) ConfOption
- func WithEncryptMethod(method string) ConfOption
- func WithLocalAddr(addr string) ConfOption
- func WithLocalPort(port string) ConfOption
- func WithMultiServerMode(mode string) ConfOption
- func WithPassword(pwd string) ConfOption
- func WithRemoteServer(server, method, passwd string) ConfOption
- func WithServer(server string) ConfOption
- func WithServerPort(port string) ConfOption
- func WithTimeOut(t int) ConfOption
- type Config
- type Dialer
- func (d *Dialer) Dial(network, addr string) (c net.Conn, err error)
- func (d *Dialer) DialUDP(network, laddr, raddr string) (c net.PacketConn, err error)
- func (d *Dialer) DialWithRawAddr(rawaddr []byte) (conn net.Conn, err error)
- func (d *Dialer) ListenPacket(network, laddr string) (c net.PacketConn, err error)
- type NatPacketUnit
- type NatTable
- type NetConnection
- type SecureConn
- type SecurePacketConn
- type ServerEntry
Constants ¶
const ( // AddrMask is used to mask the AddrType AddrMask byte = 0xf )
Variables ¶
var ( // Logger used to out put the log, zap logger is fast and efficiency Logger *zap.Logger // Level can be set into Debug Info Error, and Error level is used by default Level string )
var ( ErrPacketTooSmall = errors.New("[udp]read error: cannot decrypt, received packet is smaller than ivLen") ErrBufferTooSmall = errors.New("[udp]read error: given buffer is too small to hold data") ErrInvalidHostname = errors.New("error invalid hostname") ErrInvalidPacket = errors.New("invalid message received") ErrInvalidServerAddress = errors.New("invalid server ip address, can not be parsed") ErrNilPasswd = errors.New("password should NOT be nil") ErrParesConfigfile = errors.New("can not parse the config fire") ErrNilCipher = errors.New("cipher should NOT be nil") ErrInvalidCipher = errors.New("cipher method invalid or not supported") ErrUnexpectedIO = errors.New("error in IO, expect more data than we get") ErrInvalidConfig = errors.New("error in config check, config fields invalid") )
var (
BufferSize = 0x1FFFF // BufferSize define pool size for buffer. By default, 32K will give for each buffer
)
var UDPBufferPool = sync.Pool{ New: func() interface{} { return make([]byte, UDPMaxSize) }, }
var (
//reqList = newReqList()
UDPMaxSize = 65536
)
Functions ¶
func ForwardUDPConn ¶
ForwardUDPConn forwards the payload (should with header) to the dst with UDP. meanwhile, the request header is cached and the connection is else cached for further use.
func GetRequest ¶
GetRequest can handler the ss request header and decryption for ss protocol
func GetUDPRequest ¶
GetUDPRequest can handler the ss request header and decryption for ss protocol
func IsFileExists ¶
IsFileExists returns true if the file exists
func NewSecureConn ¶
NewSecureConn creates a SecureConn with given cipher and timeout by warp the net.Conn
func NewSecurePacketConn ¶
func NewSecurePacketConn(c net.PacketConn, cipher encrypt.Cipher, timeout int) net.PacketConn
NewSecurePacketConn creates a secured PacketConn
func PipeThenClose ¶
func PipeThenClose(src, dst NetConnection, done func())
PipeThenClose copies data from src to dst, close dst when done.
func PipeThenCloseFromUDP ¶
func PipeThenCloseFromUDP(src net.PacketConn, dst net.Conn, timeout int)
PipeThenCloseFromUDP will copy data from UDP connection to tcp connection
func PipeUDPThenClose ¶
PipeUDPThenClose will copy data to UDP connection
func SecureListen ¶
Listen announces on the TCP address laddr and returns a TCP listener. Net must be "tcp", "tcp4", or "tcp6". If laddr has a port of 0, ListenTCP will choose an available port. The caller can use the Addr method of TCPListener to retrieve the chosen address.
func SecureListenPacket ¶
func SecureListenPacket(network, laddr string, cipher encrypt.Cipher, timeout int) (net.PacketConn, error)
ListenPacket is like net.ListenPacket() but returns an secured connection
func SetLogger ¶
func SetLogger()
SetLogger will generate a zap logger with given level for log output
Types ¶
type BackwardInfo ¶
type BackwardInfo struct {
// contains filtered or unexported fields
}
BackwardInfo is defined for the backword packet to the src address
type ConfOption ¶
type ConfOption func(c *Config)
ConfOption define the config options
func WithDNSServer ¶
func WithDNSServer(server string) ConfOption
WithDNSServer set the DNS server address
func WithEncryptMethod ¶
func WithEncryptMethod(method string) ConfOption
WithEncryptMethod set the encrypt method
func WithLocalAddr ¶
func WithLocalAddr(addr string) ConfOption
WithLocalAddr set the local socks5 address
func WithLocalPort ¶
func WithLocalPort(port string) ConfOption
WithLocalPort set the local socks5 port
func WithMultiServerMode ¶
func WithMultiServerMode(mode string) ConfOption
WithMultiServerMode choose the mode about multiserver
func WithPassword ¶
func WithPassword(pwd string) ConfOption
WithPassword set the password for server
func WithRemoteServer ¶
func WithRemoteServer(server, method, passwd string) ConfOption
WithRemoteServer add a remote server entry into serverlist
func WithServerPort ¶
func WithServerPort(port string) ConfOption
WithServerPort set the server port for server
type Config ¶
type Config struct { Server string `json:"server_addr"` // shadowsocks remote Server address ServerPort string `json:"server_port"` // shadowsocks remote Server port Local string `json:"local_addr"` // shadowsocks local socks5 Server address LocalPort string `json:"local_port"` // shadowsocks local socks5 Server port Password string `json:"password"` // shadowsocks encrypt password Method string `json:"method"` // shadowsocks encryption method TunnelPort string `json:"tunnel_port"` // shadowsocks tunnel port local, this will enable tunnel mode only tunnel remote port setted TunnelRemotePort string `json:"tunnel_remote_port"` // shadowsocks tunnel remote port for tunnel access TunnelDest string `json:"tunnel_destination"` // shadowsocks tunnel remote address for ss-remote to access MultiServerMode string `json:"multi_server_mode"` // shadowsocks client multi-server access mode: fastest,round-robin,dissable DNSServer string `json:"dns_server"` // shadowsocks remote Server DNS server option, the system DNS will be uesd for domain lookup by defalut Timeout int `json:"timeout"` // shadowsocks connection timeout ServerList []ServerEntry `json:"server_list"` // shadowsocks server list keep a list of remote ss-server information }
Config implement the ss config
func NewConfig ¶
func NewConfig(opts ...ConfOption) (*Config, error)
NewConfig use the option to generate the ss config
func ParseConfig ¶
ParseConfig parses a config file
func (*Config) Detect ¶
func (c *Config) Detect()
Detect used only when multi tcp based ss server is setted for the client Detect will try to dial each server to caculate a delay and sort server
func (*Config) GetServer ¶
func (c *Config) GetServer() ServerEntry
func (*Config) GetServerRoundRobin ¶
func (c *Config) GetServerRoundRobin() ServerEntry
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer provides client side connection support and also implements the Dialer interface described in golang.org/x/net/proxy
func NewDialer ¶
NewDialer initializes a new Dialer
func (*Dialer) Dial ¶
Dial is intended for the Dialer interface described in golang.org/x/net/proxy
func (*Dialer) DialUDP ¶
func (d *Dialer) DialUDP(network, laddr, raddr string) (c net.PacketConn, err error)
DialUDP is used to open an UDP connection on client side to and remote dst
func (*Dialer) DialWithRawAddr ¶
DialWithRawAddr is intended for use by users implementing a local socks proxy. rawaddr shoud contain part of the data in socks request, starting from the ATYP field. (Refer to rfc1928 for more information.)
type NatPacketUnit ¶
type NatPacketUnit struct { net.PacketConn // contains filtered or unexported fields }
type NatTable ¶
NatTable used to map the incomming packet to the outgoing packet listener
func (*NatTable) Delete ¶
Delete deletes an item from the table can be called parallel
type NetConnection ¶
NetConnection inmlements the net.Conn & net.TcpConn with Shutdown liked function
type SecureConn ¶
SecureConn is a secured connection with shadowsocks protocol also implements net.Conn interface
func (*SecureConn) Close ¶
func (c *SecureConn) Close() error
Close closes the connection and free the buffer
func (*SecureConn) CloseRead ¶
func (c *SecureConn) CloseRead() error
CloseRead closes the connection on read half
func (*SecureConn) CloseWrite ¶
func (c *SecureConn) CloseWrite() error
CloseWrite closes the connection on write half
func (*SecureConn) Read ¶
func (c *SecureConn) Read(b []byte) (n int, err error)
Read read the data from connection and decrypted with given cipher. the data may be cached and return with ErrAgain, that means more data is wantted for decryption
SecureConn Read will take best affort to read the data and decrypt no matter what cipher it is. The aead cipher data stream was encrypted data block which with the definitely length. So the cipher has a cache inside for tcp stream data caching, and then return the data bolck read from stream if the length is enough.
There get a second data cache here which caching the decrypted data in case the len of buffer is less than the data we decrypted. The remain data will append in the front of buffer for return when next read comes.
func (*SecureConn) Write ¶
func (c *SecureConn) Write(b []byte) (n int, err error)
type SecurePacketConn ¶
type SecurePacketConn struct { net.PacketConn encrypt.Cipher // contains filtered or unexported fields }
SecurePacketConn is the implementation of net.PacketConn interfaces for shadowsocks UDP network connections.
func (*SecurePacketConn) ReadFrom ¶
ReadFrom reads a packet from the connection.