protocol

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2014 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package protocol implements the Block Exchange Protocol.

Index

Constants

View Source
const (
	FlagDeleted    uint32 = 1 << 12
	FlagInvalid           = 1 << 13
	FlagDirectory         = 1 << 14
	FlagNoPermBits        = 1 << 15
)
View Source
const (
	FlagShareTrusted  uint32 = 1 << 0
	FlagShareReadOnly        = 1 << 1
	FlagIntroducer           = 1 << 2
	FlagShareBits            = 0x000000ff
)
View Source
const (
	BlockSize = 128 * 1024
)

Variables

View Source
var (
	ErrClusterHash = fmt.Errorf("configuration error: mismatched cluster hash")
	ErrClosed      = errors.New("connection closed")
)
View Source
var LocalDeviceID = DeviceID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

Functions

func HasPermissionBits

func HasPermissionBits(bits uint32) bool

func IsDeleted

func IsDeleted(bits uint32) bool

func IsDirectory

func IsDirectory(bits uint32) bool

func IsInvalid

func IsInvalid(bits uint32) bool

func TotalInOut

func TotalInOut() (uint64, uint64)

Types

type BlockInfo

type BlockInfo struct {
	Offset int64 // noencode (cache only)
	Size   uint32
	Hash   []byte // max:64
}

func (BlockInfo) AppendXDR

func (o BlockInfo) AppendXDR(bs []byte) []byte

func (*BlockInfo) DecodeXDR

func (o *BlockInfo) DecodeXDR(r io.Reader) error

func (BlockInfo) EncodeXDR

func (o BlockInfo) EncodeXDR(w io.Writer) (int, error)

func (BlockInfo) MarshalXDR

func (o BlockInfo) MarshalXDR() []byte

func (BlockInfo) String

func (b BlockInfo) String() string

func (*BlockInfo) UnmarshalXDR

func (o *BlockInfo) UnmarshalXDR(bs []byte) error

type CloseMessage

type CloseMessage struct {
	Reason string // max:1024
}

func (CloseMessage) AppendXDR

func (o CloseMessage) AppendXDR(bs []byte) []byte

func (*CloseMessage) DecodeXDR

func (o *CloseMessage) DecodeXDR(r io.Reader) error

func (CloseMessage) EncodeXDR

func (o CloseMessage) EncodeXDR(w io.Writer) (int, error)

func (CloseMessage) MarshalXDR

func (o CloseMessage) MarshalXDR() []byte

func (*CloseMessage) UnmarshalXDR

func (o *CloseMessage) UnmarshalXDR(bs []byte) error

type ClusterConfigMessage

type ClusterConfigMessage struct {
	ClientName    string   // max:64
	ClientVersion string   // max:64
	Folders       []Folder // max:64
	Options       []Option // max:64
}

func (ClusterConfigMessage) AppendXDR

func (o ClusterConfigMessage) AppendXDR(bs []byte) []byte

func (*ClusterConfigMessage) DecodeXDR

func (o *ClusterConfigMessage) DecodeXDR(r io.Reader) error

func (ClusterConfigMessage) EncodeXDR

func (o ClusterConfigMessage) EncodeXDR(w io.Writer) (int, error)

func (*ClusterConfigMessage) GetOption

func (o *ClusterConfigMessage) GetOption(key string) string

func (ClusterConfigMessage) MarshalXDR

func (o ClusterConfigMessage) MarshalXDR() []byte

func (*ClusterConfigMessage) UnmarshalXDR

func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error

type Connection

type Connection interface {
	ID() DeviceID
	Name() string
	Index(folder string, files []FileInfo) error
	IndexUpdate(folder string, files []FileInfo) error
	Request(folder string, name string, offset int64, size int) ([]byte, error)
	ClusterConfig(config ClusterConfigMessage)
	Statistics() Statistics
}

func NewConnection

func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress bool) Connection

type Device added in v0.10.0

type Device struct {
	ID              []byte // max:32
	Flags           uint32
	MaxLocalVersion uint64
}

func (Device) AppendXDR added in v0.10.0

func (o Device) AppendXDR(bs []byte) []byte

func (*Device) DecodeXDR added in v0.10.0

func (o *Device) DecodeXDR(r io.Reader) error

