common

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONN_DATA_SEQ     = "*#*" //Separator
	VERIFY_EER        = "vkey"
	VERIFY_SUCCESS    = "sucs"
	WORK_MAIN         = "main"
	WORK_CHAN         = "chan"
	WORK_CONFIG       = "conf"
	WORK_REGISTER     = "rgst"
	WORK_SECRET       = "sert"
	WORK_FILE         = "file"
	WORK_P2P          = "p2pm"
	WORK_P2P_VISITOR  = "p2pv"
	WORK_P2P_PROVIDER = "p2pp"
	WORK_P2P_CONNECT  = "p2pc"
	WORK_P2P_SUCCESS  = "p2ps"
	WORK_P2P_END      = "p2pe"
	WORK_P2P_LAST     = "p2pl"
	WORK_STATUS       = "stus"
	RES_MSG           = "msg0"
	RES_CLOSE         = "clse"
	NEW_UDP_CONN      = "udpc" //p2p udp conn
	NEW_TASK          = "task"
	NEW_CONF          = "conf"
	NEW_HOST          = "host"
	CONN_TCP          = "tcp"
	CONN_UDP          = "udp"
	CONN_TEST         = "TST"
	UnauthorizedBytes = `HTTP/1.1 401 Unauthorized
Content-Type: text/plain; charset=utf-8
WWW-Authenticate: Basic realm="easyProxy"

401 Unauthorized`
	ConnectionFailBytes = `HTTP/1.1 404 Not Found

`
)
View Source
const (
	MUX_PING_FLAG uint8 = iota
	MUX_NEW_CONN_OK
	MUX_NEW_CONN_Fail
	MUX_NEW_MSG
	MUX_NEW_MSG_PART
	MUX_MSG_SEND_OK
	MUX_NEW_CONN
	MUX_CONN_CLOSE
	MUX_PING_RETURN
	MUX_PING             int32 = -1
	MAXIMUM_SEGMENT_SIZE       = PoolSizeWindow
	MAXIMUM_WINDOW_SIZE        = 1 << 25 // 1<<31-1 TCP slide window size is very large,

)
View Source
const MaxMsgLen = 5000
View Source
const PoolSize = 64 * 1024
View Source
const PoolSizeBuffer = 4096
View Source
const PoolSizeCopy = 32 << 10
View Source
const PoolSizeSmall = 100
View Source
const PoolSizeUdp = 1472 + 200
View Source
const PoolSizeWindow = PoolSizeBuffer - 2 - 4 - 4 - 1

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)
	},
}
View Source
var BuffPool = bufferPool{}
View Source
var CopyBuff = copyBufferPool{}
View Source
var ListElementPool = listElementPool{}
View Source
var MuxPack = muxPackagerPool{}
View Source
var WindowBuff = windowBufferPool{}

Functions

func BinaryWrite

func BinaryWrite(raw *bytes.Buffer, v ...string)

Write length and individual byte data Length prevents sticking # Characters are used to separate data

func BytesToNum added in v0.18.2

func BytesToNum(b []byte) int

convert bytes to num

func ChangeHostAndHeader

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

Change headers and host of request

func CheckAuth

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

Check if the Request request is validated

func CopyBuffer added in v0.0.16

func CopyBuffer(dst io.Writer, src io.Reader, label ...string) (written int64, err error)

func DomainCheck

func DomainCheck(domain string) bool

Check the legality of domain

func FileExists

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func FormatAddress added in v0.0.15

func FormatAddress(s string) string

if the s is just a port,return 127.0.0.1:s

func GeSynctMapLen added in v0.21.0

func GeSynctMapLen(m sync.Map) int

get the length of the sync map

func GetAppPath

func GetAppPath() string

Get the absolute path to the running directory

func GetBoolByStr

func GetBoolByStr(s string) bool

get bool by str

func GetBufPoolCopy added in v0.24.0

func GetBufPoolCopy() []byte

func GetEnvMap added in v0.18.1

func GetEnvMap() map[string]string

get env

func GetExtFromPath added in v0.22.0

func GetExtFromPath(path string) string

func GetExternalIp added in v0.24.2

func GetExternalIp() string

func GetHostByName

func GetHostByName(hostname string) string

Get the corresponding IP address through domain name

func GetInstallPath

func GetInstallPath() string

Different systems get different installation paths

func GetIntNoErrByStr

func GetIntNoErrByStr(str string) int

int

func GetIntranetIp added in v0.24.2

func GetIntranetIp() (error, string)

func GetIpByAddr added in v0.0.15

func GetIpByAddr(addr string) string

get address from the complete address

func GetLocalUdpAddr added in v0.18.0

func GetLocalUdpAddr() (net.Conn, error)

send this ip forget to get a local udp port

func GetLogMsg added in v0.25.1

func GetLogMsg() string

func GetLogPath

func GetLogPath() string

interface log file path

func GetNpcLogPath added in v0.25.2

func GetNpcLogPath() string

interface npc log file path

func GetPortByAddr added in v0.23.0

func GetPortByAddr(addr string) int

get port from the complete address

func GetPorts added in v0.0.15

func GetPorts(p string) []int

format ports str to a int array

func GetRunPath

func GetRunPath() string

Get the currently selected configuration file directory For non-Windows systems, select the /etc/nps as config directory if exist, or select ./ windows system, select the C:\Program Files\nps as config directory if exist, or select ./

func GetServerIpByClientIp added in v0.24.2

func GetServerIpByClientIp(clientIp net.IP) string

func GetStrByBool

func GetStrByBool(b bool) string

get str by bool

func GetTmpPath added in v0.0.15

func GetTmpPath() string

interface pid file path

func GetWriteStr added in v0.23.0

func GetWriteStr(v ...string) []byte

get seq str

func Getverifyval

