Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Configuration Reference

This chapter lists every configuration struct in mosaik, its fields, default values, and how the pieces fit together.

NetworkBuilder (top-level)

The entry point for creating a mosaik network. All nested configs are accessible through fluent builder methods.

use mosaik::Network;

let network = Network::builder()
    .network_id("my-network")
    .mdns_discovery(true)
    .discovery(|d| d.events_backlog(200))
    .streams(|s| s.with_backoff(my_backoff))
    .groups(|g| g.handshake_timeout(Duration::from_secs(5)))
    .build()
    .await?;
FieldTypeDefaultDescription
network_idNetworkIdrequiredUnique identifier for this network
relay_modeiroh::RelayModeRelayMode::DefaultRelay server mode for NAT/firewall traversal
mdns_discoveryboolfalseEnable mDNS local network peer discovery
addressesBTreeSet<SocketAddr>empty (all interfaces)Local bind addresses
secret_keySecretKeyrandomEd25519 key for peer identity
discoveryDiscoveryConfigBuildersee belowNested discovery config
streamsStreamsConfigBuildersee belowNested streams config
groupsGroupsConfigBuildersee belowNested groups config

Note: secret_key determines the PeerId. If omitted, a random key is generated on each run, giving the node a new identity every time. Specifying a fixed key is only recommended for bootstrap nodes that need a stable, well-known peer ID across restarts.


discovery::Config

Controls peer discovery, gossip, and catalog maintenance.

FieldTypeDefaultDescription
events_backlogusize100Past events retained in event watchers
bootstrap_peersVec<EndpointAddr>emptyInitial peers to connect to on startup
tagsVec<Tag>emptyTags advertised in local PeerEntry
purge_afterDuration300s (5 min)Time before stale peer entries are purged
max_time_driftDuration10sMaximum acceptable timestamp drift
announce_intervalDuration15sInterval between presence announcements
announce_jitterf320.5Max jitter factor on announce interval
graceful_departure_windowDuration500msWait for departure gossip to propagate

Builder methods with_bootstrap(peers) and with_tags(tags) accept either a single item or an iterator (via IntoIterOrSingle):

Network::builder()
    .discovery(|d| d
        .with_bootstrap(peer_addr)          // single peer
        .with_tags(["validator", "relay"])   // multiple tags
        .purge_after(Duration::from_secs(600))
    )

streams::Config

Controls stream consumer reconnection behavior.

FieldTypeDefaultDescription
backoffBackoffFactoryExponential, 5 min maxRetry policy for consumer stream connections

Custom backoff example:

use mosaik::streams::backoff::ExponentialBackoff;

Network::builder()
    .streams(|s| s.with_backoff(ExponentialBackoff {
        max_elapsed_time: Some(Duration::from_secs(120)),
        ..Default::default()
    }))

groups::Config

Controls bond establishment.

FieldTypeDefaultDescription
handshake_timeoutDuration2sTimeout for bond handshake with remote peers

ConsensusConfig

Consensus parameters that must be identical across all members of a group. These values are hashed into the GroupId, so any mismatch creates a different group.

FieldTypeDefaultDescription
heartbeat_intervalDuration500msBond heartbeat interval
heartbeat_jitterDuration150msMax heartbeat jitter
max_missed_heartbeatsu3210Missed heartbeats before bond is considered dead
election_timeoutDuration2sRaft election timeout (must exceed heartbeat interval)
election_timeout_jitterDuration500msElection timeout randomization
bootstrap_delayDuration3sExtra delay for the first election (term 0)
forward_timeoutDuration2sTimeout for forwarding commands to leader
query_timeoutDuration2sTimeout for leader to respond to queries
use mosaik::groups::ConsensusConfig;

let config = ConsensusConfig::builder()
    .heartbeat_interval(Duration::from_millis(250))
    .election_timeout(Duration::from_secs(1))
    .build()
    .unwrap();

Leadership deprioritization

let config = ConsensusConfig::default().deprioritize_leadership();

This multiplies the election timeout by a factor, making this node less likely to become leader. Used by collection readers.


SyncConfig (collections)

Controls snapshot-based state synchronization for collections.

FieldTypeDefaultDescription
fetch_batch_sizeusize2000Max items per batch request
snapshot_ttlDuration10sHow long a snapshot remains available
snapshot_request_timeoutDuration15sTimeout for requesting a snapshot
fetch_timeoutDuration5sTimeout for each batch fetch

Configuration hierarchy

NetworkBuilder
├── network_id          (identity)
├── secret_key          (identity)
├── relay_mode          (transport)
├── mdns_discovery      (transport)
├── addresses           (transport)
│
├── discovery::Config
│   ├── bootstrap_peers
│   ├── tags
│   ├── events_backlog
│   ├── purge_after
│   ├── max_time_drift
│   ├── announce_interval
│   └── announce_jitter
│
├── streams::Config
│   └── backoff
│
└── groups::Config
    └── handshake_timeout

Per-group:
ConsensusConfig         (consensus timing, hashed into GroupId)

Per-collection:
SyncConfig              (state sync tuning)

Environment influence

Configuration structs are pure Rust — there is no automatic environment variable parsing. However, test utilities honor:

VariableUsed byEffect
TEST_TRACETest tracing setupControls log level (debug/trace/info/etc.)
TEST_TRACE_UNMUTETest tracing setupSet to 1 to show all log output
TIME_FACTORTest time helpersFloat multiplier for all test durations