sync

package
v0.0.0-...-8e980cd Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delta

type Delta struct {
	PublicKey      NodePublicKey
	Version        Version
	Value          []byte
	AttachedSecret []byte
	Signature      Signature
}

func DecodeDelta

func DecodeDelta(buf []byte) (*Delta, int, error)

func NewDelta

func NewDelta(publicKey NodePublicKey, version Version, value []byte, attachedSecret []byte, signature Signature) *Delta

func (*Delta) Encode

func (d *Delta) Encode(buf []byte) []byte

type Deltas

type Deltas []Delta

func DecodeDeltas

func DecodeDeltas(buf []byte) (Deltas, int, error)

func (Deltas) Encode

func (d Deltas) Encode(buf []byte) []byte

func (Deltas) Len

func (d Deltas) Len() int

Len implements sort.Interface.

func (Deltas) Less

func (d Deltas) Less(i int, j int) bool

Less implements sort.Interface.

func (Deltas) Swap

func (d Deltas) Swap(i int, j int)

Swap implements sort.Interface.

type Digest

type Digest struct {
	Nodes      DigestNodes `json:"nodes"`
	MaxVersion Version     `json:"max_version"`
}

func DecodeDigest

func DecodeDigest(buf []byte) (*Digest, int, error)

Decodes the given buffer to a digest, and returns the digest along with an integer representing how many bytes of the buffer was read

func NewDigest

func NewDigest() *Digest

func (*Digest) EncodeWithoutSender

func (d *Digest) EncodeWithoutSender(buf []byte, sender NodePublicKey) []byte

func (*Digest) IncrementNode

func (d *Digest) IncrementNode(node NodePublicKey) Version

func (*Digest) IntersectingNodes

func (d *Digest) IntersectingNodes(other *Digest) []NodePublicKey

func (*Digest) SubtractNodes

func (d *Digest) SubtractNodes(other *Digest) []NodePublicKey

func (*Digest) UpdateNode

func (d *Digest) UpdateNode(node NodePublicKey, version Version) Version

type DigestNodes

type DigestNodes map[NodePublicKey]Version

func (DigestNodes) MarshalJSON

func (d DigestNodes) MarshalJSON() ([]byte, error)

func (*DigestNodes) UnmarshalJSON

func (d *DigestNodes) UnmarshalJSON(b []byte) error

type Digests

type Digests map[NodePublicKey]*Digest

func (Digests) MarshalJSON

func (d Digests) MarshalJSON() ([]byte, error)

func (*Digests) UnmarshalJSON

func (d *Digests) UnmarshalJSON(b []byte) error

type Message

type Message struct {
	Value          []byte              `json:"value"`
	Signature      Signature           `json:"sig"`
	AttachedSecret device.SharedSecret `json:"attached_secret"`
}

func NewMessage

func NewMessage(value []byte, signature Signature, attachedSecret []byte) Message

type Model

type Model struct {
	Digests    Digests            `json:"digests"`
	PrivateKey ed25519.PrivateKey `json:"private_key"`
	PublicKey  NodePublicKey      `json:"public_key"`
	NodeStates ModelNodeStates    `json:"node_states"`
	Type       ModelType          `json:"type"`
}

func DecodeModelFromJSON

func DecodeModelFromJSON(data []byte) (*Model, error)

func NewModel

func NewModel(privateKey ed25519.PrivateKey, modelType ModelType) *Model

func (*Model) Delta

func (s *Model) Delta(digest *Digest) Deltas

func (*Model) Digest

func (s *Model) Digest() *Digest

func (*Model) EncodeToJSON

func (s *Model) EncodeToJSON() ([]byte, error)

func (*Model) Merge

func (s *Model) Merge(sender NodePublicKey, deltas Deltas) bool

func (*Model) NewMessage

func (s *Model) NewMessage(value []byte, attachedSecret device.SharedSecret) Version

func (*Model) NewPullPacket

func (model *Model) NewPullPacket() (*PullPacket, error)

func (*Model) NewPushPacket

func (model *Model) NewPushPacket(receiverPublicKey NodePublicKey, delta Deltas) *PushPacket

func (*Model) UpdateDigest

func (s *Model) UpdateDigest(baseNode, nodeToUpdate NodePublicKey, version Version) bool

func (*Model) UpdateDigests

func (s *Model) UpdateDigests(node NodePublicKey, digest *Digest) bool

type ModelNodeStates