func (Device) EncodeXDR added in v0.10.0

func (o Device) EncodeXDR(w io.Writer) (int, error)

func (Device) MarshalXDR added in v0.10.0

func (o Device) MarshalXDR() []byte

func (*Device) UnmarshalXDR added in v0.10.0

func (o *Device) UnmarshalXDR(bs []byte) error

type DeviceID added in v0.10.0

type DeviceID [32]byte

func DeviceIDFromBytes added in v0.10.0

func DeviceIDFromBytes(bs []byte) DeviceID

func DeviceIDFromString added in v0.10.0

func DeviceIDFromString(s string) (DeviceID, error)

func NewDeviceID added in v0.10.0

func NewDeviceID(rawCert []byte) DeviceID

NewDeviceID generates a new device ID from the raw bytes of a certificate

func (DeviceID) Compare added in v0.10.0

func (n DeviceID) Compare(other DeviceID) int

func (DeviceID) Equals added in v0.10.0

func (n DeviceID) Equals(other DeviceID) bool

func (DeviceID) GoString added in v0.10.0

func (n DeviceID) GoString() string

func (*DeviceID) MarshalText added in v0.10.0

func (n *DeviceID) MarshalText() ([]byte, error)

func (DeviceID) String added in v0.10.0

func (n DeviceID) String() string

String returns the canonical string representation of the device ID

func (*DeviceID) UnmarshalText added in v0.10.0

func (n *DeviceID) UnmarshalText(bs []byte) error

type EmptyMessage

type EmptyMessage struct{}

func (EmptyMessage) AppendXDR

func (o EmptyMessage) AppendXDR(bs []byte) []byte

func (*EmptyMessage) DecodeXDR

func (o *EmptyMessage) DecodeXDR(r io.Reader) error

func (EmptyMessage) EncodeXDR

func (o EmptyMessage) EncodeXDR(w io.Writer) (int, error)

func (EmptyMessage) MarshalXDR

func (o EmptyMessage) MarshalXDR() []byte

func (*EmptyMessage) UnmarshalXDR

func (o *EmptyMessage) UnmarshalXDR(bs []byte) error

type FileInfo

type FileInfo struct {
	Name         string // max:8192
	Flags        uint32
	Modified     int64
	Version      uint64
	LocalVersion uint64
	Blocks       []BlockInfo
}

func (FileInfo) AppendXDR

func (o FileInfo) AppendXDR(bs []byte) []byte

func (*FileInfo) DecodeXDR

func (o *FileInfo) DecodeXDR(r io.Reader) error

func (FileInfo) EncodeXDR

func (o FileInfo) EncodeXDR(w io.Writer) (int, error)

func (FileInfo) IsDeleted

func (f FileInfo) IsDeleted() bool

func (FileInfo) IsInvalid

func (f FileInfo) IsInvalid() bool

func (FileInfo) MarshalXDR

func (o FileInfo) MarshalXDR() []byte

func (FileInfo) Size

func (f FileInfo) Size() (bytes int64)

func (FileInfo) String

func (f FileInfo) String() string

func (*FileInfo) UnmarshalXDR

func (o *FileInfo) UnmarshalXDR(bs []byte) error

type FileInfoTruncated

type FileInfoTruncated struct {
	Name         string // max:8192
	Flags        uint32
	Modified     int64
	Version      uint64
	LocalVersion uint64
	NumBlocks    uint32
}

Used for unmarshalling a FileInfo structure but skipping the actual block list

func (FileInfoTruncated) AppendXDR

func (o FileInfoTruncated) AppendXDR(bs []byte) []byte

func (*FileInfoTruncated) DecodeXDR

func (o *FileInfoTruncated) DecodeXDR(r io.Reader) error

func (FileInfoTruncated) EncodeXDR

func (o FileInfoTruncated) EncodeXDR(w io.Writer) (int, error)

func (FileInfoTruncated) IsDeleted

func (f FileInfoTruncated) IsDeleted() bool

func (FileInfoTruncated) IsInvalid

func (f FileInfoTruncated) IsInvalid() bool

func (FileInfoTruncated) MarshalXDR

func (o FileInfoTruncated) MarshalXDR() []byte

func (FileInfoTruncated) Size

