docs

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

docs

This directory is the Go port of the iroh-docs sync protocol — multi-writer key-value documents with range-based set reconciliation. It is a protocol package, not project documentation.

For project documentation, see the main README and the package reference at pkg.go.dev/github.com/tmc/go-iroh.

Documentation

Overview

Package docs implements Rust-compatible iroh-docs data and sync protocols.

The package currently covers the stable value types used to share document capabilities out of band, an in-memory entry store, the iroh-docs sync protocol over an iroh Router, and live synchronization over iroh-gossip.

Keys form a prefix hierarchy per author: an entry shadows every entry of the same author whose key it is a prefix of and whose record is not newer, so writing "menu" removes "menu/tea". See MemoryStore.Put.

The Go API is not stable before v1 and may change in any v0 release; the wire format tracks pinned upstream iroh-docs releases and does not.

Index

Examples

Constants

View Source
const ALPN = "/iroh-sync/1"

ALPN is the Rust iroh-docs sync protocol name.

View Source
const MaxTimestampFutureShift = 10 * 60 * uint64(time.Second/time.Microsecond)

MaxTimestampFutureShift is the maximum accepted future timestamp in microseconds. It bounds entries arriving from a peer only: conflicts are resolved by timestamp, so an entry dated arbitrarily far ahead would win every later write to its key and that key's subtree. Entries already in a store are left as they are.

View Source
const (
	// TicketKind is the string prefix for iroh-docs tickets.
	TicketKind = "doc"
)

Variables

This section is empty.

Functions

func Register

func Register(r *endpointticket.Registry) error

Register registers the document ticket decoder in r.

func SyncErrors

func SyncErrors(results []SyncResult) error

SyncErrors returns the joined errors in results.

Types

type AbortReason

type AbortReason uint64

AbortReason is the reason an accepting peer declined a sync request.

const (
	// AbortNotFound means the namespace is not available.
	AbortNotFound AbortReason = iota
	// AbortAlreadySyncing means the namespace is already syncing.
	AbortAlreadySyncing
	// AbortInternalServerError means the accepting peer hit an internal error.
	AbortInternalServerError
)

type Author

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

Author is a secret author key used to sign document entries.

func GenerateAuthor

func GenerateAuthor() (Author, error)

GenerateAuthor generates a random Author.

func NewAuthor

func NewAuthor(seed [32]byte) Author

NewAuthor returns an Author from a 32-byte secret seed.

func (Author) Bytes

func (a Author) Bytes() [32]byte

Bytes returns the 32-byte secret seed.

func (*Author) DecodePostcard

func (a *Author) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes a as Rust Author.

func (Author) EncodePostcard

func (a Author) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes a as Rust Author.

func (Author) ID

func (a Author) ID() AuthorID

ID returns the public author identifier.

func (Author) Sign

func (a Author) Sign(msg []byte) key.Signature

Sign signs msg with the author key.

func (Author) String

func (a Author) String() string

String returns the lowercase hex secret seed.

type AuthorID

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

AuthorID identifies an Author.

func NewAuthorID

func NewAuthorID(b [32]byte) (AuthorID, error)

NewAuthorID constructs an AuthorID from raw public-key bytes.

func (AuthorID) Bytes

func (id AuthorID) Bytes() [32]byte

Bytes returns the 32-byte public key.

func (*AuthorID) DecodePostcard

func (id *AuthorID) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes id as Rust AuthorId.

func (AuthorID) EncodePostcard

func (id AuthorID) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes id as Rust AuthorId.

func (AuthorID) EndpointID

func (id AuthorID) EndpointID() key.EndpointID

EndpointID returns id as an iroh endpoint identifier.

func (AuthorID) String

func (id AuthorID) String() string

String returns the lowercase hex public key.

func (AuthorID) Verify

func (id AuthorID) Verify(msg []byte, sig key.Signature) error

Verify verifies sig over msg with id.

type Capability

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

Capability is read or write access to a document namespace.

func CapabilityFromRaw

func CapabilityFromRaw(kind uint8, b [32]byte) (Capability, error)

CapabilityFromRaw constructs a Capability from Rust's raw representation.

