Documentation
¶
Overview ¶
Package syncutils implements the OrbitDB sync protocol, which replicates a log between peers.
It is a port of src/sync.js in @orbitdb/core 4 and interoperates with it:
- every peer subscribes to a gossipsub topic named after the log id (the database address);
- when a peer sees another peer subscribe, it opens a libp2p stream with protocol /orbitdb/heads/<address> and both sides send the raw block bytes of their current heads, then close their write side;
- after appending, a peer publishes the new entry's block bytes on the topic.
Received heads are handed to OnSynced, which joins them into the log; the log fetches any missing ancestors itself (over bitswap when its entry storage is IPFS-backed).
Index ¶
Constants ¶
const DefaultTimeout = 30 * time.Second
DefaultTimeout bounds a heads exchange with one peer, as in @orbitdb/core.
Variables ¶
This section is empty.
Functions ¶
func HeadsProtocol ¶
HeadsProtocol returns the libp2p protocol id of the heads exchange for a database address. Like @orbitdb/core it joins "/orbitdb/heads/" and the address and collapses repeated slashes, so "/orbitdb/zdpu..." becomes "/orbitdb/heads/orbitdb/zdpu...".
Types ¶
type Options ¶
type Options struct {
Host host.Host
PubSub *pubsub.PubSub
Log *oplog.Log
// OnSynced is called, one entry at a time, for every head received
// from a peer, either in a heads exchange or as a published update.
OnSynced func(ctx context.Context, entry *oplog.Entry)
// OnJoin is called when a heads exchange with a peer has completed,
// with the local heads at that moment.
OnJoin func(p peer.ID, heads []*oplog.Entry)
// OnLeave is called when a peer leaves the topic or disconnects.
OnLeave func(p peer.ID)
// OnError is called for errors that happen in the background.
OnError func(err error)
// Timeout bounds each heads exchange. Defaults to DefaultTimeout.
Timeout time.Duration
// DisableAutoStart leaves the protocol stopped until Start is called.
DisableAutoStart bool
}
Options configures New.
type Sync ¶
type Sync struct {
// contains filtered or unexported fields
}
Sync replicates one log.