tool

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2023 License: MIT Imports: 21 Imported by: 4

Documentation

Index

Constants

View Source
const (
	P2PTcpReset   = "P2PTcpReset"
	P2PTcpStart   = "P2PTcpStart"
	P2PTCpSucceed = "P2PTCpSucceed"
	P2PTCpFailed  = "P2PTCpSucceed"
)
View Source
const (
	SubOpenTypeDefault = "SubOpenTypeDefault"
	SubOpenTypeTCPP2P  = "SubOpenTypeTCPP2P"
)
View Source
const (
	LinkConnTypeTCP = "LinkConnTypeTCP"
	LinkConnTypeUDP = "LinkConnTypeUDP"
	CopyConnTypeTCP = "CopyConnTypeTCP"
	CopyConnTypeUDP = "LinkConnTypeUDP"
)
View Source
const (
	BufferSize = 4096
)

bytes size = 4096 data len 4004=4096-8-60-8-16

View Source
const ConnVPNA1 = "ConnVPNA1"
View Source
const ConnVPNA2 = "ConnVPNA2"
View Source
const ConnVPNQ1 = "ConnVPNQ1"
View Source
const ConnVPNQ2 = "ConnVPNQ2"
View Source
const DelayA = "DelayA"
View Source
const DelayQ = "DelayQ"
View Source
const HandshakeCheckStepA1 = "Hi! What's your Info?"
View Source
const HandshakeCheckStepA2 = "OK! Happy handshake"
View Source
const HandshakeCheckStepQ1 = "Hello! I want to shake hands."
View Source
const HandshakeCheckStepQ2 = "Here it is"
View Source
const HttpVPNFA1 = "HttpVPNFA1"
View Source
const HttpVPNFA2 = "HttpVPNFA2"
View Source
const HttpVPNFQ1 = "HttpVPNFQ1"
View Source
const HttpVPNFQ2 = "HttpVPNFQ2"
View Source
const P2PTcpA1 = "P2PTcpA1"
View Source
const P2PTcpA2 = "P2PTcpA2"
View Source
const P2PTcpA3 = "P2PTcpA3"
View Source
const P2PTcpQ1 = "P2PTcpQ1"
View Source
const P2PTcpQ2 = "P2PTcpQ2"
View Source
const P2PTcpQ3 = "P2PTcpQ3"
View Source
const P2PUdpA1 = "P2PUdpA1"
View Source
const P2PUdpO = "P2PUdpO"
View Source
const P2PUdpQ1 = "P2PUdpQ1"
View Source
const PingMsg = "Ping"
View Source
const PongMsg = "Pong"
View Source
const SOpenA = "sOpenA"
View Source
const SOpenQ = "sOpenQ"
View Source
const SpeedA0 = "SpeedA0"
View Source
const SpeedA1 = "SpeedA1"
View Source
const SpeedA2 = "SpeedA2"
View Source
const SpeedA3 = "SpeedA3"
View Source
const SpeedQ0 = "SpeedQ0" //server all network speed
View Source
const SpeedQ1 = "SpeedQ1" //some client network speed
View Source
const SpeedQ2 = "SpeedQ2" //one client and sub client network speed
View Source
const SpeedQ3 = "SpeedQ3" //only one client network speed
View Source
const TaskA = "TaskA"
View Source
const TaskQ = "TaskQ"

Variables