func NewReadCapability

func NewReadCapability(id NamespaceID) Capability

NewReadCapability returns a read-only namespace capability.

func NewWriteCapability

func NewWriteCapability(secret NamespaceSecret) Capability

NewWriteCapability returns a writable namespace capability.

func (Capability) Kind

func (c Capability) Kind() CapabilityKind

Kind returns c's capability kind.

func (Capability) NamespaceID

func (c Capability) NamespaceID() NamespaceID

NamespaceID returns the namespace id for c.

func (Capability) Raw

func (c Capability) Raw() (uint8, [32]byte)

Raw returns Rust's raw capability representation.

func (Capability) Secret

func (c Capability) Secret() (NamespaceSecret, bool)

Secret returns the namespace secret and whether c is writable.

type CapabilityKind

type CapabilityKind uint8

CapabilityKind identifies a document namespace capability.

const (
	// CapabilityWrite is a writable namespace capability.
	CapabilityWrite CapabilityKind = 1
	// CapabilityRead is a read-only namespace capability.
	CapabilityRead CapabilityKind = 2
)

type ContentStatus

type ContentStatus uint64

ContentStatus reports whether entry content is locally available.

const (
	// ContentComplete means the content is fully available.
	ContentComplete ContentStatus = iota
	// ContentIncomplete means the content is partially available.
	ContentIncomplete
	// ContentMissing means the content is missing.
	ContentMissing
)

type DocTicket

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

DocTicket contains a document capability and bootstrap nodes.

func DecodeBytes

func DecodeBytes(b []byte) (DocTicket, error)

DecodeBytes decodes the postcard bytes of a document ticket.

func DecodeString

func DecodeString(s string) (DocTicket, error)

DecodeString parses s as a document ticket.

func NewTicket

func NewTicket(capability Capability, nodes []netaddr.EndpointAddr) DocTicket

NewTicket returns a document ticket for capability and nodes.

func ParseTicket

func ParseTicket(s string) (DocTicket, error)

ParseTicket parses s as a document ticket.

func (DocTicket) Capability

func (t DocTicket) Capability() Capability

Capability returns the ticket's document capability.

func (DocTicket) EncodeBytes

func (t DocTicket) EncodeBytes() []byte

EncodeBytes returns the Rust-compatible postcard ticket payload.

func (DocTicket) EncodeString

func (t DocTicket) EncodeString() string

EncodeString returns the canonical ticket string.

func (DocTicket) Kind

func (t DocTicket) Kind() string

Kind returns the ticket kind prefix.

func (DocTicket) MarshalText

func (t DocTicket) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (DocTicket) Nodes

func (t DocTicket) Nodes() []netaddr.EndpointAddr

Nodes returns the ticket's bootstrap nodes.

func (DocTicket) Short

func (t DocTicket) Short() DocTicket

Short returns a ticket containing only endpoint ids and relay URLs.

func (DocTicket) String

func (t DocTicket) String() string

String returns the canonical ticket string.

func (*DocTicket) UnmarshalText

func (t *DocTicket) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type DownloadPolicy

type DownloadPolicy struct {
	// IncludePrefixes, when non-empty, allows only keys with one of these prefixes.
	IncludePrefixes []string
	// ExcludePrefixes rejects keys with one of these prefixes.
	ExcludePrefixes []string
	// IncludeGlobs, when non-empty, allows only keys matching one of these globs.
	IncludeGlobs []string
	// ExcludeGlobs rejects keys matching one of these globs.
	ExcludeGlobs []string
}

DownloadPolicy selects document entry keys for live-sync content downloads.

type Entry

type Entry struct {
	ID     RecordIdentifier
	Record Record
}

Entry is a single document entry.

func NewEntry

func NewEntry(id RecordIdentifier, record Record) Entry

NewEntry returns an entry from id and record.

func (Entry) Author

func (e Entry) Author() AuthorID

Author returns the entry author.

func (Entry) Compare

func (e Entry) Compare(other Entry) int

Compare compares e and other by identifier and record.

func (Entry) ContentHash

func (e Entry) ContentHash() blobs.Hash

