protocol

package
v0.0.0-...-6ac6f58 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULTTIMEOUTSECS        = 300
	DEFAULTREADALLTIMEOUTSECS = 600
)

define const vars for http client

Variables

View Source
var (
	SupportAbsPath = true
	DefaultWorkDir = ""
)
View Source
var (
	ErrorNotEnoughtBufData = fmt.Errorf("buf data of file is not enought")
)

Functions

func CheckAbsPathLimit

func CheckAbsPathLimit(f string) error

func DecodeBKCheckCache

func DecodeBKCheckCache(
	data []byte,
	head *protocol.PBHead,
	_ string,
	_ PathMapping,
	_ chan<- string) (*protocol.PBBodyCheckCacheReq, error)

ReceiveBKCheckCache receive check cache request and generate the body

func DecodeBKCommonDispatchReq

func DecodeBKCommonDispatchReq(
	data []byte,
	head *protocol.PBHead,
	basedir string,
	callback PathMapping,
	c chan<- string) (*protocol.PBBodyDispatchTaskReq, error)

func DecodeBKCommonDispatchReqBuf

func DecodeBKCommonDispatchReqBuf(
	data []byte,
	body *protocol.PBBodyDispatchTaskReq,
	buflen int64,
	basedir string,
	callback PathMapping,
	c chan<- string) error

func DecodeBKCommonHead

func DecodeBKCommonHead(data []byte) (*protocol.PBHead, int, error)

func DecodeBKSendFile

func DecodeBKSendFile(
	data []byte,
	head *protocol.PBHead,
	basedir string,
	callback PathMapping,
	c chan<- string,
	cm cache.Manager) (*protocol.PBBodySendFileReq, error)

func DecodeBKSendFileBuf

func DecodeBKSendFileBuf(
	data []byte,
	body *protocol.PBBodySendFileReq,
	buflen int64,
	basedir string,
	callback PathMapping,
	c chan<- string,
	cm cache.Manager) error

func DecodeUnknown

func DecodeUnknown(
	data []byte,
	head *protocol.PBHead,
	_ string,
	_ PathMapping) error

ReceiveUnknown to receive pb command body for unknown cmd

func EncodeBKCheckCacheRsp

func EncodeBKCheckCacheRsp(result []*protocol.PBCacheResult) ([]protocol.Message, error)

EncodeBKCheckCacheRsp encode result to Messages

func EncodeBKCommonDispatchRsp

func EncodeBKCommonDispatchRsp(results []*protocol.PBResult) ([]protocol.Message, error)

EncodeBKCommonDispatchRsp encode results to Messages

func EncodeBKQuerySlotRsp

func EncodeBKQuerySlotRsp(availableslotnum int32, refused int32, message string) ([]protocol.Message, error)

EncodeBKQuerySlotRsp encode time to Messages

func EncodeBKSendFileRsp

func EncodeBKSendFileRsp(req *protocol.PBBodySendFileReq) ([]protocol.Message, error)

EncodeBKSendFileRsp encode results to Messages

func EncodeBKSyncTimeRsp

func EncodeBKSyncTimeRsp(receivedtime time.Time) ([]protocol.Message, error)

EncodeBKSyncTimeRsp encode time to Messages

func EncodeBKUnknownRsp

func EncodeBKUnknownRsp(_ time.Time) ([]protocol.Message, error)

EncodeBKUnknownRsp encode time to Messages

func ReceiveBKCheckCache

func ReceiveBKCheckCache(client *TCPClient,
	head *protocol.PBHead,
	_ string,
	_ PathMapping,
	_ chan<- string) (*protocol.PBBodyCheckCacheReq, error)

ReceiveBKCheckCache receive check cache request and generate the body

func ReceiveBKCommonDispatchReq

func ReceiveBKCommonDispatchReq(client *TCPClient,
	head *protocol.PBHead,
	basedir string,
	callback PathMapping,
	c chan<- string) (*protocol.PBBodyDispatchTaskReq, error)

ReceiveBKCommonDispatchReq to receive pb command body for protocol.PBCmdType_DISPATCHTASKREQ

func ReceiveBKCommonHead

func ReceiveBKCommonHead(client *TCPClient) (*protocol.PBHead, error)

ReceiveBKCommonHead to receive pb command head

func ReceiveBKQuerySlot

func ReceiveBKQuerySlot(client *TCPClient,
	head *protocol.PBHead) (*protocol.PBBodyQuerySlotReq, error)

ReceiveBKQuerySlot to receive pb command body for query slot

func ReceiveBKSendFile

func ReceiveBKSendFile(client *TCPClient,
	head *protocol.PBHead,
	basedir string,
	callback PathMapping,
	c chan<- string,
	cm cache.Manager) (*protocol.PBBodySendFileReq, error)

ReceiveBKSendFile to receive pb command body for send file

func ReceiveBKSlotRspAck

func ReceiveBKSlotRspAck(client *TCPClient,
	head *protocol.PBHead) (*protocol.PBBodySlotRspAck, error)

ReceiveBKSlotRspAck to receive pb command body for slot offer ack

func ReceiveUnknown

func ReceiveUnknown(client *TCPClient,
	head *protocol.PBHead,
	_ string,
	_ PathMapping) error

ReceiveUnknown to receive pb command body for unknown cmd

func SendMessages

func SendMessages(client *TCPClient, messages *[]protocol.Message) error

SendMessages send messages back to client

Types

type PathMapping

type PathMapping func(inputfile string, basedir string, relativedir string) (string, string, error)

return relativepath, abspath, error

type TCPClient

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

TCPClient wrapper net.TCPConn

func NewTCPClientWithConn

func NewTCPClientWithConn(conn *net.TCPConn) *TCPClient

NewTCPClientWithConn return new TCPClient with specified conn

func (*TCPClient) Close

func (c *TCPClient) Close() error

Close close conn

func (*TCPClient) Closed

func (c *TCPClient) Closed() bool

Closed check if the TCP connection is closed

func (*TCPClient) Connect

func (c *TCPClient) Connect(server string) error

Connect connect to server

func (*TCPClient) ReadData

func (c *TCPClient) ReadData(expectlen int) ([]byte, int, error)

ReadData read data

func (*TCPClient) ReadUntilEOF

func (c *TCPClient) ReadUntilEOF() ([]byte, int, error)

ReadUntilEOF read data until EOF

func (*TCPClient) RemoteAddr

func (c *TCPClient) RemoteAddr() string

RemoteAddr return RemoteAddr

func (*TCPClient) RemoteIP

func (c *TCPClient) RemoteIP() string

RemoteIP return remote ip

func (*TCPClient) SendFile

func (c *TCPClient) SendFile(infile string, compress protocol.CompressType) error

SendFile send file

func (*TCPClient) TryReadData

func (c *TCPClient) TryReadData(expectlen int) ([]byte, int, error)

TryReadData try read data, return immediately after received any data

func (*TCPClient) WriteData

func (c *TCPClient) WriteData(data []byte) error

WriteData write data

Jump to

Keyboard shortcuts

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