View Source
var ErrBoxComplexListen = errors.New("box complex listen")
View Source
var ErrBoxIsClosed = errors.New("box is closed")
View Source
var ErrBoxIsNil = errors.New("box is nil")
View Source
var ErrBoxStopListen = errors.New("box stop listen")
View Source
var ErrCheckBadAny = func(a ...any) error { return fmt.Errorf("check err: %v", a) }
View Source
var ErrCheckUnexpectedHeader = errors.New("check err:  unexpected header")
View Source
var ErrConnIsNil = errors.New("conn is nil")
View Source
var ErrDataException = errors.New("data exception")
View Source
var ErrHandleCMsgMissProxyClient = errors.New("not Not found proxy client")
View Source
var ErrHandleCMsgMissProxyTaskRoom = errors.New("not Not found proxy task room ")
View Source
var ErrHandleCMsgProxyClientNameIsNil = errors.New("need one proxy client name to register")
View Source
var ErrHandshakeIsBad = errors.New("handshake is bad")
View Source
var ErrIsDisable = errors.New("is disable")
View Source
var ErrKeyIsNot32Bytes = errors.New("key is not 32bytes")
View Source
var ErrLinkClientIsClosed = errors.New("link client is closed")
View Source
var ErrMethodIsRefused = errors.New("the method is refused")
View Source
var ErrNameIsNil = errors.New("name is nil")
View Source
var ErrOpenSubBoxBadAny = func(a ...any) error { return fmt.Errorf("open sub box bad : %v", a) }
View Source
var ErrOpenSubUnexpectedOdj = errors.New("unexpected resp Odj")
View Source
var ErrProxyClientIsClosed = errors.New("the proxy client is closed")
View Source
var ErrReadCMsgHashCheckFailed = errors.New("hash check failed")
View Source
var ErrReadCMsgLensTooLong = fmt.Errorf("lens: too long to %v bytes", BufferSize)
View Source
var ErrReadCMsgLensTooShort = fmt.Errorf("lens: too small to %v  bytes", getHeaderSize())
View Source
var ErrReadCProtocolIsNotGoCFC = errors.New("the protocol is not go-CFC : is not " + version)
View Source
var ErrReadCSkipToFastConn = errors.New("skip to LinkConn")
View Source
var ErrReqBadAny = func(a ...any) error { return fmt.Errorf("req bad : %v", a) }
View Source
var ErrReqUnexpectedHeader = errors.New("unexpected resp header")
View Source
var ErrSubDstKeyIsNil = errors.New("sub dst key is nil")
View Source
var ErrSubIsDisable = errors.New("sub box is disable")
View Source
var ErrSubLocalAddrIsNil = errors.New("sub local addr is nil")
View Source
var ErrSubTypeInvalid = errors.New("sub type invalid")
View Source
var ErrSubTypeToMixGetSubBoxFailed = errors.New("sub type to mix get sub box failed")
View Source
var ErrTimeout = errors.New("timeout")
View Source
var ErrUnexpectedLinkConnType = errors.New("unexpected link conn type")
View Source
var ErrUnexpectedSubOpenType = errors.New("unexpected sub open type")
View Source
var TaskCbIdIsNeed = errors.New("task cb id is nil")
View Source
var TaskSkipErr = errors.New("task skip err")

Functions

func Decrypt

func Decrypt(ciphertext []byte, key []byte) ([]byte, error)

func Encrypt

func Encrypt(plaintext []byte, key []byte) ([]byte, error)

func ErrAppend added in v1.3.0

func ErrAppend(err error, errs ...error) error

func MustBase64ToBytes added in v1.2.1

func MustBase64ToBytes(str string) []byte

func MustMarshal

func MustMarshal(body interface{}) []byte

func MustResolveTCPAddr added in v1.3.3

func MustResolveTCPAddr(addr net.Addr) *net.TCPAddr

func MustUnmarshal

func MustUnmarshal(b []byte, body interface{})

func MustUnmarshalV2

func MustUnmarshalV2(inBody interface{}, outBody interface{})

func MustWriteCMsgNotKeyJson added in v1.3.8

func MustWriteCMsgNotKeyJson(cMsg ConnMsg) (b []byte)

func NewId

func NewId(n int) (str string)

func Println

func Println(conn net.Conn, i ...any)

func ReRun added in v1.3.5

func ReRun(rt string, fn func() bool) error

func UnmarshalV2

func UnmarshalV2(inBody interface{}, outBody interface{}) error

func WriteCMsgNotKeyJson added in v1.3.8

func WriteCMsgNotKeyJson(cMsg ConnMsg) (b []byte, err error)

Types

type CloseWaiter added in v1.3.5

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

func NewCloseWaiter added in v1.3.5

func NewCloseWaiter() *CloseWaiter

func (*CloseWaiter) AddCloseFn added in v1.3.5

func (cw *CloseWaiter) AddCloseFn(fn func())

func (*CloseWaiter) Close added in v1.3.5

func (cw *CloseWaiter) Close(err error)

func (*CloseWaiter) Wait added in v1.3.5

func (cw *CloseWaiter) Wait() error

type ConnMsg

type ConnMsg struct {
	Header string
	Code   int
	Data   interface{}
	Id     string
}

func MustReadCMsgNotKeyJson added in v1.3.8

func MustReadCMsgNotKeyJson(b []byte) (cMsg ConnMsg)

func MustReadCMsgNotKeyJson2 added in v1.3.8

func MustReadCMsgNotKeyJson2(reader io.Reader) (cMsg ConnMsg)

func ReadCMsgNotKeyJson added in v1.3.8

func ReadCMsgNotKeyJson(b []byte) (cMsg ConnMsg, err error)

func ReadCMsgNotKeyJson2 added in v1.3.8

