shadowsocks

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2016 License: GPL-3.0 Imports: 28 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 (
	OneTimeAuthMask byte = 0x10
	AddrMask        byte = 0xf
)

Variables

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

Functions

func AddListen

func AddListen(l Listen)

AddListen 添加网络对象

func AddRate

func AddRate(r Rate)

AddRate 按照端口统计流量

func CheckCipherMethod

func CheckCipherMethod(method string) error

func ClearPortRate

func ClearPortRate(port string)

ClearPortRate 端口流量清零

func EnoughOptions

func EnoughOptions(config *Config) bool

func GetListen

func GetListen() []string

GetListen 获取指定或者所有的网络链接

func HandleConnection

func HandleConnection(conn *Conn, auth bool, lr *Rate)

HandleConnection 处理具体链接数据

func HandleListen

func HandleListen()

HandleListen 控制每个网络链接

func HandleRate

func HandleRate()

HandleRate 统计每个端口的流出流量

func HmacSha1

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

func IsExists

func IsExists(port string) bool

IsExists 判断指定端口是否已经存在

func IsFileExists

func IsFileExists(path string) (bool, error)

func KillListen

func KillListen(port string) error

KillListen 关闭指定网络链接

func PipeThenClose

func PipeThenClose(src, dst net.Conn, lr *Rate)

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

func PipeThenCloseOta

func PipeThenCloseOta(src *Conn, dst net.Conn, lr *Rate)

PipeThenCloseOta copies data from src to dst, closes dst when done, with ota verification.

func PrintVersion

func PrintVersion()

func RawAddr

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

func Run

func Run(port, password, method string, auth bool)

Run SS执行函数 @port 监听端口 @passwd 端口绑定密钥 @method 端口绑定加密算法 @auth 是否需要一次性认证

func SetDebug

func SetDebug(d DebugLog)

func SetReadTimeout

func SetReadTimeout(c net.Conn)

func Sort

func Sort(arr []uint64, comparison func(uint64, uint64) int64) []uint64

func UnifyPortPassword

func UnifyPortPassword(config *Config) (err error)

func UpdateConfig

func UpdateConfig(old, new *Config)

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

func UpdatePasswd

func UpdatePasswd(configFile string, config *Config)

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"`
	Password   string      `json:"password"`
	Method     string      `json:"method"` // encryption method
	Auth       bool        `json:"auth"`   // one time auth

	// 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) GetAndIncrChunkId

func (c *Conn) GetAndIncrChunkId() (chunkId uint32)

func (*Conn) GetIv

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

func (*Conn) GetKey

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

func (*Conn) IsOta

func (c *Conn) IsOta() bool

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 GetDebug

func GetDebug() 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 Listen

type Listen struct {
	Port   string
	Listen net.Listener
}

Listen 网络监听对象

type PasswdManager

type PasswdManager struct {
	sync.Mutex
	PortListener map[string]*PortListener
}

func (*PasswdManager) Add

func (pm *PasswdManager) Add(port, password string, listener net.Listener)

func (*PasswdManager) Del

func (pm *PasswdManager) Del(port string)

func (*PasswdManager) Get

func (pm *PasswdManager) Get(port string) (pl *PortListener, ok bool)

func (*PasswdManager) UpdatePortPasswd

func (pm *PasswdManager) UpdatePortPasswd(port, password string, auth bool)

type PortListener

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

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 Rate

type Rate struct {
	Port string `json:"port"`
	Rate int    `json:"rate"`
}

Rate 流量类

func GetPortRate

func GetPortRate(port string) *Rate

GetPortRate 获取指定端口流量

func GetRate

func GetRate() []*Rate

GetRate 获取所有端口流量

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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