ContentHash returns the content hash.

func (Entry) ContentLen

func (e Entry) ContentLen() uint64

ContentLen returns the content length.

func (*Entry) DecodePostcard

func (e *Entry) DecodePostcard(dec *postcard.Decoder) error

DecodePostcard decodes e as Rust Entry.

func (Entry) Encode

func (e Entry) Encode() []byte

Encode returns the canonical entry bytes used for signatures.

func (Entry) EncodePostcard

func (e Entry) EncodePostcard(enc *postcard.Encoder) error

EncodePostcard encodes e as Rust Entry.

func (Entry) Key

func (e Entry) Key() []byte

Key returns the entry key.

func (Entry) Namespace

func (e Entry) Namespace() NamespaceID

Namespace returns the entry namespace.

func (Entry) Timestamp

func (e Entry) Timestamp() uint64

Timestamp returns the entry timestamp.

func (Entry) ValidateEmpty

func (e Entry) ValidateEmpty() error

ValidateEmpty validates the empty-record invariant.

type EntrySignature

type EntrySignature struct {
	Author    key.Signature
	Namespace key.Signature
}

EntrySignature is the namespace and author signatures for an entry.

func SignEntry

func SignEntry(entry Entry, namespace NamespaceSecret, author Author) EntrySignature

SignEntry returns the Rust-compatible signatures for entry.

func (*EntrySignature) DecodePostcard

func (sig *EntrySignature) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes sig as Rust EntrySignature.

func (EntrySignature) EncodePostcard

func (sig EntrySignature) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes sig as Rust EntrySignature.

func (EntrySignature) Verify

func (sig EntrySignature) Verify(entry Entry, namespace NamespaceID, author AuthorID) error

Verify verifies sig over entry.

type Fingerprint

type Fingerprint [32]byte

Fingerprint is a range-reconciliation fingerprint.

func EmptyFingerprint

func EmptyFingerprint() Fingerprint

EmptyFingerprint returns the fingerprint of the empty set.

func (*Fingerprint) Xor

func (f *Fingerprint) Xor(other Fingerprint)

Xor assigns f to the bytewise xor of f and other.

type Handler

type Handler struct {
	Store     *MemoryStore
	BlobStore blobs.Store
	Config    SyncConfig
	// Allow reports whether peer may sync namespace. A nil Allow authorizes
	// every peer for every namespace.
	Allow         func(NamespaceID, key.EndpointID) bool
	Validate      func(SignedEntry, ContentStatus) bool
	OnInsert      func(SignedEntry, ContentStatus)
	ContentStatus func(SignedEntry) ContentStatus
}

Handler handles incoming iroh-docs sync streams.

func (*Handler) Accept

func (h *Handler) Accept(ctx context.Context, conn *iroh.Conn) error

Accept handles one incoming iroh-docs connection.

type InsertOrigin

type InsertOrigin struct {
	Kind          InsertOriginKind
	From          key.EndpointID
	ContentStatus ContentStatus
}

InsertOrigin describes where an inserted entry came from.

type InsertOriginKind

type InsertOriginKind uint8

InsertOriginKind tags the origin of a store insert.

const (
	// InsertOriginLocal means the entry was inserted locally.
	InsertOriginLocal InsertOriginKind = iota
	// InsertOriginRemote means the entry came from a peer.
	InsertOriginRemote
)

type InsertOutcome

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

InsertOutcome reports the result of a store insert.

func (InsertOutcome) Inserted

func (o InsertOutcome) Inserted() bool

Inserted reports whether the entry was inserted.

func (InsertOutcome) Removed

func (o InsertOutcome) Removed() int

Removed reports how many older descendant entries were removed.

type LiveSync

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

LiveSync keeps a document store synchronized over an iroh-gossip topic.

func StartLiveSync

func StartLiveSync(ctx context.Context, ep *iroh.Endpoint, g *gossip.Gossip, namespace NamespaceID, store *MemoryStore, opts LiveSyncOptions) (*LiveSync, error)

StartLiveSync starts live synchronization for namespace.

