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 ¶
- Constants
- func Register(r *endpointticket.Registry) error
- func SyncErrors(results []SyncResult) error
- type AbortReason
- type Author
- type AuthorID
- func (id AuthorID) Bytes() [32]byte
- func (id *AuthorID) DecodePostcard(d *postcard.Decoder) error
- func (id AuthorID) EncodePostcard(e *postcard.Encoder) error
- func (id AuthorID) EndpointID() key.EndpointID
- func (id AuthorID) String() string
- func (id AuthorID) Verify(msg []byte, sig key.Signature) error
- type Capability
- type CapabilityKind
- type ContentStatus
- type DocTicket
- func (t DocTicket) Capability() Capability
- func (t DocTicket) EncodeBytes() []byte
- func (t DocTicket) EncodeString() string
- func (t DocTicket) Kind() string
- func (t DocTicket) MarshalText() ([]byte, error)
- func (t DocTicket) Nodes() []netaddr.EndpointAddr
- func (t DocTicket) Short() DocTicket
- func (t DocTicket) String() string
- func (t *DocTicket) UnmarshalText(text []byte) error
- type DownloadPolicy
- type Entry
- func (e Entry) Author() AuthorID
- func (e Entry) Compare(other Entry) int
- func (e Entry) ContentHash() blobs.Hash
- func (e Entry) ContentLen() uint64
- func (e *Entry) DecodePostcard(dec *postcard.Decoder) error
- func (e Entry) Encode() []byte
- func (e Entry) EncodePostcard(enc *postcard.Encoder) error
- func (e Entry) Key() []byte
- func (e Entry) Namespace() NamespaceID
- func (e Entry) Timestamp() uint64
- func (e Entry) ValidateEmpty() error
- type EntrySignature
- type Fingerprint
- type Handler
- type InsertOrigin
- type InsertOriginKind
- type InsertOutcome
- type LiveSync
- type LiveSyncOptions
- type MemoryStore
- func (s *MemoryStore) Entries() []SignedEntry
- func (s *MemoryStore) Fingerprint(r Range) Fingerprint
- func (s *MemoryStore) GetExact(namespace NamespaceID, author AuthorID, key []byte, includeEmpty bool) (SignedEntry, bool)
- func (s *MemoryStore) GetRange(r Range) []SignedEntry
- func (s *MemoryStore) InitialMessage() Message
- func (s *MemoryStore) Len() int
- func (s *MemoryStore) PersistError() error
- func (s *MemoryStore) ProcessMessage(config SyncConfig, message Message, ...) (Message, bool)
- func (s *MemoryStore) Put(entry SignedEntry) InsertOutcome
- func (s *MemoryStore) PutWithOrigin(entry SignedEntry, origin InsertOrigin) InsertOutcome
- func (s *MemoryStore) ReadFrom(r io.Reader) (int64, error)
- func (s *MemoryStore) SaveFile(path string) error
- func (s *MemoryStore) Subscribe() (<-chan StoreEvent, func())
- func (s *MemoryStore) WriteTo(w io.Writer) (int64, error)
- type Message
- type MessagePart
- type MessagePartKind
- type NamespaceID
- func (id NamespaceID) Bytes() [32]byte
- func (id *NamespaceID) DecodePostcard(d *postcard.Decoder) error
- func (id NamespaceID) EncodePostcard(e *postcard.Encoder) error
- func (id NamespaceID) EndpointID() key.EndpointID
- func (id NamespaceID) String() string
- func (id NamespaceID) Verify(msg []byte, sig key.Signature) error
- type NamespaceSecret
- func (s NamespaceSecret) Bytes() [32]byte
- func (s *NamespaceSecret) DecodePostcard(d *postcard.Decoder) error
- func (s NamespaceSecret) EncodePostcard(e *postcard.Encoder) error
- func (s NamespaceSecret) ID() NamespaceID
- func (s NamespaceSecret) Sign(msg []byte) key.Signature
- func (s NamespaceSecret) String() string
- type Range
- type RangeFingerprint
- type RangeItem
- type RangeValue
- type Record
- type RecordIdentifier
- func (id RecordIdentifier) Author() AuthorID
- func (id RecordIdentifier) Compare(other RecordIdentifier) int
- func (id *RecordIdentifier) DecodePostcard(d *postcard.Decoder) error
- func (id RecordIdentifier) EncodePostcard(e *postcard.Encoder) error
- func (id RecordIdentifier) Key() []byte
- func (id RecordIdentifier) Namespace() NamespaceID
- type SignedEntry
- type StoreEvent
- type StoreEventKind
- type SyncConfig
- type SyncOutcome
- type SyncResult
Examples ¶
Constants ¶
const ALPN = "/iroh-sync/1"
ALPN is the Rust iroh-docs sync protocol name.
const MaxTimestampFutureShift = 10 * 60 * uint64(time.Second/time.Microsecond)
MaxTimestampFutureShift is the maximum accepted future timestamp in microseconds.
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 ¶
GenerateAuthor generates a random Author.
func (*Author) DecodePostcard ¶
DecodePostcard decodes a as Rust Author.
func (Author) EncodePostcard ¶
EncodePostcard encodes a as Rust Author.
type AuthorID ¶
type AuthorID struct {
// contains filtered or unexported fields
}
AuthorID identifies an Author.
func NewAuthorID ¶
NewAuthorID constructs an AuthorID from raw public-key bytes.
func (*AuthorID) DecodePostcard ¶
DecodePostcard decodes id as Rust AuthorId.
func (AuthorID) EncodePostcard ¶
EncodePostcard encodes id as Rust AuthorId.
func (AuthorID) EndpointID ¶
func (id AuthorID) EndpointID() key.EndpointID
EndpointID returns id as an iroh endpoint identifier.
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 ¶
DecodeBytes decodes the postcard bytes of a document ticket.
func DecodeString ¶
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 ¶
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 ¶
EncodeBytes returns the Rust-compatible postcard ticket payload.
func (DocTicket) EncodeString ¶
EncodeString returns the canonical ticket string.
func (DocTicket) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (DocTicket) Nodes ¶
func (t DocTicket) Nodes() []netaddr.EndpointAddr
Nodes returns the ticket's bootstrap nodes.
func (*DocTicket) UnmarshalText ¶
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) ContentHash ¶
ContentHash returns the content hash.
func (*Entry) DecodePostcard ¶
DecodePostcard decodes e as Rust Entry.
func (Entry) EncodePostcard ¶
EncodePostcard encodes e as Rust Entry.
func (Entry) Namespace ¶
func (e Entry) Namespace() NamespaceID
Namespace returns the entry namespace.
func (Entry) ValidateEmpty ¶
ValidateEmpty validates the empty-record invariant.
type EntrySignature ¶
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 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.
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()
}
Output:
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 ¶
func (s *MemoryStore) InitialMessage() Message
InitialMessage returns the Rust range reconciliation initial message.
func (*MemoryStore) PersistError ¶
func (s *MemoryStore) PersistError() error
PersistError returns the last error from an automatic file-store save.
func (*MemoryStore) ProcessMessage ¶
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.
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.
type Message ¶
type Message struct {
Parts []MessagePart
}
Message is a range reconciliation message.
func (Message) ValueCount ¶
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.
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 ¶
func (s NamespaceSecret) ID() NamespaceID
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.
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 ¶
Record is the value part of an entry.
func EmptyRecord ¶
EmptyRecord returns a tombstone record.
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) 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 ¶
SyncConfig configures range reconciliation.
func DefaultSyncConfig ¶
func DefaultSyncConfig() SyncConfig
DefaultSyncConfig returns the Rust iroh-docs reconciliation defaults.
type SyncOutcome ¶
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.