protocol

package
v0.11.16 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2015 License: MIT, MPL-2.0 Imports: 20 Imported by: 0

README

The BEPv1 Protocol

Latest Build API Documentation MIT License

This is the protocol implementation used by Syncthing.

License

MIT

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
	FlagSymlink                     = 1 << 16
	FlagSymlinkMissingTarget        = 1 << 17

	FlagsAll = (1 << 18) - 1

	SymlinkTypeMask = FlagDirectory | FlagSymlinkMissingTarget
)

FileInfo flags

View Source
const (
	FlagShareTrusted  uint32 = 1 << 0
	FlagShareReadOnly        = 1 << 1
	FlagIntroducer           = 1 << 2
	FlagShareBits            = 0x000000ff
)

ClusterConfigMessage.Folders.Devices flags

View Source
const (
	BlockSize = 128 * 1024
)
View Source
const (
	FlagIndexTemporary uint32 = 1 << iota
)

IndexMessage message flags (for IndexUpdate)

View Source
const (
	FlagRequestTemporary uint32 = 1 << iota
)

Request message flags

Variables

View Source
var (
	ErrNoError    error = nil
	ErrGeneric          = errors.New("generic error")
	ErrNoSuchFile       = errors.New("no such file")
	ErrInvalid          = errors.New("file is invalid")
)
View Source
var (
	ErrClusterHash = fmt.Errorf("configuration error: mismatched cluster hash")
	ErrClosed      = errors.New("connection closed")
)
View Source
var (
	PingTimeout  = 30 * time.Second
	PingIdleTime = 60 * time.Second
)
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 TotalInOut

func TotalInOut() (int64, int64)

Types

type BlockInfo

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

func (BlockInfo) AppendXDR

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

func (*BlockInfo) DecodeXDR

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

func (*BlockInfo) DecodeXDRFrom added in v0.11.0

func (o *BlockInfo) DecodeXDRFrom(xr *xdr.Reader) error

func (BlockInfo) EncodeXDR

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

func (BlockInfo) EncodeXDRInto added in v0.11.0

func (o BlockInfo) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (BlockInfo) MarshalXDR

func (o BlockInfo) MarshalXDR() ([]byte, error)

func (BlockInfo) MustMarshalXDR

func (o BlockInfo) MustMarshalXDR() []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
	Code   int32
}

func (CloseMessage) AppendXDR

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

func (*CloseMessage) DecodeXDR

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

func (*CloseMessage) DecodeXDRFrom added in v0.11.0

func (o *CloseMessage) DecodeXDRFrom(xr *xdr.Reader) error

func (CloseMessage) EncodeXDR

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

func (CloseMessage) EncodeXDRInto added in v0.11.0

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 {
	ClientName    string // max:64
	ClientVersion string // max:64
	Folders       []Folder
	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 added in v0.11.0

func (o *ClusterConfigMessage) DecodeXDRFrom(xr *xdr.Reader) error

func (ClusterConfigMessage) EncodeXDR

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

func (ClusterConfigMessage) EncodeXDRInto added in v0.11.0

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 added in v0.10.26

type Compression int
const (
	CompressMetadata Compression = iota // zero value is the default, default should be "metadata"
	CompressNever
	CompressAlways
)

func (Compression) GoString added in v0.10.26

func (c Compression) GoString() string

func (Compression) MarshalText added in v0.10.26

func (c Compression) MarshalText() ([]byte, error)

func (Compression) String added in v0.10.26

func (c Compression) String() string

func (*Compression) UnmarshalText added in v0.10.26

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
}

func NewConnection

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

type Counter added in v0.11.0

type Counter struct {
	ID    uint64
	Value uint64
}

Counter represents a single counter in the version vector.

type Device

type Device struct {
	ID              []byte // max:32
	MaxLocalVersion int64
	Flags           uint32
	Options         []Option // max:64
}

func (Device) AppendXDR

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

func (*Device) DecodeXDR

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

func (*Device) DecodeXDRFrom added in v0.11.0

func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error