Local store inserts are broadcast over gossip. Received inserts are added as remote entries. New neighbors and bootstrap peers are synchronized with the iroh-docs range-reconciliation protocol.

Example
package main

import (
	"context"

	"github.com/tmc/go-iroh/docs"
	"github.com/tmc/go-iroh/gossip"
	"github.com/tmc/go-iroh/iroh"
)

func main() {
	ctx := context.Background()

	var ep *iroh.Endpoint
	var g *gossip.Gossip
	var namespace docs.NamespaceID
	store := docs.NewMemoryStore()

	live, err := docs.StartLiveSync(ctx, ep, g, namespace, store, docs.LiveSyncOptions{})
	if err != nil {
		return
	}
	defer live.Close()
}

func (*LiveSync) Close

func (l *LiveSync) Close() error

Close stops the live synchronization background task.

type LiveSyncOptions

type LiveSyncOptions struct {
	// Bootstrap is the initial set of peers to join and sync with.
	Bootstrap []netaddr.EndpointAddr
	// Resolver resolves neighbor IDs to endpoint addresses before syncing.
	Resolver iroh.AddressResolver
	// BlobStore reports which entry content is locally available.
	BlobStore blobs.Store
	// Config configures range reconciliation.
	Config SyncConfig
	// DownloadPolicy selects which entry content live sync downloads. The zero
	// value downloads every key.
	DownloadPolicy DownloadPolicy
	// OnSync, if non-nil, is called after each sync attempt.
	OnSync func(SyncResult)
}

LiveSyncOptions configures live document synchronization over iroh-gossip.

type MemoryStore

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

MemoryStore is an in-memory document entry store.

func LoadMemoryStoreFile

func LoadMemoryStoreFile(path string) (*MemoryStore, error)

LoadMemoryStoreFile loads a store snapshot from path.

func NewFileStore

func NewFileStore(path string) (*MemoryStore, error)

NewFileStore opens a store that persists successful inserts to path.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns an empty in-memory store.

func (*MemoryStore) Entries

func (s *MemoryStore) Entries() []SignedEntry

Entries returns the store entries in document order.

func (*MemoryStore) Fingerprint

func (s *MemoryStore) Fingerprint(r Range) Fingerprint

Fingerprint returns the fingerprint of entries in r.

func (*MemoryStore) GetExact

func (s *MemoryStore) GetExact(namespace NamespaceID, author AuthorID, key []byte, includeEmpty bool) (SignedEntry, bool)

GetExact returns the entry for namespace, author, and key.

func (*MemoryStore) GetRange

func (s *MemoryStore) GetRange(r Range) []SignedEntry

GetRange returns entries whose identifiers are in r.

func (*MemoryStore) InitialMessage deprecated

func (s *MemoryStore) InitialMessage() Message

InitialMessage returns the Rust range reconciliation initial message.

Deprecated: use InitialMessageInNamespace.

func (*MemoryStore) InitialMessageInNamespace added in v0.2.2

func (s *MemoryStore) InitialMessageInNamespace(namespace NamespaceID) Message

InitialMessageInNamespace returns the Rust range reconciliation initial message for namespace.

func (*MemoryStore) Len

func (s *MemoryStore) Len() int

Len returns the number of entries in s.

func (*MemoryStore) PersistError

func (s *MemoryStore) PersistError() error

PersistError returns the last error from an automatic file-store save.

func (*MemoryStore) ProcessMessage deprecated

func (s *MemoryStore) ProcessMessage(config SyncConfig, message Message, validate func(SignedEntry, ContentStatus) bool, onInsert func(SignedEntry, ContentStatus), contentStatus func(SignedEntry) ContentStatus) (Message, bool)

ProcessMessage processes message and returns a response, if reconciliation should continue. The validate callback must verify incoming entries that should be trusted.

Deprecated: use ProcessMessageInNamespace.

func (*MemoryStore) ProcessMessageInNamespace added in v0.2.2

func (s *MemoryStore) ProcessMessageInNamespace(namespace NamespaceID, config SyncConfig, message Message, validate func(SignedEntry, ContentStatus) bool, onInsert func(SignedEntry, ContentStatus), contentStatus func(SignedEntry) ContentStatus) (Message, bool)

