pub struct RelayClientBuilder {
client_keypair_inner: Option<Arc<KeyPair>>,
server_public_key: Option<VerifyingKey>,
server_address: Option<SocketAddr>,
db_config: Option<StorageConfig>,
encryption_key: Option<[u8; 32]>,
storage: Option<Arc<SqliteMessageStorage>>,
autosubscribe: bool,
buffer_size: Option<usize>,
}Expand description
Builder for creating RelayClient instances with configurable options.
This builder allows configuring storage, connection parameters, and message persistence before creating a RelayClient instance. All RelayClients have message persistence enabled by default and require storage configuration.
§Example
let server_key = VerifyingKey::from([0u8; 32]); // Replace with actual key
let server_addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
let encryption_key = [42u8; 32]; // Use a proper encryption key
let client = RelayClientBuilder::new()
.server_public_key(server_key)
.server_address(server_addr)
.db_storage_path("client_messages.db")
.encryption_key(encryption_key)
.autosubscribe(true)
.build()
.await?;Fields§
§client_keypair_inner: Option<Arc<KeyPair>>§server_public_key: Option<VerifyingKey>§server_address: Option<SocketAddr>§db_config: Option<StorageConfig>§encryption_key: Option<[u8; 32]>§storage: Option<Arc<SqliteMessageStorage>>§autosubscribe: bool§buffer_size: Option<usize>Implementations§
Source§impl RelayClientBuilder
impl RelayClientBuilder
Sourcepub fn client_keypair(self, keypair: Arc<KeyPair>) -> Self
pub fn client_keypair(self, keypair: Arc<KeyPair>) -> Self
Set the client’s inner protocol keypair (for message signing/verification) If not set, a random keypair will be generated
Sourcepub fn server_public_key(self, key: VerifyingKey) -> Self
pub fn server_public_key(self, key: VerifyingKey) -> Self
Set the server’s public key for TLS verification
Sourcepub fn server_address(self, addr: SocketAddr) -> Self
pub fn server_address(self, addr: SocketAddr) -> Self
Set the server address to connect to
Sourcepub fn db_storage_path<P: Into<PathBuf>>(self, path: P) -> Self
pub fn db_storage_path<P: Into<PathBuf>>(self, path: P) -> Self
Set the storage database path (convenience method)
Sourcepub fn encryption_key(self, key: [u8; 32]) -> Self
pub fn encryption_key(self, key: [u8; 32]) -> Self
Set the encryption key for storage
Sourcepub fn storage(self, storage: Arc<SqliteMessageStorage>) -> Self
pub fn storage(self, storage: Arc<SqliteMessageStorage>) -> Self
Set a pre-created storage instance
When this is set, the builder will use this storage instead of creating one from db_config and encryption_key.
Sourcepub fn autosubscribe(self, enable: bool) -> Self
pub fn autosubscribe(self, enable: bool) -> Self
Enable or disable automatic subscription to messages
Sourcepub fn buffer_size(self, size: usize) -> Self
pub fn buffer_size(self, size: usize) -> Self
Set the buffer size for message processing
Sourcepub async fn build(self) -> Result<RelayClient>
pub async fn build(self) -> Result<RelayClient>
Build the RelayClient with the configured options
Storage and encryption key are required for message persistence.