shadowsocks

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 18 Imported by: 3

README

ShadowSocks

ShadowSocks server and client

Build Go Report Card GoDoc GitHub license gocover.io

This project is to add protocol support for the Bridge, or it can be used alone

The following is the implementation of other proxy protocols

Usage

API Documentation

Example

Features

  • Support TCP proxy
  • Support UDP proxy

Supported ciphers

  • AEAD
    • aes-128-gcm
    • aes-192-gcm
    • aes-256-gcm
    • chacha20-ietf-poly1305
    • xchacha20-poly1305
  • Stream
    • aes-128-cfb
    • aes-192-cfb
    • aes-256-cfb
    • aes-128-ctr
    • aes-192-ctr
    • aes-256-ctr
    • des-cfb
    • bf-cfb
    • cast5-cfb
    • rc4-md5
    • chacha20
    • chacha20-ietf
    • xchacha20
    • salsa20
  • dummy (no encryption)

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CipherList

func CipherList() []string

func GetCipherAndPasswordFromUserinfo added in v0.2.1

func GetCipherAndPasswordFromUserinfo(user *url.Userinfo) (cipher, password string, err error)

func IsCipher added in v0.2.1

func IsCipher(method string) bool

func KDF

func KDF(password string, keyLen int) []byte

key-derivation function from original Shadowsocks

func RegisterCipher

func RegisterCipher(method string, fun func(password string) (ConnCipher, error))

Types

type BytesPool

type BytesPool interface {
	Get() []byte
	Put([]byte)
}

BytesPool is an interface for getting and returning temporary bytes for use by io.CopyBuffer.

type ConnCipher

type ConnCipher interface {
	StreamConn(net.Conn) net.Conn
	Decrypt(dist, src []byte) (n int, err error)
	Encrypt(dist, src []byte) (n int, err error)
}

func NewCipher

func NewCipher(method, password string) (c ConnCipher, err error)

NewCipher creates a cipher that can be used in Dial()

type Dialer

type Dialer struct {
	// ProxyNetwork network between a proxy server and a client
	ProxyNetwork string
	// ProxyAddress proxy server address
	ProxyAddress string
	// ProxyDial specifies the optional dial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)
	// Cipher use cipher protocol
	Cipher string
	// Password use password authentication
	Password string
	// ConnCipher is connect the cipher codec
	ConnCipher ConnCipher
	// IsResolve resolve domain name on locally
	IsResolve bool
	// Resolver optionally specifies an alternate resolver to use
	Resolver *net.Resolver
	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. The default is no timeout
	Timeout time.Duration
}

Dialer is a shadowsocks dialer.

func NewDialer

func NewDialer(addr string) (*Dialer, error)

NewDialer returns a new Dialer that dials through the provided proxy server's network and address.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connect to the provided address on the provided network.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connect to the provided address on the provided network.

type ListenPacket added in v0.2.0

type ListenPacket interface {
	ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
}

type Logger added in v0.3.0

type Logger interface {
	Println(v ...interface{})
}

type PacketClient added in v0.2.0

type PacketClient struct {
	// ProxyNetwork network between a proxy server and a client
	ProxyNetwork string
	// ProxyAddress proxy server address
	ProxyAddress string
	// ProxyPacket specifies the optional dial function for
	// establishing the transport connection.
	ProxyPacket func(ctx context.Context, network, address string) (net.PacketConn, error)
	// Cipher use cipher protocol
	Cipher string
	// Password use password authentication
	Password string
	// ConnCipher is connect the cipher codec
	ConnCipher ConnCipher
	// IsResolve resolve domain name on locally
	IsResolve bool
	// Resolver optionally specifies an alternate resolver to use
	Resolver *net.Resolver
	// BytesPool getting and returning temporary bytes
	BytesPool BytesPool
}

func NewPacketClient added in v0.2.0

func NewPacketClient(addr string) (*PacketClient, error)

func (*PacketClient) ListenPacket added in v0.2.0

