transfer

package
v0.0.0-...-dc791d1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Transfer uses kcp to transport data betwween kcp client and server. By default, transfer split data into specified size trunck, and append md5 checksum after data. The recv side read data from network, check received data, append it to the output buffer(file). If there's anything wrong with the received data, transfer will ask the other side to resend the failed part. After receiving all the data, transfer will recheck all the recevied data with md5 again to make sure data completeness.

Index

Constants

View Source
const (
	TIMEOUT    = 30 * time.Second
	BLOCK_SIZE = 1024 * 16
	ASK_WND    = 5
)

Variables

This section is empty.

Functions

func AppendConfig

func AppendConfig(file *os.File, index uint32)

func BinaryCompare

func BinaryCompare(a, b []byte) int

func CheckSum

func CheckSum(data []byte) []byte

func ChooseName

func ChooseName(name string) (string, bool)

func CloseFiles

func CloseFiles(files ...*os.File)

func ConfigName

func ConfigName(name string) string

func EncodeMesg

func EncodeMesg(mesg *msg.Transfer) ([]byte, error)

func FillFile

func FillFile(file *os.File, total uint32) error

func FlushFile

func FlushFile(file, cfile *os.File, idx, pos uint32, data []byte, signal chan error)

func LoadConfig

func LoadConfig(cfile *os.File, point *EndPoint) (bool, error)

func OpenConfigName

func OpenConfigName(name string) (*os.File, error)

func ParseInitMesg

func ParseInitMesg(init *msg.SendInit, point *EndPoint) (bool, error)

func ReadConfig

func ReadConfig(file *os.File) ([]byte, error)

func ReadData

func ReadData(store []byte, sock Pipe) error

func ReadFile

func ReadFile(file *os.File, pos int, buffer []byte) (int, error)

func ReadHeader

func ReadHeader(store []byte, sock Pipe) (uint32, error)

func ReadMessage

func ReadMessage(dlen uint32, sock Pipe) ([]byte, error)

func RecvFile

func RecvFile(name string, dest string, raddr string) error

func RecvFileProc

func RecvFileProc(point *EndPoint, file, cfile *os.File, fill bool) error

func SendFile

func SendFile(name string, raddr string) error

func SendFileProc

func SendFileProc(point *EndPoint, info os.FileInfo, file *os.File) error

func Serve

func Serve(host string, dest string) error

func WriteConfig

func WriteConfig(cfile *os.File, point *EndPoint) error

Types

type EndPoint

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

func NewEndPoint

func NewEndPoint(id uint32, sock Pipe) *EndPoint

func (*EndPoint) AskIndex

func (end *EndPoint) AskIndex(size int) []uint32

func (*EndPoint) AskPartial

func (end *EndPoint) AskPartial(index []uint32) error

func (*EndPoint) Decode

func (end *EndPoint) Decode(data []byte) error

func (*EndPoint) Encode

func (end *EndPoint) Encode() []byte

func (*EndPoint) Error

func (end *EndPoint) Error(code uint32) error

func (*EndPoint) ReadMessageTimeout

func (end *EndPoint) ReadMessageTimeout(timeout time.Duration) (*msg.Transfer, error)

func (*EndPoint) RecvInit

func (end *EndPoint) RecvInit(name string, total, block, cnt uint32) error

func (*EndPoint) SendInit

func (end *EndPoint) SendInit(info os.FileInfo, timeout time.Duration) error

func (*EndPoint) SendPartial

func (end *EndPoint) SendPartial(index uint32, data []byte) error

func (*EndPoint) SetInfo

func (end *EndPoint) SetInfo(total, block, cnt uint32)

type Pipe

type Pipe interface {
	Write(data []byte) error
	Read(store []byte) (int, error)
}

Jump to

Keyboard shortcuts

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