utils

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2019 License: MIT Imports: 21 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"
	CONN_SUCCESS       = "sucs"
	CONN_ERROR         = "fail"
	TEST_FLAG          = "tst"
	CONN_TCP           = "tcp"
	CONN_UDP           = "udp"
	Unauthorized_BYTES = `HTTP/1.1 401 Unauthorized
Content-Type: text/plain; charset=utf-8
WWW-Authenticate: Basic realm="easyProxy"

401 Unauthorized`
	IO_EOF = "PROXYEOF"
)

Variables

This section is empty.

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 FlushConn

func FlushConn(c net.Conn)

连接重置 清空缓存区

func GetBoolByStr

func GetBoolByStr(s string) bool

get bool by str

func GetCompressType

func GetCompressType(compress string) (int, int)

判断压缩方式

func GetIntNoerrByStr

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 Gethostbyname

func Gethostbyname(hostname string) string

通过host获取对应的ip地址

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 Relay

func Relay(in, out net.Conn, compressType int, crypt, mux bool)

copy

func ReplayWaitGroup added in v0.0.9

func ReplayWaitGroup(conn1 net.Conn, conn2 net.Conn, compressEncode, compressDecode int, crypt, mux bool)

wait replay group

Types

type Conn

type Conn struct {
	Conn net.Conn
}

func NewConn

func NewConn(conn net.Conn) *Conn

new conn

func (*Conn) Close

func (s *Conn) Close() error

close

func (*Conn) GetConnInfoFromConn

func (s *Conn) GetConnInfoFromConn() (en, de int, crypt, mux bool)

获取压缩方式,是否加密

func (*Conn) GetHost

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

从tcp报文中解析出host,连接类型等 TODO 多种情况

func (*Conn) GetHostFromConn

func (s *Conn) GetHostFromConn() (typeStr string, host string, en, de int, crypt, mux bool, err error)

读取host 连接地址 压缩类型

func (*Conn) GetLen

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

获取长度

func (*Conn) Read

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

read

func (*Conn) ReadFlag

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

读取flag

func (*Conn) ReadFrom

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

单独读(加密|压缩)

func (*Conn) ReadLen

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

读取指定长度内容

func (*Conn) SetAlive

func (s *Conn) SetAlive()

设置连接为长连接

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) WriteConnInfo

func (s *Conn) WriteConnInfo(en, de int, crypt, mux bool)

写压缩方式,加密

func (*Conn) WriteError

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

write error

func (*Conn) WriteFail

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

write test

func (*Conn) WriteHost

func (s *Conn) WriteHost(ltype string, host string) (int, error)

写连接类型 和 host地址

func (*Conn) WriteLen

func (s *Conn) WriteLen(buf []byte) (int, error)

写入长度+内容 粘包

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() (int, error)

write test

func (*Conn) WriteTest

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

write test

func (*Conn) WriteTo

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

单独写(加密|压缩)

type CryptConn

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

func NewCryptConn

func NewCryptConn(conn net.Conn, crypt bool) *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 SnappyConn

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

func NewSnappyConn

func NewSnappyConn(conn net.Conn, crypt bool) *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压缩写 包含加密

Jump to

Keyboard shortcuts

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