ProcessMessageInNamespace processes message for namespace and returns a response, if reconciliation should continue. Entries of another namespace are neither sent nor accepted. The validate callback must verify incoming entries that should be trusted.

func (*MemoryStore) Put

func (s *MemoryStore) Put(entry SignedEntry) InsertOutcome

Put inserts entry if it is newer than all matching parent entries.

Keys form a prefix hierarchy per author, so an entry shadows its descendants: writing "menu" for an author removes that author's "menu/tea" and every other key under "menu" whose record is older than or equal to the one being written. A descendant with a newer record is left alone, so the two do coexist in that case. The insert is dropped instead when an ancestor key is already present with a newer or equal record. "Newer" is the record timestamp, with the content hash breaking ties. Entries from different authors never shadow each other.

This is the iroh-docs model, deliberate and how a subtree is deleted, but it is silent: InsertOutcome.Removed reports how many entries a write deleted, and nothing reports it to a later reader. A caller that wants "menu" and "menu/tea" to coexist must keep the author's keys prefix-free, so that no key is a prefix of another. Note that a trailing separator does not help: "menu/" is still a prefix of "menu/tea".

func (*MemoryStore) PutWithOrigin

func (s *MemoryStore) PutWithOrigin(entry SignedEntry, origin InsertOrigin) InsertOutcome

PutWithOrigin inserts entry with origin metadata for subscribers. It shadows descendant keys exactly as MemoryStore.Put does.

func (*MemoryStore) ReadFrom

func (s *MemoryStore) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a snapshot written by MemoryStore.WriteTo and inserts its entries into s. Entries are verified before insertion.

func (*MemoryStore) SaveFile

func (s *MemoryStore) SaveFile(path string) error

SaveFile writes s to path atomically.

func (*MemoryStore) Subscribe

func (s *MemoryStore) Subscribe() (<-chan StoreEvent, func())

Subscribe returns a subscription to successful store insert events. Events sent before Subscribe are not replayed.

func (*MemoryStore) WriteTo

func (s *MemoryStore) WriteTo(w io.Writer) (int64, error)

WriteTo writes a deterministic snapshot of s to w.

type Message

type Message struct {
	Parts []MessagePart
}

Message is a range reconciliation message.

func (Message) ValueCount

func (m Message) ValueCount() int

ValueCount returns the number of entry values carried by m.

func (Message) Values

func (m Message) Values() []RangeValue

Values returns all entry values carried by m.

type MessagePart

type MessagePart struct {
	Kind             MessagePartKind
	RangeFingerprint RangeFingerprint
	RangeItem        RangeItem
}

MessagePart is one range reconciliation message part.

func (*MessagePart) DecodePostcard

func (p *MessagePart) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes p as Rust ranger::MessagePart<SignedEntry>.

func (MessagePart) EncodePostcard

func (p MessagePart) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes p as Rust ranger::MessagePart<SignedEntry>.

func (MessagePart) Values

func (p MessagePart) Values() []RangeValue

Values returns p's entries, if p is a range item.

type MessagePartKind

type MessagePartKind uint64

MessagePartKind identifies a message part variant.

const (
	// MessagePartRangeFingerprint carries a range fingerprint.
	MessagePartRangeFingerprint MessagePartKind = iota
	// MessagePartRangeItem carries entries in a range.
	MessagePartRangeItem
)

type NamespaceID

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

NamespaceID identifies a document namespace.

func MustNamespaceID

func MustNamespaceID(b [32]byte) NamespaceID

MustNamespaceID constructs a NamespaceID or panics. It is intended for tests and package-level constants.

func NewNamespaceID

func NewNamespaceID(b [32]byte) (NamespaceID, error)

NewNamespaceID constructs a NamespaceID from raw public-key bytes.

func (NamespaceID) Bytes

func (id NamespaceID) Bytes() [32]byte

Bytes returns the 32-byte public key.

func (*NamespaceID) DecodePostcard

func (id *NamespaceID) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes id as Rust NamespaceId.

func (NamespaceID) EncodePostcard