func ReadCMsgNotKeyJson2(reader io.Reader) (cMsg ConnMsg, err error)

func (*ConnMsg) CheckConnMsgHeaderAndCode added in v1.3.1

func (cMsg *ConnMsg) CheckConnMsgHeaderAndCode(header string, code int) error

func (*ConnMsg) MustUnmarshal added in v1.3.3

func (cMsg *ConnMsg) MustUnmarshal(out any)

func (*ConnMsg) Unmarshal added in v1.3.3

func (cMsg *ConnMsg) Unmarshal(out any) error

type CtxCloser added in v1.3.7

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

func NewCtxCloser added in v1.3.7

func NewCtxCloser(ctx context.Context) *CtxCloser

func (*CtxCloser) AddCloseFn added in v1.3.7

func (cc *CtxCloser) AddCloseFn(fn func())

func (*CtxCloser) Chan added in v1.3.7

func (cc *CtxCloser) Chan() <-chan struct{}

func (*CtxCloser) CheckDone added in v1.3.7

func (cc *CtxCloser) CheckDone() bool

func (*CtxCloser) Close added in v1.3.7

func (cc *CtxCloser) Close()

type Key

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

func NewKey

func NewKey(key string) Key

func (*Key) Decode

func (k *Key) Decode(i interface{}, data []byte) error

func (*Key) Encode

func (k *Key) Encode(i interface{}) (b [][]byte)

func (*Key) GetRawKey added in v1.3.0

func (k *Key) GetRawKey() string

func (*Key) ReadCMsg added in v1.3.0

func (k *Key) ReadCMsg(reader *bufio.Reader, skip *atomic.Bool, speed *SpeedTicker) (cMsg ConnMsg, err error)

func (*Key) ReadCPacket added in v1.3.0

func (k *Key) ReadCPacket(reader *bufio.Reader, skip *atomic.Bool) (b []byte, err error)

func (*Key) SetMsg

func (k *Key) SetMsg(header, id string, code int, data interface{}) [][]byte
type LinkBox struct {
	// contains filtered or unexported fields
}
func NewLinkBox(rw io.ReadWriter, readrSize int, readFn LinkBoxRWFn, writeFn LinkBoxRWFn) *LinkBox

func (*LinkBox) ReadLinkBoxToWriter added in v1.3.5

func (lb *LinkBox) ReadLinkBoxToWriter(writer io.Writer, lock *sync.Mutex) error

ReadLinkBoxToWriter link -> other

func (*LinkBox) WriteLinkBoxFromReader added in v1.3.5

func (lb *LinkBox) WriteLinkBoxFromReader(reader *bufio.Reader) error

WriteLinkBoxFromReader link <- other

type LinkBoxRWFn added in v1.3.5

type LinkBoxRWFn func(reader *bufio.Reader) ([][]byte, error)

type MashBytes added in v1.2.1

type MashBytes struct {
	Data string `json:"go-CFC-Data"`
}

func MustBytesToBase64 added in v1.2.1

func MustBytesToBase64(b []byte) MashBytes

type NetworkSpeedTicker added in v1.3.0

type NetworkSpeedTicker struct {
	Upload   *SpeedTicker
	Download *SpeedTicker
}

func NewNetworkSpeedTicker added in v1.3.0

func NewNetworkSpeedTicker() NetworkSpeedTicker

func (*NetworkSpeedTicker) ToView added in v1.3.0

type NetworkSpeedView added in v1.3.0

type NetworkSpeedView struct {
	UploadSpeed       int
	DownloadSpeed     int
	UploadSpeedShow   string
	DownloadSpeedShow string
}

func CountAllNetworkSpeedView added in v1.3.0

func CountAllNetworkSpeedView(list ...NetworkSpeedView) NetworkSpeedView

type OdjClientInfo

type OdjClientInfo struct {
	Name      string
	Anonymity bool
}

type OdjErrMsg added in v1.3.5

type OdjErrMsg struct {
	ErrMsg string
}

func NewErrMsg added in v1.3.5

func NewErrMsg(pre string, err error) OdjErrMsg

type OdjIdList

type OdjIdList struct {
	IdList []string
}

type OdjMsg

type OdjMsg struct {
	Msg string
}

type OdjPing

type OdjPing struct {
	Name   string
	Ping   Ping
	Active bool
}

type OdjSubOpenReq added in v1.3.3

type OdjSubOpenReq struct {
	Type    string
	OdjName string
}

type OdjSubOpenResp added in v1.3.3

type OdjSubOpenResp struct {
	Tid  string
	Type string
}

type OdjSubReq added in v1.3.3

