utils

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COMPRESS_NONE_ENCODE = iota
	COMPRESS_NONE_DECODE
	COMPRESS_SNAPY_ENCODE
	COMPRESS_SNAPY_DECODE
	VERIFY_EER        = "vkey"
	WORK_MAIN         = "main"
	WORK_CHAN         = "chan"
	RES_SIGN          = "sign"
	RES_MSG           = "msg0"
	RES_CLOSE         = "clse"
	NEW_CONN          = "conn" //新连接标志
	CONN_SUCCESS      = "sucs"
	CONN_TCP          = "tcp"
	CONN_UDP          = "udp"
	UnauthorizedBytes = `HTTP/1.1 401 Unauthorized
Content-Type: text/plain; charset=utf-8
WWW-Authenticate: Basic realm="easyProxy"

401 Unauthorized`
	IO_EOF              = "PROXYEOF"
	ConnectionFailBytes = `HTTP/1.1 404 Not Found

`
)

Variables

View Source
var BufPool = sync.Pool{
	New: func() interface{} {
		return make([]byte, poolSize)
	},
}
View Source
var BufPoolCopy = sync.Pool{
	New: func() interface{} {
		return make([]byte, poolSizeCopy)
	},
}
View Source
var BufPoolMax = sync.Pool{
	New: func() interface{} {
		return make([]byte, poolSize)
	},
}
View Source
var BufPoolSmall = sync.Pool{
	New: func() interface{} {
		return make([]byte, poolSizeSmall)
	},
}
View Source
var BufPoolUdp = sync.Pool{
	New: func() interface{} {
		return make([]byte, poolSizeUdp)
	},
}

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

de

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

en

func ChangeHostAndHeader added in v0.0.9

func ChangeHostAndHeader(r *http.Request, host string, header string, addr string)

func CheckAuth

func CheckAuth(r *http.Request, user, passwd string) bool

检查basic认证

func DomainCheck

func DomainCheck(domain string) bool

检查是否是域名

func GetBoolByStr

func GetBoolByStr(s string) bool

get bool by str

func GetCompressType

func GetCompressType(compress string) (int, int)

判断压缩方式

func GetHostByName added in v0.0.10

func GetHostByName(hostname string) string

通过host获取对应的ip地址

func GetIntNoErrByStr added in v0.0.10

func GetIntNoErrByStr(str string) int

int

func GetLenByBytes

func GetLenByBytes(buf []byte) (int, error)

解析出长度

func GetLenBytes

func GetLenBytes(buf []byte) (b []byte, err error)

获取长度+内容

func GetRandomString

func GetRandomString(l int) string

生成随机验证密钥

func GetStrByBool

func GetStrByBool(b bool) string

get str by bool

func Getverifyval

func Getverifyval(vkey string) string

简单的一个校验值

func Md5

func Md5(s string) string

生成32位md5字串

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

补全

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) (error, []byte)

去补

func PutBufPoolCopy added in v0.0.12

func PutBufPoolCopy(buf []byte)

func ReadAllFromFile added in v0.0.10

func ReadAllFromFile(filePath string) ([]byte, error)

Types

type Client added in v0.0.10

type Client struct {
	Cnf       *Config
	Id        int    //id
	VerifyKey string //验证密钥
	Addr      string //客户端ip地址
	Remark    string //备注
	Status    bool   //是否开启
	IsConnect bool   //是否连接
	RateLimit int    //速度限制 /kb
	Flow      *Flow  //流量
	Rate      *Rate  //速度控制

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Client) GetId added in v0.0.12

func (s *Client) GetId() int

type Config added in v0.0.10

type Config struct {
	U              string //socks5验证用户名
	P              string //socks5验证密码
	Compress       string //压缩方式
	Crypt          bool   //是否加密
	CompressEncode int    //加密方式
	CompressDecode int    //解密方式
}

func DeepCopyConfig added in v0.0.10

func DeepCopyConfig(c *Config) *Config

深拷贝Config

type Conn

type Conn struct {
	Conn net.Conn
	sync.Mutex
}

func NewConn

func NewConn(conn net.Conn) *Conn

new conn

func (*Conn) Close

func (s *Conn) Close() error

close

func (*Conn) GetConnStatus added in v0.0.12

