shadowsocks

package
v0.0.0-...-7446508 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

*

  • Created with IntelliJ IDEA.
  • User: clowwindy
  • Date: 12-11-2
  • Time: 上午10:31
  • To change this template use File | Settings | File Templates.

Provides leaky buffer, based on the example in Effective Go.

Index

Constants

View Source
const (
	AddrMask byte = 0xf
)

Variables

View Source
var ErrNilCipher = errors.New("cipher can't be nil")

Functions

func CheckCipherMethod

func CheckCipherMethod(method string) error

func HmacSha1

func HmacSha1(key []byte, data []byte) []byte

func IsFileExists

func IsFileExists(path string) (bool, error)

func PipeThenClose

func PipeThenClose(src, dst net.Conn, addTraffic func(int))

PipeThenClose copies data from src to dst, closes dst when done.

func Pipeloop

func Pipeloop(write net.PacketConn, writeAddr net.Addr, readClose net.PacketConn, addTraffic func(int))

func PrintVersion

func PrintVersion()

func RawAddr

func RawAddr(addr string) (buf []byte, err error)

func ReadAndHandleUDPReq

func ReadAndHandleUDPReq(c *SecurePacketConn, addTraffic func(int)) error

func SetDebug

func SetDebug(d DebugLog)

func SetReadTimeout

func SetReadTimeout(c net.Conn)

func UpdateConfig

func UpdateConfig(old, new *Config)

Useful for command line to override options specified in config file Debug is not updated.

Types

type Cipher

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

func NewCipher

func NewCipher(method, password string) (c *Cipher, err error)

NewCipher creates a cipher that can be used in Dial() etc. Use cipher.Copy() to create a new cipher with the same method and password to avoid the cost of repeated cipher initialization.

func (*Cipher) Copy

func (c *Cipher) Copy() *Cipher

Copy creates a new cipher at it's initial state.

type ClosedFlag

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

func (*ClosedFlag) IsClosed

func (flag *ClosedFlag) IsClosed() bool

func (*ClosedFlag) SetClosed

func (flag *ClosedFlag) SetClosed()

type Config

type Config struct {
	Server       interface{} `json:"server"`
	ServerPort   int         `json:"server_port"`
	LocalPort    int         `json:"local_port"`
	LocalAddress string      `json:"local_address"`
	Password     string      `json:"password"`
	Method       string      `json:"method"` // encryption method

	// following options are only used by server
	PortPassword map[string]string `json:"port_password"`
	Timeout      int               `json:"timeout"`

	// The order of servers in the client config is significant, so use array
	// instead of map to preserve the order.
	ServerPassword [][]string `json:"server_password"`
}

func ParseConfig

func ParseConfig(path string) (config *Config, err error)

func (*Config) GetServerArray

func (config *Config) GetServerArray() []string

type Conn

type Conn struct {
	net.Conn
	*Cipher
	// contains filtered or unexported fields
}

func Dial

func Dial(addr, server string, cipher *Cipher) (c *Conn, err error)

addr should be in the form of host:port

func DialWithRawAddr

func DialWithRawAddr(rawaddr []byte, server string, cipher *Cipher) (c *Conn, err error)

This 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.)

func NewConn

func NewConn(c net.Conn, cipher *Cipher) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) GetIv

func (c *Conn) GetIv() (iv []byte)

func (*Conn) GetKey

func (c *Conn) GetKey() (key []byte)

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

type DebugLog

type DebugLog bool
var Debug DebugLog

func (DebugLog) Printf

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

func (DebugLog) Println

func (d DebugLog) Println(args ...interface{})

type DecOrEnc

type DecOrEnc int
const (
	Decrypt DecOrEnc = iota
	Encrypt
)

type Dialer

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

func NewDialer

func NewDialer(server string, cipher *Cipher) (dialer *Dialer, err error)

func (*Dialer) Dial

func (d *Dialer) Dial(network, addr string) (c net.Conn, err error)

type LeakyBuf

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

func NewLeakyBuf

func NewLeakyBuf(n, bufSize int) *LeakyBuf

NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each with bufSize bytes.

func (*LeakyBuf) Get

func (lb *LeakyBuf) Get() (b []byte)

Get returns a buffer from the leaky buffer or create a new buffer.

func (*LeakyBuf) Put

func (lb *LeakyBuf) Put(b []byte)

Put add the buffer into the free buffer pool for reuse. Panic if the buffer size is not the same with the leaky buffer's. This is intended to expose error usage of leaky buffer.

type ProxyAddr

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

func (*ProxyAddr) Network

func (a *ProxyAddr) Network() string

func (*ProxyAddr) String

func (a *ProxyAddr) String() string

type ProxyConn

type ProxyConn struct {
	*Conn
	// contains filtered or unexported fields
}

func (*ProxyConn) LocalAddr

func (c *ProxyConn) LocalAddr() net.Addr

func (*ProxyConn) RemoteAddr

func (c *ProxyConn) RemoteAddr() net.Addr

func (*ProxyConn) SetDeadline

func (c *ProxyConn) SetDeadline(t time.Time) error

func (*ProxyConn) SetReadDeadline

func (c *ProxyConn) SetReadDeadline(t time.Time) error

func (*ProxyConn) SetWriteDeadline

func (c *ProxyConn) SetWriteDeadline(t time.Time) error

type SecurePacketConn

type SecurePacketConn struct {
	net.PacketConn
	*Cipher
}

func NewSecurePacketConn

func NewSecurePacketConn(c net.PacketConn, cipher *Cipher) *SecurePacketConn

func (*SecurePacketConn) Close

func (c *SecurePacketConn) Close() error

func (*SecurePacketConn) LocalAddr

func (c *SecurePacketConn) LocalAddr() net.Addr

func (*SecurePacketConn) ReadFrom

func (c *SecurePacketConn) ReadFrom(b []byte) (n int, src net.Addr, err error)

func (*SecurePacketConn) SetDeadline

func (c *SecurePacketConn) SetDeadline(t time.Time) error

func (*SecurePacketConn) SetReadDeadline

func (c *SecurePacketConn) SetReadDeadline(t time.Time) error

func (*SecurePacketConn) SetWriteDeadline

func (c *SecurePacketConn) SetWriteDeadline(t time.Time) error

func (*SecurePacketConn) WriteTo

func (c *SecurePacketConn) WriteTo(b []byte, dst net.Addr) (n int, err error)

Jump to

Keyboard shortcuts

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