Struct dittolive_ditto::ditto::Ditto
source · pub struct Ditto { /* private fields */ }
Expand description
The entry point for accessing Ditto-related functionality.
This struct is generally a handle and interface to ditto-functionality which operates in background threads.
Implementations§
source§impl Ditto
impl Ditto
sourcepub fn start_sync(&self) -> Result<(), DittoError>
pub fn start_sync(&self) -> Result<(), DittoError>
Starts the network transports. Ditto will connect to other devices.
By default, Ditto will enable all peer-to-peer transport types.
The network configuration can be customized using set_transport_config
.
Performance of initial sync when bootstrapping a new peer can be improved
by calling disable_sync_with_v3
before calling start_sync
. Only
do this when all peers in the mesh are known to be running Ditto v4 or higher.
sourcepub fn set_transport_config(&self, config: TransportConfig)
pub fn set_transport_config(&self, config: TransportConfig)
Set a new TransportConfig
and begin syncing over these
transports. Any change to start or stop a specific transport should proceed via providing a
modified configuration to this method.
sourcepub fn current_transport_config(&self) -> Result<TransportConfig, DittoError>
pub fn current_transport_config(&self) -> Result<TransportConfig, DittoError>
Returns a snapshot of the currently configured transports.
source§impl Ditto
impl Ditto
sourcepub fn with_sdk_version<R>(ret: impl FnOnce(&str) -> R) -> R
pub fn with_sdk_version<R>(ret: impl FnOnce(&str) -> R) -> R
Return the version of the SDK.
source§impl Ditto
impl Ditto
sourcepub fn set_offline_only_license_token(
&self,
license_token: &str
) -> Result<(), DittoError>
pub fn set_offline_only_license_token( &self, license_token: &str ) -> Result<(), DittoError>
Activate an offline Ditto
instance by setting a license token.
You cannot initiate sync on an offline
(OfflinePlayground
, Manual
, or SharedKey
)
Ditto
instance before you have activated it.
sourcepub fn set_license_from_env(&self, var_name: &str) -> Result<(), DittoError>
pub fn set_license_from_env(&self, var_name: &str) -> Result<(), DittoError>
Look for a license token from a given environment variable.
source§impl Ditto
impl Ditto
sourcepub fn small_peer_info(&self) -> &SmallPeerInfo
pub fn small_peer_info(&self) -> &SmallPeerInfo
Return a reference to the SmallPeerInfo
object.
sourcepub fn site_id(&self) -> u64
pub fn site_id(&self) -> u64
Returns the site ID that the instance of Ditto is using as part of its identity.
sourcepub fn persistence_directory(&self) -> &Path
pub fn persistence_directory(&self) -> &Path
Returns the Ditto persistence directory path.
sourcepub fn application_id(&self) -> AppId
pub fn application_id(&self) -> AppId
Returns the application Id being used by this Ditto
instance.
sourcepub fn set_device_name(&self, name: &str)
pub fn set_device_name(&self, name: &str)
Set a custom identifier for the current device.
When using observe_peers
, each remote peer is represented by a
short UTF-8 “device name”. By default this will be a truncated version of the device’s
hostname. It does not need to be unique among peers. Configure the device name before
calling start_sync
. If it is too long it will be truncated.
sourcepub fn presence(&self) -> &Arc<Presence>
pub fn presence(&self) -> &Arc<Presence>
Return a handle to Presence
to monitor the peers’ activity in
the Ditto mesh. It can be used to retrieve an immediate representation of known peers :
let presence_graph = ditto.presence().graph();
Or to bind a callback to the changes :
let handle = ditto.presence().observe(|graph| {
// do something with the graph
});
// The handle must be kept to keep receiving updates on the other peers.
// To stop receiving update, drop the handle.
sourcepub fn disk_usage(&self) -> &DiskUsage
pub fn disk_usage(&self) -> &DiskUsage
Return a DiskUsage
to monitor the disk usage of the Ditto
instance. It can be used to retrieve an immediate representation of the Ditto file system:
let fs_tree = ditto.disk_usage().exec();
Or to bind a callback to the changes :
let handle = ditto.disk_usage().observe(|fs_tree| {
// do something with the graph
});
// The handle must be kept to keep receiving updates on the file system.
// To stop receiving update, drop the handle.
sourcepub fn authenticator(&self) -> Option<DittoAuthenticator>
pub fn authenticator(&self) -> Option<DittoAuthenticator>
Returns the current DittoAuthenticator
, if it exists.
sourcepub fn is_activated(&self) -> bool
pub fn is_activated(&self) -> bool
Has this Ditto
instance been activated yet with a valid license
token.
source§impl Ditto
impl Ditto
sourcepub fn run_garbage_collection(&self)
pub fn run_garbage_collection(&self)
Removes all sync metadata for any remote peers which aren’t currently connected. This method shouldn’t usually be called. Manually running garbage collection often will result in slower sync times. Ditto automatically runs a garbage a collection process in the background at optimal times.
Manually running garbage collection is typically only useful during testing if large amounts of data are being generated. Alternatively, if an entire data set is to be evicted and it’s clear that maintaining this metadata isn’t necessary, then garbage collection could be run after evicting the old data.
sourcepub fn disable_sync_with_v3(&self) -> Result<(), DittoError>
pub fn disable_sync_with_v3(&self) -> Result<(), DittoError>
Disable sync with peers running version 3 or lower of the Ditto SDK.
Required for the execution of mutating DQL statements.
This setting spreads to other peers on connection. Those peers will in turn spread it further until all peers in the mesh take on the same setting. This is irreversible and will persist across restarts of the Ditto instance.
Calling this method before calling start_sync
is recommended whenever
possible. This improves performance of initial sync when this peer has
never before connected to a Ditto mesh for which sync with v3 peers is
disabled.