func (f FileInfoTruncated) Size() int64

Returns a statistical guess on the size, not the exact figure

func (*FileInfoTruncated) UnmarshalXDR

func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error

type FileIntf

type FileIntf interface {
	Size() int64
	IsDeleted() bool
	IsInvalid() bool
}

type Folder added in v0.10.0

type Folder struct {
	ID      string   // max:64
	Devices []Device // max:64
}

func (Folder) AppendXDR added in v0.10.0

func (o Folder) AppendXDR(bs []byte) []byte

func (*Folder) DecodeXDR added in v0.10.0

func (o *Folder) DecodeXDR(r io.Reader) error

func (Folder) EncodeXDR added in v0.10.0

func (o Folder) EncodeXDR(w io.Writer) (int, error)

func (Folder) MarshalXDR added in v0.10.0

func (o Folder) MarshalXDR() []byte

func (*Folder) UnmarshalXDR added in v0.10.0

func (o *Folder) UnmarshalXDR(bs []byte) error

type IndexMessage

type IndexMessage struct {
	Folder string // max:64
	Files  []FileInfo
}

func (IndexMessage) AppendXDR

func (o IndexMessage) AppendXDR(bs []byte) []byte

func (*IndexMessage) DecodeXDR

func (o *IndexMessage) DecodeXDR(r io.Reader) error

func (IndexMessage) EncodeXDR

func (o IndexMessage) EncodeXDR(w io.Writer) (int, error)

func (IndexMessage) MarshalXDR

func (o IndexMessage) MarshalXDR() []byte

func (*IndexMessage) UnmarshalXDR

func (o *IndexMessage) UnmarshalXDR(bs []byte) error

type Model

type Model interface {
	// An index was received from the peer device
	Index(deviceID DeviceID, folder string, files []FileInfo)
	// An index update was received from the peer device
	IndexUpdate(deviceID DeviceID, folder string, files []FileInfo)
	// A request was made by the peer device
	Request(deviceID DeviceID, folder string, name string, offset int64, size int) ([]byte, error)
	// A cluster configuration message was received
	ClusterConfig(deviceID DeviceID, config ClusterConfigMessage)
	// The peer device closed the connection
	Close(deviceID DeviceID, err error)
}

type Option

type Option struct {
	Key   string // max:64
	Value string // max:1024
}

func (Option) AppendXDR

func (o Option) AppendXDR(bs []byte) []byte

func (*Option) DecodeXDR

func (o *Option) DecodeXDR(r io.Reader) error

func (Option) EncodeXDR

func (o Option) EncodeXDR(w io.Writer) (int, error)

func (Option) MarshalXDR

func (o Option) MarshalXDR() []byte

func (*Option) UnmarshalXDR

func (o *Option) UnmarshalXDR(bs []byte) error

type RequestMessage

type RequestMessage struct {
	Folder string // max:64
	Name   string // max:8192
	Offset uint64
	Size   uint32
}

func (RequestMessage) AppendXDR

func (o RequestMessage) AppendXDR(bs []byte) []byte

func (*RequestMessage) DecodeXDR

func (o *RequestMessage) DecodeXDR(r io.Reader) error

func (RequestMessage) EncodeXDR

func (o RequestMessage) EncodeXDR(w io.Writer) (int, error)

func (RequestMessage) MarshalXDR

func (o RequestMessage) MarshalXDR() []byte

func (*RequestMessage) UnmarshalXDR

func (o *RequestMessage) UnmarshalXDR(bs []byte) error

type ResponseMessage

type ResponseMessage struct {
	Data []byte
}

func (ResponseMessage) AppendXDR

func (o ResponseMessage) AppendXDR(bs []byte) []byte

func (*ResponseMessage) DecodeXDR

func (o *ResponseMessage) DecodeXDR(r io.Reader) error

func (ResponseMessage) EncodeXDR

func (o ResponseMessage) EncodeXDR(w io.Writer) (int, error)

func (ResponseMessage) MarshalXDR

func (o ResponseMessage) MarshalXDR() []byte

func (*ResponseMessage) UnmarshalXDR

func (o *ResponseMessage) UnmarshalXDR(bs []byte) error

type Statistics

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

Jump to

Keyboard shortcuts

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