protocol

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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 {
	Length uint32
	Hash   []byte
}

type Connection

type Connection struct {
	sync.RWMutex

	ID string
	// contains filtered or unexported fields
}

func NewConnection

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

func (*Connection) Close

func (c *Connection) Close(err error)

func (*Connection) Index

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

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

func (*Connection) Ping

func (c *Connection) Ping() bool

func (*Connection) Request

func (c *Connection) Request(name string, offset uint64, 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

func (*Connection) Stop

func (c *Connection) Stop()

type FileInfo

type FileInfo struct {
	Name     string
	Flags    uint32
	Modified int64
	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 uint64, 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