type ModelNodeStates map[NodePublicKey]NodeState

func (ModelNodeStates) MarshalJSON

func (s ModelNodeStates) MarshalJSON() ([]byte, error)

func (*ModelNodeStates) UnmarshalJSON

func (s *ModelNodeStates) UnmarshalJSON(b []byte) error

type ModelType

type ModelType string
const (
	ModelTypeGroup ModelType = "group"
	ModelTypeLink  ModelType = "link"
)

type NodePublicKey

type NodePublicKey [32]byte

func DecodeNodePublicKey

func DecodeNodePublicKey(buf []byte) NodePublicKey

func ExtractNodePublicKey

func ExtractNodePublicKey(privateKey ed25519.PrivateKey) NodePublicKey

func (NodePublicKey) Encode

func (s NodePublicKey) Encode(buf []byte) []byte

func (NodePublicKey) Key

func (NodePublicKey) MarshalJSON

func (n NodePublicKey) MarshalJSON() ([]byte, error)

func (*NodePublicKey) UnmarshalJSON

func (k *NodePublicKey) UnmarshalJSON(b []byte) error

type NodeState

type NodeState map[Version]Message

func NewNodeState

func NewNodeState() NodeState

type PullPacket

type PullPacket struct {
	// contains filtered or unexported fields
}

func DecodePullPacket

func DecodePullPacket(buf []byte) (*PullPacket, error)

func (*PullPacket) Encode

func (packet *PullPacket) Encode() []byte

type PushPacket

type PushPacket struct {
	// contains filtered or unexported fields
}

func DecodePushPacket

func DecodePushPacket(buf []byte) (*PushPacket, error)

func (*PushPacket) Encode

func (packet *PushPacket) Encode() []byte

type Signature

type Signature []byte

func (Signature) Encode

func (s Signature) Encode(buf []byte) []byte

type Sync

type Sync struct {
	// contains filtered or unexported fields
}

func NewSync

func NewSync(events SyncEvents) *Sync

func (*Sync) ContactState

func (sync *Sync) ContactState(contact device.ContactID) ([]byte, error)

func (*Sync) DeleteContact

func (sync *Sync) DeleteContact(contact device.ContactID)

func (*Sync) HandlePullPacket

func (sync *Sync) HandlePullPacket(session device.SessionID, contact device.ContactID, publicKey NodePublicKey, digest *Digest) error

HandlePullPacket is called in a response to a pull packet

func (*Sync) HasContact

func (sync *Sync) HasContact(contact device.ContactID) bool

func (*Sync) LoadState

func (sync *Sync) LoadState(contact device.ContactID, state []byte) error

func (*Sync) MergePushPacket

func (sync *Sync) MergePushPacket(session device.SessionID, contact device.ContactID, pushPacket *PushPacket) error

func (*Sync) NewContact

func (sync *Sync) NewContact(contact device.ContactID, privateKey ed25519.PrivateKey, modelType ModelType) error

func (*Sync) NewMessage

func (sync *Sync) NewMessage(contact device.ContactID, body []byte, attachedSecret device.SharedSecret) error

func (*Sync) PullPacket

func (sync *Sync) PullPacket(contact device.ContactID) (*PullPacket, error)

func (*Sync) PushPacketDelivered

func (sync *Sync) PushPacketDelivered(contact device.ContactID, session device.SessionID, packet *PushPacket) error

func (*Sync) ReceiveSyncPacket

func (sync *Sync) ReceiveSyncPacket(contact device.ContactID, session device.SessionID, packet []byte) error

func (*Sync) SessionBroken

func (sync *Sync) SessionBroken(session device.SessionID)

type SyncEvents

type SyncEvents interface {
	PushSyncUpdates(contact device.ContactID, session device.SessionID, pushPacket *PushPacket)
	// DiscoverContact is called when there is an update to a contact with no currently active session.
	// A route request may be broadcasted in order to deliver the update if possible.
	DiscoverContact(contact device.ContactID)
	SyncStateChanged(contact device.ContactID, updatedState []byte)
	Log(message string)
}

type SyncPacketType

type SyncPacketType byte
const (
	SYNC_PULL SyncPacketType = iota
	SYNC_PUSH
)

type Version

type Version uint32

func DecodeVersion

func DecodeVersion(buf []byte) Version

func (Version) Encode

func (v Version) Encode(buf []byte) []byte

Jump to

Keyboard shortcuts

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