func (id NamespaceID) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes id as Rust NamespaceId.

func (NamespaceID) EndpointID

func (id NamespaceID) EndpointID() key.EndpointID

EndpointID returns id as an iroh endpoint identifier.

func (NamespaceID) String

func (id NamespaceID) String() string

String returns the lowercase hex public key.

func (NamespaceID) Verify

func (id NamespaceID) Verify(msg []byte, sig key.Signature) error

Verify verifies sig over msg with id.

type NamespaceSecret

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

NamespaceSecret is a secret namespace key. Holders can write document entries in the namespace.

func GenerateNamespaceSecret

func GenerateNamespaceSecret() (NamespaceSecret, error)

GenerateNamespaceSecret generates a random NamespaceSecret.

func NewNamespaceSecret

func NewNamespaceSecret(seed [32]byte) NamespaceSecret

NewNamespaceSecret returns a NamespaceSecret from a 32-byte secret seed.

func (NamespaceSecret) Bytes

func (s NamespaceSecret) Bytes() [32]byte

Bytes returns the 32-byte secret seed.

func (*NamespaceSecret) DecodePostcard

func (s *NamespaceSecret) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes s as Rust NamespaceSecret.

func (NamespaceSecret) EncodePostcard

func (s NamespaceSecret) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes s as Rust NamespaceSecret.

func (NamespaceSecret) ID

ID returns the public namespace identifier.

func (NamespaceSecret) Sign

func (s NamespaceSecret) Sign(msg []byte) key.Signature

Sign signs msg with the namespace key.

func (NamespaceSecret) String

func (s NamespaceSecret) String() string

String returns the lowercase hex secret seed.

type Range

type Range struct {
	Start RecordIdentifier
	End   RecordIdentifier
}

Range is a wraparound half-open range of record identifiers.

func NewRange

func NewRange(start, end RecordIdentifier) Range

NewRange returns the range [start, end).

func (Range) Contains

func (r Range) Contains(id RecordIdentifier) bool

Contains reports whether id is in r.

func (Range) IsAll

func (r Range) IsAll() bool

IsAll reports whether r denotes the whole set.

type RangeFingerprint

type RangeFingerprint struct {
	Range       Range
	Fingerprint Fingerprint
}

RangeFingerprint is the fingerprint for a range.

type RangeItem

type RangeItem struct {
	Range     Range
	Values    []RangeValue
	HaveLocal bool
}

RangeItem transfers entries inside a range.

type RangeValue

type RangeValue struct {
	Entry  SignedEntry
	Status ContentStatus
}

RangeValue is one entry and its content status in a range item.

type Record

type Record struct {
	Len       uint64
	Hash      blobs.Hash
	Timestamp uint64
}

Record is the value part of an entry.

func EmptyRecord

func EmptyRecord(timestamp uint64) Record

EmptyRecord returns a tombstone record.

func NewRecord

func NewRecord(hash blobs.Hash, length uint64, timestamp uint64) Record

NewRecord returns a content record.

func (Record) Compare

func (r Record) Compare(other Record) int

Compare compares r and other by timestamp and content hash.

func (Record) IsEmpty

func (r Record) IsEmpty() bool

IsEmpty reports whether r is a tombstone.

type RecordIdentifier

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

RecordIdentifier identifies an entry by namespace, author, and key.

func NewRecordIdentifier

func NewRecordIdentifier(namespace NamespaceID, author AuthorID, k []byte) RecordIdentifier

NewRecordIdentifier returns an entry identifier.

func (RecordIdentifier) Author

func (id RecordIdentifier) Author() AuthorID

Author returns the author id.

func (RecordIdentifier) Compare

func (id RecordIdentifier) Compare(other RecordIdentifier) int

Compare compares id and other by namespace, author, and key.

func (*RecordIdentifier) DecodePostcard

func (id *RecordIdentifier) DecodePostcard(d *postcard.Decoder) error

DecodePostcard decodes id as Rust RecordIdentifier.

func (RecordIdentifier) EncodePostcard

func (id RecordIdentifier) EncodePostcard(e *postcard.Encoder) error