func (l *PacketClient) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)

type PacketServer added in v0.2.0

type PacketServer struct {
	// ProxyNetwork network between a proxy server and a client
	ProxyNetwork string
	// ProxyAddress proxy server address
	ProxyAddress string
	// Context is default context
	Context context.Context
	// ProxyPacket specifies the optional dial function for
	// establishing the transport connection.
	ProxyPacket func(ctx context.Context, network, address string) (net.PacketConn, error)
	// Cipher use cipher protocol
	Cipher string
	// Password use password authentication
	Password string
	// ConnCipher is connect the cipher codec
	ConnCipher ConnCipher
	// IsResolve resolve domain name on locally
	IsResolve bool
	// Resolver optionally specifies an alternate resolver to use
	Resolver *net.Resolver
	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. The default is no timeout
	Timeout time.Duration
	// Logger error log
	Logger Logger
	// BytesPool getting and returning temporary bytes
	BytesPool BytesPool
	// contains filtered or unexported fields
}

func NewPacketServer added in v0.2.0

func NewPacketServer() *PacketServer

func (*PacketServer) ListenAndServe added in v0.2.0

func (p *PacketServer) ListenAndServe(network, addr string) error

ListenAndServe is used to create a listener and serve on it

func (*PacketServer) ServePacket added in v0.2.0

func (p *PacketServer) ServePacket(conn net.PacketConn) error

type Server

type Server struct {
	// ProxyDial specifies the optional proxyDial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)
	// Logger error log
	Logger Logger
	// Context is default context
	Context context.Context
	// Cipher use cipher protocol
	Cipher string
	// Password use password authentication
	Password string
	// ConnCipher is connect the cipher codec
	ConnCipher ConnCipher
	// BytesPool getting and returning temporary bytes for use by io.CopyBuffer
	BytesPool BytesPool
}

Server is accepting connections and handling the details of the shadowsocks protocol

func NewServer

func NewServer() *Server

NewServer creates a new Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(network, addr string) error

ListenAndServe is used to create a listener and serve on it

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve is used to serve connections from a listener

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

ServeConn is used to serve a single connection.

type SimplePacketServer added in v0.2.0

type SimplePacketServer struct {
	PacketServer
	PacketConn net.PacketConn
	Network    string
	Address    string
}

SimplePacketServer is a simplified server, which can be configured as easily as client.

func NewSimplePacketServer added in v0.2.0

func NewSimplePacketServer(addr string) (*SimplePacketServer, error)

NewSimplePacketServer creates a new NewSimplePacketServer

func (*SimplePacketServer) Close added in v0.2.0

func (s *SimplePacketServer) Close() error

Close closes the listener

func (*SimplePacketServer) ProxyURL added in v0.2.0

func (s *SimplePacketServer) ProxyURL() string

ProxyURL returns the URL of the proxy

func (*SimplePacketServer) Run added in v0.2.0

Run the PacketServer

func (*SimplePacketServer) Start added in v0.2.0

func (s *SimplePacketServer) Start(ctx context.Context) error

Start the PacketServer

type SimpleServer added in v0.1.1

type SimpleServer struct {
	Server
	Listener net.Listener
	Network  string
	Address  string
}

SimpleServer is a simplified server, which can be configured as easily as client.

func NewSimpleServer added in v0.1.1

func NewSimpleServer(addr string) (*SimpleServer, error)

NewServer creates a new NewSimpleServer

func (*SimpleServer) Close added in v0.1.1

func (s *SimpleServer) Close() error

Close closes the listener

func (*SimpleServer) ProxyURL added in v0.1.1

func (s *SimpleServer) ProxyURL() string

ProxyURL returns the URL of the proxy

func (*SimpleServer) Run added in v0.1.1

func (s *SimpleServer) Run(ctx context.Context) error

Run the server

func (*SimpleServer) Start added in v0.1.1

func (s *SimpleServer) Start(ctx context.Context) error

Start the server

Jump to

Keyboard shortcuts

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