protocol

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagDeleted = 1 << 12
	FlagInvalid = 1 << 13
)

Variables

View Source
var ErrClosed = errors.New("Connection closed")
View Source
var ErrFieldLengthExceeded = errors.New("Raw bytes field size exceeds limit")

Functions

func WriteIndex

func WriteIndex(w io.Writer, idx []FileInfo) (int, error)

Types

type BlockInfo

type BlockInfo struct {
	Size uint32
	Hash []byte
}

type Connection

type Connection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(nodeID string, reader io.Reader, writer io.Writer, receiver Model) *Connection

func (*Connection) ID

func (c *Connection) ID() string

func (*Connection) Index

func (c *Connection) Index(idx []FileInfo)

Index writes the list of file information to the connected peer node

func (*Connection) Request

func (c *Connection) Request(name string, offset int64, size uint32, hash []byte) ([]byte, error)

Request returns the bytes for the specified block after fetching them from the connected peer.

func (*Connection) Statistics

func (c *Connection) Statistics() Statistics

type FileInfo

type FileInfo struct {
	Name     string
	Flags    uint32
	Modified int64
	Version  uint32
	Blocks   []BlockInfo
}

func ReadIndex

func ReadIndex(r io.Reader) ([]FileInfo, error)

type Model

type Model interface {
	// An index was received from the peer node
	Index(nodeID string, files []FileInfo)
	// An index update was received from the peer node
	IndexUpdate(nodeID string, files []FileInfo)
	// A request was made by the peer node
	Request(nodeID, name string, offset int64, size uint32, hash []byte) ([]byte, error)
	// The peer node closed the connection
	Close(nodeID string, err error)
}

type Statistics

type Statistics struct {
	At            time.Time
	InBytesTotal  int
	OutBytesTotal int
}

Jump to

Keyboard shortcuts

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