EncodePostcard encodes id as Rust RecordIdentifier.

func (RecordIdentifier) Key

func (id RecordIdentifier) Key() []byte

Key returns the entry key.

func (RecordIdentifier) Namespace

func (id RecordIdentifier) Namespace() NamespaceID

Namespace returns the namespace id.

type SignedEntry

type SignedEntry struct {
	Signature EntrySignature
	Entry     Entry
}

SignedEntry is an entry with namespace and author signatures.

func NewSignedEntry

func NewSignedEntry(entry Entry, namespace NamespaceSecret, author Author) SignedEntry

NewSignedEntry signs entry with namespace and author.

func (SignedEntry) Compare

func (s SignedEntry) Compare(other SignedEntry) int

Compare compares s and other by entry.

func (SignedEntry) Equal

func (s SignedEntry) Equal(other SignedEntry) bool

Equal reports whether s and other are identical.

func (SignedEntry) Fingerprint

func (s SignedEntry) Fingerprint() [32]byte

Fingerprint returns the range-reconciliation fingerprint for s.

func (SignedEntry) Verify

func (s SignedEntry) Verify() error

Verify verifies the entry signatures.

type StoreEvent

type StoreEvent struct {
	// Kind is which kind of event this is.
	Kind StoreEventKind
	// Sequence is the store-local event sequence.
	Sequence uint64
	// Entry is the inserted entry. It is zero for StoreEventLagged.
	Entry SignedEntry
	// Hash is the content hash for StoreEventContentReady.
	Hash blobs.Hash
	// Removed is the number of older descendant entries removed by the insert.
	Removed int
	// From is the peer an inserted entry came from. It is zero for local inserts.
	From key.EndpointID
	// ContentStatus reports whether remote entry content is locally available.
	ContentStatus ContentStatus
	// Missed is the number of dropped events for StoreEventLagged.
	Missed uint64
}

StoreEvent reports a store insertion or subscriber lag.

type StoreEventKind

type StoreEventKind uint8

StoreEventKind tags the variant of a StoreEvent.

const (
	// StoreEventInsertLocal reports a locally inserted entry.
	StoreEventInsertLocal StoreEventKind = iota
	// StoreEventInsertRemote reports an entry inserted from a peer.
	StoreEventInsertRemote
	// StoreEventLagged reports that a subscriber missed events.
	StoreEventLagged
	// StoreEventContentReady reports that entry content is now locally available.
	StoreEventContentReady
)

type SyncConfig

type SyncConfig struct {
	MaxSetSize  int
	SplitFactor int
	// contains filtered or unexported fields
}

SyncConfig configures range reconciliation.

func DefaultSyncConfig

func DefaultSyncConfig() SyncConfig

DefaultSyncConfig returns the Rust iroh-docs reconciliation defaults.

type SyncOutcome

type SyncOutcome struct {
	NumSent int
	NumRecv int
}

SyncOutcome counts entries exchanged during one sync stream.

func Sync

func Sync(ctx context.Context, ep *iroh.Endpoint, addr netaddr.EndpointAddr, namespace NamespaceID, store *MemoryStore, blobStore blobs.Store, config SyncConfig) (SyncOutcome, error)

Sync connects to addr and syncs store with the remote peer.

type SyncResult

type SyncResult struct {
	Addr    netaddr.EndpointAddr
	Outcome SyncOutcome
	Err     error
}

SyncResult is the result of one peer sync attempt.

func SyncPeers

func SyncPeers(ctx context.Context, ep *iroh.Endpoint, namespace NamespaceID, peers []netaddr.EndpointAddr, store *MemoryStore, blobStore blobs.Store, config SyncConfig) []SyncResult

SyncPeers syncs store with peers in order.

func SyncTicket

func SyncTicket(ctx context.Context, ep *iroh.Endpoint, ticket DocTicket, store *MemoryStore, blobStore blobs.Store, config SyncConfig, resolver iroh.AddressResolver) []SyncResult

SyncTicket syncs store with peers from ticket. If resolver is not nil, ticket node IDs are resolved before syncing.

Jump to

Keyboard shortcuts

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