func Getverifyval(vkey string) string

Get verify value

func InIntArr added in v0.0.15

func InIntArr(arr []int, val int) bool

inArray int interface

func InStrArr added in v0.0.16

func InStrArr(arr []string, val string) bool

inArray str interface

func IsArrContains added in v0.18.1

func IsArrContains(arr []string, val string) bool

func IsPort added in v0.0.15

func IsPort(p string) bool

is the string a port

func IsPublicIP added in v0.24.2

func IsPublicIP(IP net.IP) bool

func IsWindows

func IsWindows() bool

Determine whether the current system is a Windows system?

func ParseStr added in v0.18.1

func ParseStr(str string) (string, error)

parse template

func PutBufPoolCopy added in v0.24.0

func PutBufPoolCopy(buf []byte)

func PutBufPoolMax added in v0.24.0

func PutBufPoolMax(buf []byte)

func PutBufPoolUdp added in v0.24.0

func PutBufPoolUdp(buf []byte)

func ReadAllFromFile

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

Read file content by file path

func RemoveArrVal added in v0.18.1

func RemoveArrVal(arr []string, val string) []string

remove value from string array

func TestTcpPort

func TestTcpPort(port int) bool

Judge whether the TCP port can open normally

func TestUdpPort

func TestUdpPort(port int) bool

Judge whether the UDP port can open normally

func TrimArr added in v0.18.1

func TrimArr(arr []string) []string

throw the empty element of the string array

Types

type Addr added in v0.24.2

type Addr struct {
	Type uint8
	Host string
	Port uint16
}

func ToSocksAddr added in v0.24.2

func ToSocksAddr(addr net.Addr) *Addr

func (*Addr) Decode added in v0.24.2

func (addr *Addr) Decode(b []byte) error

func (*Addr) Encode added in v0.24.2

func (addr *Addr) Encode(b []byte) (int, error)

func (*Addr) String added in v0.24.2

func (addr *Addr) String() string

type BasePackager added in v0.24.0

type BasePackager struct {
	Length  uint16
	Content []byte
}

func (*BasePackager) NewPac added in v0.24.0

func (Self *BasePackager) NewPac(contents ...interface{}) (err error)

func (*BasePackager) Pack added in v0.24.0

func (Self *BasePackager) Pack(writer io.Writer) (err error)

似乎这里涉及到父类作用域问题,当子类调用父类的方法时,其struct仅仅为父类的

func (*BasePackager) Split added in v0.24.0

func (Self *BasePackager) Split() (strList []string)

func (*BasePackager) UnPack added in v0.24.0

func (Self *BasePackager) UnPack(reader io.Reader) (n uint16, err error)

Unpack 会导致传入的数字类型转化成float64!! 主要原因是json unmarshal并未传入正确的数据类型

func (*BasePackager) Unmarshal added in v0.24.0

func (Self *BasePackager) Unmarshal(content interface{}) (err error)

type ConnPackager added in v0.24.0

type ConnPackager struct {
	// Todo
	ConnType uint8
	BasePackager
}

func (*ConnPackager) NewPac added in v0.24.0

func (Self *ConnPackager) NewPac(connType uint8, content ...interface{}) (err error)

func (*ConnPackager) Pack added in v0.24.0

func (Self *ConnPackager) Pack(writer io.Writer) (err error)

func (*ConnPackager) UnPack added in v0.24.0

func (Self *ConnPackager) UnPack(reader io.Reader) (n uint16, err error)

type ListElement added in v0.24.0

type ListElement struct {
	Buf  []byte
	L    uint16
	Part bool
}

type MuxPackager added in v0.24.0

type MuxPackager struct {
	Flag   uint8
	Id     int32
	Window uint64
	BasePackager
}

func (*MuxPackager) NewPac added in v0.24.0

func (Self *MuxPackager) NewPac(flag uint8, id int32, content ...interface{}) (err error)

func (*MuxPackager) Pack added in v0.24.0

func (Self *MuxPackager) Pack(writer io.Writer) (err error)

func (*MuxPackager) UnPack added in v0.24.0

func (Self *MuxPackager) UnPack(reader io.Reader) (n uint16, err error)

type NetPackager added in v0.24.0

type NetPackager interface {
	Pack(writer io.Writer) (err error)
	UnPack(reader io.Reader) (err error)
}

type StoreMsg added in v0.25.1

type StoreMsg struct {
}

func (*StoreMsg) Destroy added in v0.25.1

func (lg *StoreMsg) Destroy()

func (*StoreMsg) Flush added in v0.25.1

func (lg *StoreMsg) Flush()

func (*StoreMsg) Init added in v0.25.1

func (lg *StoreMsg) Init(config string) error

func (*StoreMsg) WriteMsg added in v0.25.1

func (lg *StoreMsg) WriteMsg(when time.Time, msg string, level int) error

type UDPDatagram added in v0.24.2

type UDPDatagram struct {
	Header *UDPHeader
	Data   []byte
}

func NewUDPDatagram added in v0.24.2

func NewUDPDatagram(header *UDPHeader, data []byte) *UDPDatagram

func ReadUDPDatagram added in v0.24.2

func ReadUDPDatagram(r io.Reader) (*UDPDatagram, error)

func (*UDPDatagram) Write added in v0.24.2

func (d *UDPDatagram) Write(w io.Writer) error

type UDPHeader added in v0.24.2

type UDPHeader struct {
	Rsv  uint16
	Frag uint8
	Addr *Addr
}

func NewUDPHeader added in v0.24.2

func NewUDPHeader(rsv uint16, frag uint8, addr *Addr) *UDPHeader

func (*UDPHeader) Write added in v0.24.2

func (h *UDPHeader) Write(w io.Writer) error

Jump to

Keyboard shortcuts

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