shadowsocks

package
v0.0.0-...-0573075 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	OneTimeAuthMask byte = 0x10
	AddrMask        byte = 0xf
)
View Source
const (
	// TIMEFORMATE 默认时间格式
	TIMEFORMATE = "2006-01-02"
)

Variables

View Source
var (
	// Minport 默认最低端口从10001开始
	Minport = 10001
	// Maxport 默认最低端口从19999开始
	Maxport = 19999
	// Currport 当前端口
	Currport = Minport
)
View Source
var ConnChan = make(chan error)

ConnChan 用于定制网络链接信息

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

GlobaIP 全局监听IP

View Source
var PassMap map[string]UserPass
View Source
var PasswdChan = make(chan *UserPass)

PasswdChan 用于保存网络链接及其口令

View Source
var UserChan = make(chan *User)

UserChan 传递新建用户信息

Functions

func AddListen

func AddListen(l Listen)

AddListen 添加网络对象

func AddRate

func AddRate(r Listen)

AddRate 按照端口统计流量

func CheckCipherMethod

func CheckCipherMethod(method string) error

func ClearPortRate

func ClearPortRate(port string)

ClearPortRate 端口流量清零

func ConvertRate

func ConvertRate(rate int) string

ConvertRate 流量转换。 Btye --> KB --> MB --> GB

func CreatePasswd

func CreatePasswd() string

CreatePasswd 创建一个8位数随机密码

func CreateUser

func CreateUser(u *User)

CreateUser 创建新用户

func EnoughOptions

func EnoughOptions(config *Config) bool

EnoughOptions 确认参数是否完整

func GetListen

func GetListen() []string

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

func HandleConnection

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

HandleConnection 处理具体链接数据

func HandleListen

func HandleListen()

HandleListen 控制每个网络链接

func HandleRate

func HandleRate()

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

func HmacSha1

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

func IsAboveRate

func IsAboveRate()

IsAboveRate 判断当前每个链接是否超过指定流量

func IsExists

func IsExists(port string) bool

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

func IsExpiry

func IsExpiry()

IsExpiry 当前链接是否有效

func IsFileExists

func IsFileExists(path string) (bool, error)

func KillListen

func KillListen(port string) error

KillListen 关闭指定网络链接

func KillUserPass

func KillUserPass(port string)

KillUserPass 当断开链接时,一并删除其口令

func ParseBackConfig

func ParseBackConfig(config *Config) error

ParseBackConfig 解析备份配置文件数据

func Persistence

func Persistence()

Persistence 用户数据持久化

func PersistencePasswd

func PersistencePasswd()

PersistencePasswd 用户口令持久化

func PipeThenClose

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

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

func PipeThenCloseLocal

func PipeThenCloseLocal(src, dst net.Conn)

PipeThenCloseLocal For Local use. copies data from src to dst, closes dst when done.

func PipeThenCloseOta

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

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

func PipeThenCloseOtaLocal

func PipeThenCloseOtaLocal(src *Conn, dst net.Conn)

PipeThenCloseOtaLocal For Local use. 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 RunNew

func RunNew(u *User)

RunNew 通过API自动创建一个网络链接

func SendEmail

func SendEmail(content string, addr string) error

SendEmail 发送邮件到指定邮箱 content 邮件内容 addr 对方邮箱

func SetDebug

func SetDebug(d DebugLog)

SetDebug 设置输出日志级别

func SetExpiry

func SetExpiry(port string, d string) error

SetExpiry 设置指定网络链接有效期 @port 指定网络链接端口 @d 调整后的失效日期,只能为YYYY-MM-DD格式

func SetRate

func SetRate(port, rate string) error

SetRate 设置网络链接流量上限

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)

UnifyPortPassword 确认链接密钥

func UpdateConfig

func UpdateConfig(old, new *Config)

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

func UpdatePasswd

func UpdatePasswd(configFile string, config *Config)

UpdatePasswd 更新链接密钥

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
	Minport    int         `json:"minport"`
	Maxport    int         `json:"maxport"`
	// 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"`
}

Config 网络链接配置信息

func ParseConfig

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

ParseConfig 解析配置文件数据

func (*Config) GetServerArray

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

GetServerArray 获取当前所有服务参数

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

GetDebug 用于设置Debug函数

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 Email

type Email struct {
	Host     string `json:"host"`
	Username string `json:"user"`
	Password string `json:"passwd"`
	Port     int    `json:"port"`
	Dest     string `json:"dest"`
}

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 `json:"port"`
	Rate       int    `json:"rate"`
	ExpiryDate string `json:"expiry_date"`
	RateLimit  int    `json:"rate_limit"`
	Email      string `json:"email"` //16-12-14 新增Email属性
	// contains filtered or unexported fields
}

Listen 网络监听对象

func GetPortRate

func GetPortRate(port string) *Listen

GetPortRate 获取指定端口流量

type ListenBak

type ListenBak struct {
	Lb []Listen `json:"lb"`
}

ListenBak 网络备份

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 string `json:"rate"`
}

Rate 流量数据 每次都从Listen中重新获取数据

type User

type User struct {
	Port      string
	Expriy    string `json:"expriy"`
	Rate      int    `json:"rate"`
	RateLimit int    `json:"ratelimit"`
	Email     string `json:"email"` //16-12-14 新增email属性
	Password  string `json:"password"`
	ID        string `json:"port"`
}

User 网络链接结构体. Conn对应网络链接,所以这里使用User替代Conn

func GetRate

func GetRate() ([]User, error)

GetRate 获取所有端口流量

type UserPass

type UserPass struct {
	Port     string `json:"port"`
	Password string `json:"password"`
}

UserPass 将端口和链接口令单独保存

type UserPassBack

type UserPassBack struct {
	Upb []UserPass `json:"upb"`
}

UserPassBack 用于格式化输出UserPass

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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