pub struct ProtocolConfigBuilder { /* private fields */ }Expand description
Builder for ProtocolConfig with a fluent API.
Implementations§
Source§impl ProtocolConfigBuilder
impl ProtocolConfigBuilder
Sourcepub fn new(app_id: impl Into<String>, profile: impl Into<String>) -> Self
pub fn new(app_id: impl Into<String>, profile: impl Into<String>) -> Self
Creates a new builder.
Sourcepub fn transport(self, config: TransportConfig) -> Self
pub fn transport(self, config: TransportConfig) -> Self
Configures transports.
Sourcepub fn ble_enabled(self, enabled: bool) -> Self
pub fn ble_enabled(self, enabled: bool) -> Self
Enables or disables BLE transport.
Sourcepub fn wifi_direct_enabled(self, enabled: bool) -> Self
pub fn wifi_direct_enabled(self, enabled: bool) -> Self
Enables or disables Wi-Fi Direct transport.
Sourcepub fn internet_enabled(self, enabled: bool) -> Self
pub fn internet_enabled(self, enabled: bool) -> Self
Enables or disables Internet transport.
Sourcepub fn nostr_enabled(self, enabled: bool) -> Self
pub fn nostr_enabled(self, enabled: bool) -> Self
Enables or disables Nostr relay transport.
Sourcepub fn nostr_sealing_enabled(self, enabled: bool) -> Self
pub fn nostr_sealing_enabled(self, enabled: bool) -> Self
Enables or disables sealing of outgoing Nostr frames (default on).
Sourcepub fn nostr_username_discovery_enabled(self, enabled: bool) -> Self
pub fn nostr_username_discovery_enabled(self, enabled: bool) -> Self
Enables username discovery publication and resolution
(default off; see
TransportConfig::nostr_username_discovery_enabled).
Sourcepub fn nostr_cold_contact_enabled(self, enabled: bool) -> Self
pub fn nostr_cold_contact_enabled(self, enabled: bool) -> Self
Enables or disables Nostr key-package publication and peer resolution
(default on; see TransportConfig::nostr_cold_contact_enabled).
Sourcepub fn dors(self, config: DorsConfig) -> Self
pub fn dors(self, config: DorsConfig) -> Self
Configures DORS (Dynamic Offline Relay Switch).
Sourcepub fn online_first(self, enabled: bool) -> Self
pub fn online_first(self, enabled: bool) -> Self
Enables online-first mode (prefer Internet when available).
Sourcepub fn relay(self, config: RelayConfig) -> Self
pub fn relay(self, config: RelayConfig) -> Self
Configures relay management.
Sourcepub fn mesh_relay(self, config: MeshRelayConfig) -> Self
pub fn mesh_relay(self, config: MeshRelayConfig) -> Self
Configures how traffic is carried for other people.
Sourcepub fn reliability(self, config: ReliabilityConfig) -> Self
pub fn reliability(self, config: ReliabilityConfig) -> Self
Configures reliability layer.
Sourcepub fn initial_ttl(self, ttl: u8) -> Self
pub fn initial_ttl(self, ttl: u8) -> Self
Sets the initial TTL for messages.
Sourcepub fn encryption(self, config: EncryptionConfig) -> Self
pub fn encryption(self, config: EncryptionConfig) -> Self
Configures encryption settings.
Sourcepub fn encryption_enabled(self, enabled: bool) -> Self
pub fn encryption_enabled(self, enabled: bool) -> Self
Enables or disables automatic encryption.
Sourcepub fn auto_key_exchange(self, enabled: bool) -> Self
pub fn auto_key_exchange(self, enabled: bool) -> Self
Enables or disables automatic key exchange on peer discovery.
Sourcepub fn store_pending_messages(self, enabled: bool) -> Self
pub fn store_pending_messages(self, enabled: bool) -> Self
Enables or disables storing pending messages for later encryption.
Sourcepub fn require_encryption(self, required: bool) -> Self
pub fn require_encryption(self, required: bool) -> Self
Enables or disables strict encryption requirement.
Sourcepub fn pending_queue(self, config: PendingQueueConfig) -> Self
pub fn pending_queue(self, config: PendingQueueConfig) -> Self
Configures pending encrypted message queue bounds and overflow behavior.
Sourcepub fn group(self, config: GroupConfig) -> Self
pub fn group(self, config: GroupConfig) -> Self
Configures group messaging settings.
Sourcepub fn max_group_members(self, max: usize) -> Self
pub fn max_group_members(self, max: usize) -> Self
Sets the maximum number of members allowed in a single group.
Sourcepub fn group_relay_enabled(self, enabled: bool) -> Self
pub fn group_relay_enabled(self, enabled: bool) -> Self
Sets whether groups should attempt relay server registration.
Sourcepub fn group_relay_broadcast_enabled(self, enabled: bool) -> Self
pub fn group_relay_broadcast_enabled(self, enabled: bool) -> Self
Sets whether relay-synced groups may send via a single relay broadcast
instead of per-member fan-out. See
GroupConfig::relay_broadcast_enabled — on by default, but only
ever taken against a relay that advertised the group_delivery_v3
capability, whose settled, address-space delivery report gives the
broadcast a per-recipient delivery contract.
Sourcepub fn group_enforce_admin_commits(self, enabled: bool) -> Self
pub fn group_enforce_admin_commits(self, enabled: bool) -> Self
Sets whether unauthorized MLS membership commits are refused rather
than applied-and-reported. See
GroupConfig::enforce_admin_commits — off by default, and enabling
it risks permanently forking members whose admin overlay disagrees.
Sourcepub fn security(self, config: SecurityConfig) -> Self
pub fn security(self, config: SecurityConfig) -> Self
Configures security settings.
Sourcepub fn require_transport_identity(self, required: bool) -> Self
pub fn require_transport_identity(self, required: bool) -> Self
Sets whether transport identity is required for control messages.
Sourcepub fn data(self, config: DataConfig) -> Self
pub fn data(self, config: DataConfig) -> Self
Configures the replicated-document data layer.
Sourcepub fn data_enabled(self, enabled: bool) -> Self
pub fn data_enabled(self, enabled: bool) -> Self
Sets whether the data layer accepts work. See DataConfig::enabled.
Sourcepub fn data_storage(self, storage: Arc<dyn ProtocolStateStorage>) -> Self
pub fn data_storage(self, storage: Arc<dyn ProtocolStateStorage>) -> Self
Points documents at a storage backend of the application’s choosing.
The whole bring-your-own-backend path, in one call. See
DataConfig::storage, including what it means for logout.
Sourcepub fn custody(self, config: CustodyConfig) -> Self
pub fn custody(self, config: CustodyConfig) -> Self
Configures custody: whether this device holds a neighbour’s replication
frames, and under what quotas. See CustodyConfig.
Sourcepub fn build(self) -> Result<ProtocolConfig>
pub fn build(self) -> Result<ProtocolConfig>
Builds and validates the configuration.
§Returns
Returns Ok(ProtocolConfig) if valid, Err otherwise.
Examples found in repository?
57fn main() -> Result<(), Box<dyn std::error::Error>> {
58 let root = match std::env::args_os().nth(1) {
59 Some(root) => PathBuf::from(root),
60 None => {
61 let mut suffix = [0u8; 8];
62 OsRng.fill_bytes(&mut suffix);
63 std::env::temp_dir().join(format!("replicated-notes-{}", hex::encode(suffix)))
64 }
65 };
66 let key: Box<dyn StoreKeyProvider> =
67 if std::env::var_os(EnvStoreKey::DEFAULT_VARIABLE).is_some() {
68 Box::new(EnvStoreKey::default())
69 } else {
70 let mut key = [0u8; 32];
71 OsRng.fill_bytes(&mut key);
72 Box::new(StaticStoreKey::new(key))
73 };
74 println!("stores: {}", root.display());
75
76 // Both stores are on disk, which is what makes the reopen at the end a
77 // reopen rather than a fresh start. The secure store matters as much as
78 // the record store: documents are sealed with a key that lives in it, so
79 // losing only that half looks exactly like data loss.
80 let (secure, records) = open_stores(&root, key.as_ref())?;
81
82 // `data.enabled` defaults to true, so nothing here switches the layer on.
83 let config = ProtocolConfig::builder(APP_ID, PROFILE).build()?;
84 let mut protocol = OfflineProtocol::new(config)?;
85
86 // Documents are sealed at rest and the record key is minted here, so this
87 // call is the prerequisite for every method below.
88 protocol.initialize_mls(secure.clone(), records.clone())?;
89
90 // A space is an MLS scope: a peer's address for a 1:1 space, or the group
91 // id for a group. Nothing replicates in this example, so the name only
92 // has to be a valid one.
93 let space = "demo-space";
94
95 protocol.data_create_doc(space, "trip")?;
96
97 // A map: last writer wins per key, and different keys never conflict.
98 protocol.data_map_set(
99 space,
100 "trip",
101 "meta",
102 "title",
103 DataValue::Text {
104 value: "Coast road".to_string(),
105 },
106 )?;
107
108 // A list: concurrent insertions both survive, in a deterministic order.
109 for item in ["water", "map", "torch"] {
110 protocol.data_list_push(
111 space,
112 "trip",
113 "packing",
114 DataValue::Text {
115 value: item.to_string(),
116 },
117 )?;
118 }
119
120 // Text: character-level merge, so two people typing in one paragraph keep
121 // both sets of words. Positions are character offsets, not byte offsets.
122 protocol.data_text_insert(space, "trip", "notes", 0, "Meet at the bridge")?;
123
124 // A counter: increments add up rather than overwriting each other.
125 protocol.data_counter_increment(space, "trip", "opened", 1.0)?;
126
127 // Edits batch before they reach storage. This is the call that makes them
128 // durable, and `data_changed` fires after the same point, never before.
129 protocol.data_flush(space, "trip")?;
130
131 println!("spaces: {:?}", protocol.data_list_spaces()?);
132 println!("documents: {:?}", protocol.data_list_docs(space)?);
133 println!(
134 "compacted: {} bytes",
135 protocol.data_doc_size(space, "trip")?
136 );
137 println!(
138 "history: {} bytes",
139 protocol.data_export_raw(space, "trip")?.len()
140 );
141 println!("json: {}", protocol.data_doc_json(space, "trip")?);
142
143 // Both halves of the escape hatch are above: `data_doc_json` is the plain
144 // JSON of the current state, `data_export_raw` the engine-native history.
145 // An application can always take its data and leave.
146
147 // Reopen: a new engine over the same two directories, opened afresh as a
148 // restarted process would. The records were sealed by the first engine
149 // and are read back by the second, which is the property an application
150 // depends on across a restart.
151 drop(protocol);
152 drop((secure, records));
153 let (secure, records) = open_stores(&root, key.as_ref())?;
154 let config = ProtocolConfig::builder(APP_ID, PROFILE).build()?;
155 let mut reopened = OfflineProtocol::new(config)?;
156 reopened.initialize_mls(secure, records)?;
157
158 println!("after reopen");
159 println!(
160 " title: {:?}",
161 reopened.data_map_get(space, "trip", "meta", "title")?
162 );
163 println!(
164 " packing: {}",
165 reopened.data_list_len(space, "trip", "packing")?
166 );
167 println!(
168 " notes: {:?}",
169 reopened.data_text_value(space, "trip", "notes")?
170 );
171 println!(
172 " opened: {}",
173 reopened.data_counter_value(space, "trip", "opened")?
174 );
175
176 Ok(())
177}Auto Trait Implementations§
impl !RefUnwindSafe for ProtocolConfigBuilder
impl !UnwindSafe for ProtocolConfigBuilder
impl Freeze for ProtocolConfigBuilder
impl Send for ProtocolConfigBuilder
impl Sync for ProtocolConfigBuilder
impl Unpin for ProtocolConfigBuilder
impl UnsafeUnpin for ProtocolConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);