func (Device) EncodeXDR

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

func (Device) EncodeXDRInto added in v0.11.0

func (o Device) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Device) MarshalXDR

func (o Device) MarshalXDR() ([]byte, error)

func (Device) MustMarshalXDR

func (o Device) MustMarshalXDR() []byte

func (*Device) UnmarshalXDR

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

type DeviceID

type DeviceID [32]byte

func DeviceIDFromBytes

func DeviceIDFromBytes(bs []byte) DeviceID

func DeviceIDFromString

func DeviceIDFromString(s string) (DeviceID, error)

func NewDeviceID

func NewDeviceID(rawCert []byte) DeviceID

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

func (DeviceID) Compare

func (n DeviceID) Compare(other DeviceID) int

func (DeviceID) Equals

func (n DeviceID) Equals(other DeviceID) bool

func (DeviceID) GoString

func (n DeviceID) GoString() string

func (*DeviceID) MarshalText

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

func (DeviceID) Short added in v0.11.0

func (n DeviceID) Short() uint64

Short returns an integer representing bits 0-63 of the device ID.

func (DeviceID) String

func (n DeviceID) String() string

String returns the canonical string representation of the device ID

func (*DeviceID) UnmarshalText

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

type EmptyMessage

type EmptyMessage struct{}

func (EmptyMessage) AppendXDR

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

func (*EmptyMessage) DecodeXDR

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

func (*EmptyMessage) DecodeXDRFrom added in v0.11.0

func (o *EmptyMessage) DecodeXDRFrom(xr *xdr.Reader) error

func (EmptyMessage) EncodeXDR

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

func (EmptyMessage) EncodeXDRInto added in v0.11.0

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
	Blocks       []BlockInfo
}

func (FileInfo) AppendXDR

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

func (*FileInfo) DecodeXDR

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

func (*FileInfo) DecodeXDRFrom added in v0.11.0

func (o *FileInfo) DecodeXDRFrom(xr *xdr.Reader) error

func (FileInfo) EncodeXDR

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

func (FileInfo) EncodeXDRInto added in v0.11.0

func (o FileInfo) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (FileInfo) HasPermissionBits

func (f FileInfo) HasPermissionBits() bool

func (FileInfo) IsDeleted

func (f FileInfo) IsDeleted() bool

func (FileInfo) IsDirectory

func (f FileInfo) IsDirectory() bool

func (FileInfo) IsInvalid

func (f FileInfo) IsInvalid() bool
func (f FileInfo) IsSymlink() bool

func (FileInfo) MarshalXDR

func (o FileInfo) MarshalXDR() ([]byte, error)

func (FileInfo) MustMarshalXDR

func (o FileInfo) MustMarshalXDR() []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 Folder

type Folder struct {
	ID      string // max:64
	Devices []Device
	Flags   uint32
	Options []Option // max:64
}

func (Folder) AppendXDR

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

func (*Folder) DecodeXDR

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

func (*Folder) DecodeXDRFrom added in v0.11.0

func (o *Folder) DecodeXDRFrom(xr *xdr.Reader) error

func (Folder) EncodeXDR

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

func (Folder) EncodeXDRInto added in v0.11.0

func (o Folder) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Folder) MarshalXDR

func (o Folder) MarshalXDR() ([]byte, error)

func (Folder) MustMarshalXDR

func (o Folder) MustMarshalXDR() []byte

func (*Folder) UnmarshalXDR

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

type IndexMessage

type IndexMessage struct {
	Folder  string
	Files   []FileInfo
	Flags   uint32
	Options []Option // max:64
}

func (IndexMessage) AppendXDR

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

func (*IndexMessage) DecodeXDR

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

func (*IndexMessage) DecodeXDRFrom added in v0.11.0

func (o *IndexMessage) DecodeXDRFrom(xr *xdr.Reader) error

func (IndexMessage) EncodeXDR

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

func (IndexMessage) EncodeXDRInto added in v0.11.0

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, size int, hash []byte, flags uint32, options []Option) ([]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, error)

