Documentation ¶
Overview ¶
Package protocol implements the Block Exchange Protocol.
Index ¶
- Constants
- Variables
- func TotalInOut() (int64, int64)
- type BlockInfo
- func (o BlockInfo) AppendXDR(bs []byte) ([]byte, error)
- func (o *BlockInfo) DecodeXDR(r io.Reader) error
- func (o *BlockInfo) DecodeXDRFrom(xr *xdr.Reader) error
- func (o BlockInfo) EncodeXDR(w io.Writer) (int, error)
- func (o BlockInfo) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (b BlockInfo) IsEmpty() bool
- func (o BlockInfo) MarshalXDR() ([]byte, error)
- func (o BlockInfo) MustMarshalXDR() []byte
- func (b BlockInfo) String() string
- func (o *BlockInfo) UnmarshalXDR(bs []byte) error
- type CloseMessage
- func (o CloseMessage) AppendXDR(bs []byte) ([]byte, error)
- func (o *CloseMessage) DecodeXDR(r io.Reader) error
- func (o *CloseMessage) DecodeXDRFrom(xr *xdr.Reader) error
- func (o CloseMessage) EncodeXDR(w io.Writer) (int, error)
- func (o CloseMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o CloseMessage) MarshalXDR() ([]byte, error)
- func (o CloseMessage) MustMarshalXDR() []byte
- func (o *CloseMessage) UnmarshalXDR(bs []byte) error
- type ClusterConfigMessage
- func (o ClusterConfigMessage) AppendXDR(bs []byte) ([]byte, error)
- func (o *ClusterConfigMessage) DecodeXDR(r io.Reader) error
- func (o *ClusterConfigMessage) DecodeXDRFrom(xr *xdr.Reader) error
- func (o ClusterConfigMessage) EncodeXDR(w io.Writer) (int, error)
- func (o ClusterConfigMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o *ClusterConfigMessage) GetOption(key string) string
- func (o ClusterConfigMessage) MarshalXDR() ([]byte, error)
- func (o ClusterConfigMessage) MustMarshalXDR() []byte
- func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error
- type Compression
- type Connection
- type Counter
- type Device
- func (o Device) AppendXDR(bs []byte) ([]byte, error)
- func (o *Device) DecodeXDR(r io.Reader) error
- func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error
- func (o Device) EncodeXDR(w io.Writer) (int, error)
- func (o Device) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o Device) MarshalXDR() ([]byte, error)
- func (o Device) MustMarshalXDR() []byte
- func (o *Device) UnmarshalXDR(bs []byte) error
- type DeviceID
- type EmptyMessage
- func (o EmptyMessage) AppendXDR(bs []byte) ([]byte, error)
- func (o *EmptyMessage) DecodeXDR(r io.Reader) error
- func (o *EmptyMessage) DecodeXDRFrom(xr *xdr.Reader) error
- func (o EmptyMessage) EncodeXDR(w io.Writer) (int, error)
- func (o EmptyMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o EmptyMessage) MarshalXDR() ([]byte, error)
- func (o EmptyMessage) MustMarshalXDR() []byte
- func (o *EmptyMessage) UnmarshalXDR(bs []byte) error
- type FileInfo
- func (o FileInfo) AppendXDR(bs []byte) ([]byte, error)
- func (o *FileInfo) DecodeXDR(r io.Reader) error
- func (o *FileInfo) DecodeXDRFrom(xr *xdr.Reader) error
- func (o FileInfo) EncodeXDR(w io.Writer) (int, error)
- func (o FileInfo) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (f FileInfo) HasPermissionBits() bool
- func (f FileInfo) IsDeleted() bool
- func (f FileInfo) IsDirectory() bool
- func (f FileInfo) IsInvalid() bool
- func (f FileInfo) IsSymlink() bool
- func (o FileInfo) MarshalXDR() ([]byte, error)
- func (o FileInfo) MustMarshalXDR() []byte
- func (f FileInfo) Size() (bytes int64)
- func (f FileInfo) String() string
- func (o *FileInfo) UnmarshalXDR(bs []byte) error
- func (f FileInfo) WinsConflict(other FileInfo) bool
- type Folder
- func (o Folder) AppendXDR(bs []byte) ([]byte, error)
- func (o *Folder) DecodeXDR(r io.Reader) error
- func (o *Folder) DecodeXDRFrom(xr *xdr.Reader) error
- func (o Folder) EncodeXDR(w io.Writer) (int, error)
- func (o Folder) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o Folder) MarshalXDR() ([]byte, error)
- func (o Folder) MustMarshalXDR() []byte
- func (o *Folder) UnmarshalXDR(bs []byte) error
- type IndexMessage
- func (o IndexMessage) AppendXDR(bs []byte) ([]byte, error)
- func (o *IndexMessage) DecodeXDR(r io.Reader) error
- func (o *IndexMessage) DecodeXDRFrom(xr *xdr.Reader) error
- func (o IndexMessage) EncodeXDR(w io.Writer) (int, error)
- func (o IndexMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o IndexMessage) MarshalXDR() ([]byte, error)
- func (o IndexMessage) MustMarshalXDR() []byte
- func (o *IndexMessage) UnmarshalXDR(bs []byte) error
- type Model
- type Option
- func (o Option) AppendXDR(bs []byte) ([]byte, error)
- func (o *Option) DecodeXDR(r io.Reader) error
- func (o *Option) DecodeXDRFrom(xr *xdr.Reader) error
- func (o Option) EncodeXDR(w io.Writer) (int, error)
- func (o Option) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o Option) MarshalXDR() ([]byte, error)
- func (o Option) MustMarshalXDR() []byte
- func (o *Option) UnmarshalXDR(bs []byte) error
- type Ordering
- type RequestMessage
- func (o RequestMessage) AppendXDR(bs []byte) ([]byte, error)
- func (o *RequestMessage) DecodeXDR(r io.Reader) error
- func (o *RequestMessage) DecodeXDRFrom(xr *xdr.Reader) error
- func (o RequestMessage) EncodeXDR(w io.Writer) (int, error)
- func (o RequestMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o RequestMessage) MarshalXDR() ([]byte, error)
- func (o RequestMessage) MustMarshalXDR() []byte
- func (o *RequestMessage) UnmarshalXDR(bs []byte) error
- type ResponseMessage
- func (o ResponseMessage) AppendXDR(bs []byte) ([]byte, error)
- func (o *ResponseMessage) DecodeXDR(r io.Reader) error
- func (o *ResponseMessage) DecodeXDRFrom(xr *xdr.Reader) error
- func (o ResponseMessage) EncodeXDR(w io.Writer) (int, error)
- func (o ResponseMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
- func (o ResponseMessage) MarshalXDR() ([]byte, error)
- func (o ResponseMessage) MustMarshalXDR() []byte
- func (o *ResponseMessage) UnmarshalXDR(bs []byte) error
- type ShortID
- type Statistics
- type Vector
- func (a Vector) Compare(b Vector) Ordering
- func (v Vector) Concurrent(b Vector) bool
- func (v Vector) Copy() Vector
- func (v Vector) Counter(id ShortID) uint64
- func (v *Vector) DecodeXDRFrom(r xdrReader) error
- func (v Vector) EncodeXDRInto(w xdrWriter) (int, error)
- func (v Vector) Equal(b Vector) bool
- func (v Vector) GreaterEqual(b Vector) bool
- func (v Vector) LesserEqual(b Vector) bool
- func (v Vector) Merge(b Vector) Vector
- func (v Vector) Update(id ShortID) Vector
Constants ¶
const ( // BlockSize is the standard ata block size (128 KiB) BlockSize = 128 << 10 // MaxMessageLen is the largest message size allowed on the wire. (64 MiB) MaxMessageLen = 64 << 20 )
const ( FlagDeleted uint32 = 1 << 12 FlagInvalid = 1 << 13 FlagDirectory = 1 << 14 FlagNoPermBits = 1 << 15 FlagSymlink = 1 << 16 FlagSymlinkMissingTarget = 1 << 17 FlagsAll = (1 << 18) - 1 SymlinkTypeMask = FlagDirectory | FlagSymlinkMissingTarget )
FileInfo flags
const ( FlagFolderReadOnly uint32 = 1 << 0 FlagFolderIgnorePerms = 1 << 1 FlagFolderIgnoreDelete = 1 << 2 FlagFolderAll = 1<<3 - 1 )
ClusterConfigMessage.Folders flags
const ( FlagIntroducer = 1 << 2 )
ClusterConfigMessage.Folders.Devices flags
const ( // PingSendInterval is how often we make sure to send a message, by // triggering pings if necessary. PingSendInterval = 90 * time.Second // ReceiveTimeout is the longest we'll wait for a message from the other // side before closing the connection. ReceiveTimeout = 300 * time.Second )
const (
FlagIndexTemporary uint32 = 1 << iota
)
IndexMessage message flags (for IndexUpdate)
const (
FlagRequestTemporary uint32 = 1 << iota
)
Request message flags
Variables ¶
var ( ErrNoError error ErrGeneric = errors.New("generic error") ErrNoSuchFile = errors.New("no such file") ErrInvalid = errors.New("file is invalid") )
var ( ErrClosed = errors.New("connection closed") ErrTimeout = errors.New("read timeout") )
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 TotalInOut ¶
Types ¶
type BlockInfo ¶
func (BlockInfo) IsEmpty ¶ added in v0.12.4
IsEmpty returns true if the block is a full block of zeroes.
func (BlockInfo) MarshalXDR ¶
func (BlockInfo) MustMarshalXDR ¶
func (*BlockInfo) UnmarshalXDR ¶
type CloseMessage ¶
func (*CloseMessage) DecodeXDRFrom ¶
func (o *CloseMessage) DecodeXDRFrom(xr *xdr.Reader) error
func (CloseMessage) EncodeXDRInto ¶
func (o CloseMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
func (CloseMessage) MarshalXDR ¶
func (o CloseMessage) MarshalXDR() ([]byte, error)
func (CloseMessage) MustMarshalXDR ¶
func (o CloseMessage) MustMarshalXDR() []byte
func (*CloseMessage) UnmarshalXDR ¶
func (o *CloseMessage) UnmarshalXDR(bs []byte) error
type ClusterConfigMessage ¶
type ClusterConfigMessage struct { DeviceName string // max:64 ClientName string // max:64 ClientVersion string // max:64 Folders []Folder // max:1000000 Options []Option // max:64 }
func (ClusterConfigMessage) AppendXDR ¶
func (o ClusterConfigMessage) AppendXDR(bs []byte) ([]byte, error)
func (*ClusterConfigMessage) DecodeXDR ¶
func (o *ClusterConfigMessage) DecodeXDR(r io.Reader) error
func (*ClusterConfigMessage) DecodeXDRFrom ¶
func (o *ClusterConfigMessage) DecodeXDRFrom(xr *xdr.Reader) error
func (ClusterConfigMessage) EncodeXDR ¶
func (o ClusterConfigMessage) EncodeXDR(w io.Writer) (int, error)
func (ClusterConfigMessage) EncodeXDRInto ¶
func (o ClusterConfigMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
func (*ClusterConfigMessage) GetOption ¶
func (o *ClusterConfigMessage) GetOption(key string) string
func (ClusterConfigMessage) MarshalXDR ¶
func (o ClusterConfigMessage) MarshalXDR() ([]byte, error)
func (ClusterConfigMessage) MustMarshalXDR ¶
func (o ClusterConfigMessage) MustMarshalXDR() []byte
func (*ClusterConfigMessage) UnmarshalXDR ¶
func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error
type Compression ¶
type Compression int
const ( CompressMetadata Compression = iota // zero value is the default, default should be "metadata" CompressNever CompressAlways )
func (Compression) GoString ¶
func (c Compression) GoString() string
func (Compression) MarshalText ¶
func (c Compression) MarshalText() ([]byte, error)
func (Compression) String ¶
func (c Compression) String() string
func (*Compression) UnmarshalText ¶
func (c *Compression) UnmarshalText(bs []byte) error
type Connection ¶
type Connection interface { Start() ID() DeviceID Name() string Index(folder string, files []FileInfo, flags uint32, options []Option) error IndexUpdate(folder string, files []FileInfo, flags uint32, options []Option) error Request(folder string, name string, offset int64, size int, hash []byte, flags uint32, options []Option) ([]byte, error) ClusterConfig(config ClusterConfigMessage) Statistics() Statistics Closed() bool }
func NewConnection ¶
func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress Compression) Connection
type Device ¶
type Device struct { ID []byte // max:32 Name string // max:64 Addresses []string // max:64,2083 Compression uint32 CertName string // max:64 MaxLocalVersion int64 Flags uint32 Options []Option // max:64 }
func (Device) MarshalXDR ¶
func (Device) MustMarshalXDR ¶
func (*Device) UnmarshalXDR ¶
type DeviceID ¶
type DeviceID [32]byte
func DeviceIDFromBytes ¶
func DeviceIDFromString ¶
func NewDeviceID ¶
NewDeviceID generates a new device ID from the raw bytes of a certificate
func (*DeviceID) MarshalText ¶
func (*DeviceID) UnmarshalText ¶
type EmptyMessage ¶
type EmptyMessage struct{}
func (*EmptyMessage) DecodeXDRFrom ¶
func (o *EmptyMessage) DecodeXDRFrom(xr *xdr.Reader) error
func (EmptyMessage) EncodeXDRInto ¶
func (o EmptyMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
func (EmptyMessage) MarshalXDR ¶
func (o EmptyMessage) MarshalXDR() ([]byte, error)
func (EmptyMessage) MustMarshalXDR ¶
func (o EmptyMessage) MustMarshalXDR() []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 Vector LocalVersion int64 CachedSize int64 // noencode (cache only) Blocks []BlockInfo // max:1000000 }
func (FileInfo) HasPermissionBits ¶
func (FileInfo) IsDirectory ¶
func (FileInfo) MarshalXDR ¶
func (FileInfo) MustMarshalXDR ¶
func (*FileInfo) UnmarshalXDR ¶
func (FileInfo) WinsConflict ¶
WinsConflict returns true if "f" is the one to choose when it is in conflict with "other".
type Folder ¶
type Folder struct { ID string // max:256 Devices []Device // max:1000000 Flags uint32 Options []Option // max:64 }
func (Folder) MarshalXDR ¶
func (Folder) MustMarshalXDR ¶
func (*Folder) UnmarshalXDR ¶
type IndexMessage ¶
type IndexMessage struct { Folder string // max:256 Files []FileInfo // max:1000000 Flags uint32 Options []Option // max:64 }
func (*IndexMessage) DecodeXDRFrom ¶
func (o *IndexMessage) DecodeXDRFrom(xr *xdr.Reader) error
func (IndexMessage) EncodeXDRInto ¶
func (o IndexMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
func (IndexMessage) MarshalXDR ¶
func (o IndexMessage) MarshalXDR() ([]byte, error)
func (IndexMessage) MustMarshalXDR ¶
func (o IndexMessage) MustMarshalXDR() []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, flags uint32, options []Option) // An index update was received from the peer device IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) // A request was made by the peer device Request(deviceID DeviceID, folder string, name string, offset int64, hash []byte, flags uint32, options []Option, buf []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 ¶
func (Option) MarshalXDR ¶
func (Option) MustMarshalXDR ¶
func (*Option) UnmarshalXDR ¶
type RequestMessage ¶
type RequestMessage struct { Folder string // max:256 Name string // max:8192 Offset int64 Size int32 Hash []byte // max:64 Flags uint32 Options []Option // max:64 }
func (*RequestMessage) DecodeXDRFrom ¶
func (o *RequestMessage) DecodeXDRFrom(xr *xdr.Reader) error
func (RequestMessage) EncodeXDRInto ¶
func (o RequestMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
func (RequestMessage) MarshalXDR ¶
func (o RequestMessage) MarshalXDR() ([]byte, error)
func (RequestMessage) MustMarshalXDR ¶
func (o RequestMessage) MustMarshalXDR() []byte
func (*RequestMessage) UnmarshalXDR ¶
func (o *RequestMessage) UnmarshalXDR(bs []byte) error
type ResponseMessage ¶
func (*ResponseMessage) DecodeXDRFrom ¶
func (o *ResponseMessage) DecodeXDRFrom(xr *xdr.Reader) error
func (ResponseMessage) EncodeXDRInto ¶
func (o ResponseMessage) EncodeXDRInto(xw *xdr.Writer) (int, error)
func (ResponseMessage) MarshalXDR ¶
func (o ResponseMessage) MarshalXDR() ([]byte, error)
func (ResponseMessage) MustMarshalXDR ¶
func (o ResponseMessage) MustMarshalXDR() []byte
func (*ResponseMessage) UnmarshalXDR ¶
func (o *ResponseMessage) UnmarshalXDR(bs []byte) error
type Vector ¶
type Vector []Counter
The Vector type represents a version vector. The zero value is a usable version vector. The vector has slice semantics and some operations on it are "append-like" in that they may return the same vector modified, or v new allocated Vector with the modified contents.
func (Vector) Concurrent ¶
Concurrent returns true when the two vectors are concrurrent.
func (*Vector) DecodeXDRFrom ¶
DecodeXDRFrom decodes the XDR objects from the given reader into itself.
func (Vector) EncodeXDRInto ¶
EncodeXDRInto encodes the vector as an XDR object into the given XDR encoder.
func (Vector) GreaterEqual ¶
GreaterEqual returns true when the two vectors are equivalent or v is Greater than b.
func (Vector) LesserEqual ¶
LesserEqual returns true when the two vectors are equivalent or v is Lesser than b.