type OdjSubReq struct {
	Id      string
	SrcName string
	DstKey  string
	Addr    *net.TCPAddr
}

type OdjUP2PKId added in v1.3.6

type OdjUP2PKId struct {
	Id string
}

type OdjUP2PKName added in v1.3.6

type OdjUP2PKName struct {
	Name string
}

type OdjUP2PReq added in v1.3.6

type OdjUP2PReq struct {
	Id      string
	SrcName string
	Addr    *net.UDPAddr
}

type OdjUP2PResp added in v1.3.6

type OdjUP2PResp struct {
	Addr *net.UDPAddr
	Info *SubInfo
}

type OdjVPNLinkAddr added in v1.3.5

type OdjVPNLinkAddr struct {
	ConnType string
	Addr     string

	AddrInfo *VpnInfo
}

type Ping

type Ping struct {
	Ping time.Duration
}

type SpeedTicker added in v1.3.0

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

func (*SpeedTicker) Get added in v1.3.0

func (st *SpeedTicker) Get() int

func (*SpeedTicker) Set added in v1.3.0

func (st *SpeedTicker) Set(i int)

type SubInfo added in v1.3.3

type SubInfo struct {
	LocalName  string
	RemoteName string

	LocalIntranetAddr  *net.TCPAddr
	RemoteIntranetAddr *net.TCPAddr

	ULocalIntranetAddr  *net.UDPAddr
	URemoteIntranetAddr *net.UDPAddr

	LocalPublicAddr  *net.TCPAddr
	RemotePublicAddr *net.TCPAddr

	ULocalPublicAddr  *net.UDPAddr
	URemotePublicAddr *net.UDPAddr
}

type TaskCb added in v1.3.1

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

func (*TaskCb) KeepWaitCb added in v1.3.1

func (task *TaskCb) KeepWaitCb(timeout time.Duration, cb func(cMsg ConnMsg) error) (err error)

func (*TaskCb) NowaitCb added in v1.3.1

func (task *TaskCb) NowaitCb(cb func(cMsg ConnMsg) error) error

func (*TaskCb) OverTask added in v1.3.1

func (task *TaskCb) OverTask(err error)

func (*TaskCb) SetKeep added in v1.3.1

func (task *TaskCb) SetKeep(keep bool) *TaskCb

func (*TaskCb) WaitCb added in v1.3.1

func (task *TaskCb) WaitCb(timeout time.Duration, cb func(cMsg ConnMsg) error) (err error)

type TaskCbContext added in v1.3.1

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

func NewTaskContext added in v1.3.1

func NewTaskContext(rw io.ReadWriter, key Key) *TaskCbContext

func (*TaskCbContext) Close added in v1.3.3

func (tc *TaskCbContext) Close()

func (*TaskCbContext) NewTaskCb added in v1.3.1

func (tc *TaskCbContext) NewTaskCb(id string, fn func() error) *TaskCb

func (*TaskCbContext) NewTaskCbCMsg added in v1.3.1

func (tc *TaskCbContext) NewTaskCbCMsg(header string, code int, data interface{}) *TaskCb

func (*TaskCbContext) NewTaskCbCMsgNeedId added in v1.3.1

func (tc *TaskCbContext) NewTaskCbCMsgNeedId(header string, id string, code int, data interface{}) *TaskCb

func (*TaskCbContext) ReadCMsg added in v1.3.1

func (tc *TaskCbContext) ReadCMsg() error

func (*TaskCbContext) SetNoCb added in v1.3.1

func (tc *TaskCbContext) SetNoCb(fn func(cMsg ConnMsg))

func (*TaskCbContext) SetWriteLock added in v1.3.1

func (tc *TaskCbContext) SetWriteLock(lock *sync.Mutex)

func (*TaskCbContext) WriteCMsg added in v1.3.1

func (tc *TaskCbContext) WriteCMsg(header string, id string, code int, data interface{}) error

type VpnInfo added in v1.3.5

type VpnInfo struct {
	LinkConnType      string
	LinkRemoteAddrTcp *net.TCPAddr
	LinkLocalAddrTcp  *net.TCPAddr
	LinkRemoteAddrUdp *net.UDPAddr
	LinkLocalAddrUdp  *net.UDPAddr
	CopyConnType      string
	CopyRemoteAddrTcp *net.TCPAddr
	CopyLocalAddrTcp  *net.TCPAddr
	CopyRemoteAddrUdp *net.UDPAddr
	CopyLocalAddrUdp  *net.UDPAddr
}

Jump to

Keyboard shortcuts

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