func (s *Conn) GetConnStatus() (id int, status bool, err error)

read connect status

func (*Conn) GetHost

func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request)

从tcp报文中解析出host,连接类型等

func (*Conn) GetLen

func (s *Conn) GetLen() (int, error)

read length or id (content length=4)

func (*Conn) GetLinkInfo added in v0.0.12

func (s *Conn) GetLinkInfo() (link *Link, err error)

func (*Conn) GetMsgContent added in v0.0.12

func (s *Conn) GetMsgContent(link *Link) (content []byte, err error)

get msg content from conn

func (*Conn) Read

func (s *Conn) Read(b []byte) (int, error)

read

func (*Conn) ReadFlag

func (s *Conn) ReadFlag() (string, error)

read flag

func (*Conn) ReadFrom

func (s *Conn) ReadFrom(b []byte, compress int, crypt bool, rate *Rate) (int, error)

单独读(加密|压缩)

func (*Conn) ReadLen

func (s *Conn) ReadLen(cLen int) ([]byte, error)

读取指定长度内容

func (*Conn) SendLinkInfo added in v0.0.12

func (s *Conn) SendLinkInfo(link *Link) (int, error)

send info for link

func (*Conn) SendMsg added in v0.0.12

func (s *Conn) SendMsg(content []byte, link *Link) (n int, err error)

send msg

func (*Conn) SetAlive

func (s *Conn) SetAlive()

设置连接为长连接

func (*Conn) SetReadDeadline added in v0.0.11

func (s *Conn) SetReadDeadline(t time.Duration)

set read dead time

func (*Conn) Write

func (s *Conn) Write(b []byte) (int, error)

write

func (*Conn) WriteChan

func (s *Conn) WriteChan() (int, error)

write chan

func (*Conn) WriteClose added in v0.0.11

func (s *Conn) WriteClose() (int, error)

write sign flag

func (*Conn) WriteError

func (s *Conn) WriteError() (int, error)

write error

func (*Conn) WriteFail

func (s *Conn) WriteFail(id int) (int, error)

write connect fail

func (*Conn) WriteMain

func (s *Conn) WriteMain() (int, error)

write main

func (*Conn) WriteSign

func (s *Conn) WriteSign() (int, error)

write sign flag

func (*Conn) WriteSuccess

func (s *Conn) WriteSuccess(id int) (int, error)

write connect success

func (*Conn) WriteTo

func (s *Conn) WriteTo(b []byte, compress int, crypt bool, rate *Rate) (n int, err error)

单独写(加密|压缩)

type CryptConn

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

func NewCryptConn

func NewCryptConn(conn net.Conn, crypt bool, rate *Rate) *CryptConn

func (*CryptConn) Read

func (s *CryptConn) Read(b []byte) (n int, err error)

解密读

func (*CryptConn) Write

func (s *CryptConn) Write(b []byte) (n int, err error)

加密写

type Csv added in v0.0.10

type Csv struct {
	Tasks            []*Tunnel
	Path             string
	Hosts            []*Host   //域名列表
	Clients          []*Client //客户端
	ClientIncreaseId int       //客户端id
	TaskIncreaseId   int       //任务自增ID
	sync.Mutex
}
var (
	CsvDb *Csv
)

func GetCsvDb added in v0.0.10

func GetCsvDb() *Csv

init csv from file

func NewCsv added in v0.0.10

func NewCsv() *Csv

func (*Csv) DelClient added in v0.0.10

func (s *Csv) DelClient(id int) error

func (*Csv) DelHost added in v0.0.10

func (s *Csv) DelHost(host string) error

func (*Csv) DelTask added in v0.0.10

func (s *Csv) DelTask(id int) error

func (*Csv) GetClient added in v0.0.10

func (s *Csv) GetClient(id int) (v *Client, err error)

func (*Csv) GetClientId added in v0.0.10

func (s *Csv) GetClientId() int

func (*Csv) GetClientList added in v0.0.10

func (s *Csv) GetClientList(start, length int) ([]*Client, int)

func (*Csv) GetHost added in v0.0.10

func (s *Csv) GetHost(start, length int, id int) ([]*Host, int)

func (*Csv) GetIdByVerifyKey added in v0.0.10