func (*Option) DecodeXDR

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

func (*Option) DecodeXDRFrom added in v0.11.0

func (o *Option) DecodeXDRFrom(xr *xdr.Reader) error

func (Option) EncodeXDR

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

func (Option) EncodeXDRInto added in v0.11.0

func (o Option) EncodeXDRInto(xw *xdr.Writer) (int, error)

func (Option) MarshalXDR

func (o Option) MarshalXDR() ([]byte, error)

func (Option) MustMarshalXDR

func (o Option) MustMarshalXDR() []byte

func (*Option) UnmarshalXDR

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

type Ordering added in v0.11.0

type Ordering int

Ordering represents the relationship between two Vectors.

const (
	Equal Ordering = iota
	Greater
	Lesser
	ConcurrentLesser
	ConcurrentGreater
)

type RequestMessage

type RequestMessage struct {
	Folder  string // max:64
	Name    string // max:8192
	Offset  int64
	Size    int32
	Hash    []byte // max:64
	Flags   uint32
	Options []Option // max:64
}

func (RequestMessage) AppendXDR

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

func (*RequestMessage) DecodeXDR

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

func (*RequestMessage) DecodeXDRFrom added in v0.11.0

func (o *RequestMessage) DecodeXDRFrom(xr *xdr.Reader) error

func (RequestMessage) EncodeXDR

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

func (RequestMessage) EncodeXDRInto added in v0.11.0

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

type ResponseMessage struct {
	Data []byte
	Code int32
}

func (ResponseMessage) AppendXDR

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

func (*ResponseMessage) DecodeXDR

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

func (*ResponseMessage) DecodeXDRFrom added in v0.11.0

func (o *ResponseMessage) DecodeXDRFrom(xr *xdr.Reader) error

func (ResponseMessage) EncodeXDR

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

func (ResponseMessage) EncodeXDRInto added in v0.11.0

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 Statistics

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

type Vector added in v0.11.0

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 a new allocated Vector with the modified contents.

func (Vector) Compare added in v0.11.0

func (a Vector) Compare(b Vector) Ordering

Compare returns the Ordering that describes a's relation to b.

func (Vector) Concurrent added in v0.11.0

func (a Vector) Concurrent(b Vector) bool

Concurrent returns true when the two vectors are concrurrent.

func (Vector) Copy added in v0.11.0

func (v Vector) Copy() Vector

Copy returns an identical vector that is not shared with v.

func (Vector) Counter added in v0.11.0

func (v Vector) Counter(id uint64) uint64

Counter returns the current value of the given counter ID.

func (*Vector) DecodeXDRFrom added in v0.11.0

func (v *Vector) DecodeXDRFrom(r xdrReader) error

DecodeXDRFrom decodes the XDR objects from the given reader into itself.

func (Vector) EncodeXDRInto added in v0.11.0

func (v Vector) EncodeXDRInto(w xdrWriter) (int, error)

EncodeXDRInto encodes the vector as an XDR object into the given XDR encoder.

func (Vector) Equal added in v0.11.0

func (a Vector) Equal(b Vector) bool

Equal returns true when the two vectors are equivalent.

func (Vector) GreaterEqual added in v0.11.0

func (a Vector) GreaterEqual(b Vector) bool

LesserEqual returns true when the two vectors are equivalent or a is Greater than b.

func (Vector) LesserEqual added in v0.11.0

func (a Vector) LesserEqual(b Vector) bool

LesserEqual returns true when the two vectors are equivalent or a is Lesser than b.

func (Vector) Merge added in v0.11.0

func (a Vector) Merge(b Vector) Vector

Merge returns the vector containing the maximum indexes from a and b. If it is possible, the vector a is updated and returned. If it is not, a copy will be created, updated and returned.

func (Vector) Update added in v0.11.0

func (v Vector) Update(ID uint64) Vector

Update returns a Vector with the index for the specific ID incremented by one. If it is possible, the vector v is updated and returned. If it is not, a copy will be created, updated and returned.

Jump to

Keyboard shortcuts

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