tool

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 20 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 (
	BufferSize = 4096
)

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

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 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 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 ErrConnIsNil = errors.New("conn is nil")
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 ErrHandshakeIsDad = 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 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 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 fastConn")
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 ErrSubIsDisable = errors.New("sub box is disable")
View Source
var ErrSubLocalAddrIsNil = errors.New("sub local addr is nil")
View Source
var ErrTimeout = errors.New("timeout")
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 NewId

func NewId(n int) (str string)

func Println

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

func UnmarshalV2

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

Types

type ConnMsg

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

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 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 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
}

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

	LocalPublicAddr  *net.TCPAddr
	RemotePublicAddr *net.TCPAddr
}

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

Jump to

Keyboard shortcuts

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