func (s *Csv) GetIdByVerifyKey(vKey string, addr string) (int, error)

func (*Csv) GetTask added in v0.0.10

func (s *Csv) GetTask(id int) (v *Tunnel, err error)

func (*Csv) GetTaskId added in v0.0.10

func (s *Csv) GetTaskId() int

func (*Csv) Init added in v0.0.10

func (s *Csv) Init()

func (*Csv) LoadClientFromCsv added in v0.0.10

func (s *Csv) LoadClientFromCsv()

func (*Csv) LoadHostFromCsv added in v0.0.10

func (s *Csv) LoadHostFromCsv()

func (*Csv) LoadTaskFromCsv added in v0.0.10

func (s *Csv) LoadTaskFromCsv()

func (*Csv) NewClient added in v0.0.10

func (s *Csv) NewClient(c *Client)

func (*Csv) NewHost added in v0.0.10

func (s *Csv) NewHost(t *Host)

func (*Csv) NewTask added in v0.0.10

func (s *Csv) NewTask(t *Tunnel)

func (*Csv) StoreClientsToCsv added in v0.0.10

func (s *Csv) StoreClientsToCsv()

func (*Csv) StoreHostToCsv added in v0.0.10

func (s *Csv) StoreHostToCsv()

func (*Csv) StoreTasksToCsv added in v0.0.10

func (s *Csv) StoreTasksToCsv()

func (*Csv) UpdateClient added in v0.0.10

func (s *Csv) UpdateClient(t *Client) error

func (*Csv) UpdateHost added in v0.0.10

func (s *Csv) UpdateHost(t *Host) error

func (*Csv) UpdateTask added in v0.0.10

func (s *Csv) UpdateTask(t *Tunnel) error

type Flow added in v0.0.10

type Flow struct {
	ExportFlow int64 //出口流量
	InletFlow  int64 //入口流量
	FlowLimit  int64 //流量限制,出口+入口 /M
	sync.RWMutex
}

func (*Flow) Add added in v0.0.12

func (s *Flow) Add(in, out int)

type Host added in v0.0.10

type Host struct {
	Host         string //启动方式
	Target       string //目标
	HeaderChange string //host修改
	HostChange   string //host修改
	Flow         *Flow
	Client       *Client
	Remark       string //备注
}
type Link struct {
	Id            int    //id
	ConnType      string //连接类型
	Host          string //目标
	En            int    //加密
	De            int    //解密
	Crypt         bool   //加密
	Conn          *Conn
	Flow          *Flow
	UdpListener   *net.UDPConn
	Rate          *Rate
	UdpRemoteAddr *net.UDPAddr
}
func NewLink(id int, connType string, host string, en, de int, crypt bool, conn *Conn, flow *Flow, udpListener *net.UDPConn, rate *Rate, UdpRemoteAddr *net.UDPAddr) *Link

type Rate added in v0.0.11

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

func NewRate added in v0.0.11

func NewRate(addSize int64) *Rate

func (*Rate) Get added in v0.0.11

func (s *Rate) Get(size int64)

func (*Rate) ReturnBucket added in v0.0.11

func (s *Rate) ReturnBucket(size int64)

回桶

func (*Rate) Start added in v0.0.11

func (s *Rate) Start()

func (*Rate) Stop added in v0.0.11

func (s *Rate) Stop()

停止

type SnappyConn

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

func NewSnappyConn

func NewSnappyConn(conn net.Conn, crypt bool, rate *Rate) *SnappyConn

func (*SnappyConn) Read

func (s *SnappyConn) Read(b []byte) (n int, err error)

snappy压缩读 包含解密

func (*SnappyConn) Write

func (s *SnappyConn) Write(b []byte) (n int, err error)

snappy压缩写 包含加密

type Tunnel added in v0.0.10

type Tunnel struct {
	Id           int     //Id
	TcpPort      int     //服务端与客户端通信端口
	Mode         string  //启动方式
	Target       string  //目标
	Status       bool    //是否开启
	Client       *Client //所属客户端id
	Flow         *Flow
	Config       *Config
	UseClientCnf bool   //是否继承客户端配置
	Remark       string //备注
}

Jump to

Keyboard shortcuts

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