pub struct NetworkManager { /* private fields */ }Expand description
Persistent manager for network membership and folder associations.
Implementations§
Source§impl NetworkManager
impl NetworkManager
Sourcepub fn new(
db: NodeDatabase,
local_node: PublicKey,
member_keys: Arc<RwLock<HashSet<PublicKey>>>,
) -> Result<Self>
pub fn new( db: NodeDatabase, local_node: PublicKey, member_keys: Arc<RwLock<HashSet<PublicKey>>>, ) -> Result<Self>
Sourcepub fn with_logger(
db: NodeDatabase,
local_node: PublicKey,
logger: NetworkLogger,
member_keys: Arc<RwLock<HashSet<PublicKey>>>,
) -> Result<Self>
pub fn with_logger( db: NodeDatabase, local_node: PublicKey, logger: NetworkLogger, member_keys: Arc<RwLock<HashSet<PublicKey>>>, ) -> Result<Self>
Open the network database with a network logger.
§Errors
Returns an error if existing state cannot be read.
Sourcepub const fn logger(&self) -> &Option<NetworkLogger>
pub const fn logger(&self) -> &Option<NetworkLogger>
Return a reference to the network logger, if set.
Sourcepub fn set_logger(&mut self, logger: NetworkLogger)
pub fn set_logger(&mut self, logger: NetworkLogger)
Set the network logger after construction.
Sourcepub const fn database(&self) -> &NodeDatabase
pub const fn database(&self) -> &NodeDatabase
Return a reference to the underlying database.
Sourcepub const fn local_node(&self) -> &PublicKey
pub const fn local_node(&self) -> &PublicKey
Return the local node’s public key.
Sourcepub fn create(
&mut self,
name: &str,
options: NetworkOptions,
) -> Result<NetworkId>
pub fn create( &mut self, name: &str, options: NetworkOptions, ) -> Result<NetworkId>
Create and persist a network owned by the local node.
§Errors
Returns an error for an empty/duplicate name or failed persistence.
Sourcepub fn create_with_doc_ticket(
&mut self,
name: &str,
options: NetworkOptions,
doc_ticket: Option<String>,
) -> Result<NetworkId>
pub fn create_with_doc_ticket( &mut self, name: &str, options: NetworkOptions, doc_ticket: Option<String>, ) -> Result<NetworkId>
Create a network with an optional membership doc ticket.
§Errors
Returns an error for an empty/duplicate name or failed persistence.
Sourcepub fn join(&mut self, ticket: NetworkTicket) -> Result<NetworkId>
pub fn join(&mut self, ticket: NetworkTicket) -> Result<NetworkId>
Join and persist the network represented by a ticket.
§Errors
Returns an error if the ticket is for another device or persistence fails.
Sourcepub fn leave(&mut self, id: NetworkId) -> Result<()>
pub fn leave(&mut self, id: NetworkId) -> Result<()>
Leave a network and remove its local state.
§Errors
Returns an error if the network does not exist or persistence fails.
Sourcepub fn invite(
&mut self,
id: NetworkId,
device: PublicKey,
) -> Result<NetworkTicket>
pub fn invite( &mut self, id: NetworkId, device: PublicKey, ) -> Result<NetworkTicket>
Generate a device-bound invitation and add the device as a member.
§Errors
Returns an error if the network does not exist, the local node is not its owner, or persistence fails.
Sourcepub fn invite_any(&self, id: NetworkId) -> Result<NetworkTicket>
pub fn invite_any(&self, id: NetworkId) -> Result<NetworkTicket>
Generate an invitation usable by any device.
§Errors
Returns an error if the network does not exist or the local node is not its owner.
Sourcepub fn kick(&mut self, id: NetworkId, device: &PublicKey) -> Result<()>
pub fn kick(&mut self, id: NetworkId, device: &PublicKey) -> Result<()>
Remove a member from a locally owned network.
§Errors
Returns an error if the network does not exist, authorization fails, the owner is targeted, or persistence fails.
Sourcepub fn set_doc_ticket(
&mut self,
id: NetworkId,
doc_ticket: &Option<String>,
) -> Result<()>
pub fn set_doc_ticket( &mut self, id: NetworkId, doc_ticket: &Option<String>, ) -> Result<()>
Set (or clear) the membership-doc ticket on a network.
§Errors
Returns an error if the network does not exist or persistence fails.
Sourcepub fn add_folder(&mut self, id: NetworkId, folder: NamespaceId) -> Result<()>
pub fn add_folder(&mut self, id: NetworkId, folder: NamespaceId) -> Result<()>
Associate a folder with a network.
§Errors
Returns an error if the network does not exist or persistence fails.
Sourcepub fn remove_folder(
&mut self,
id: NetworkId,
folder: NamespaceId,
) -> Result<()>
pub fn remove_folder( &mut self, id: NetworkId, folder: NamespaceId, ) -> Result<()>
Remove a folder association without changing the folder itself.
§Errors
Returns an error if the network does not exist or persistence fails.
pub fn list(&self) -> Vec<&Network>
pub fn get(&self, id: &NetworkId) -> Option<&Network>
pub fn get_by_name(&self, name: &str) -> Option<&Network>
Sourcepub fn networks_for_folder(
&self,
namespace_id: &NamespaceId,
) -> Result<Vec<String>>
pub fn networks_for_folder( &self, namespace_id: &NamespaceId, ) -> Result<Vec<String>>
Return the network IDs (as strings) that contain a given folder.
§Errors
Returns an error if the database query fails.
Sourcepub fn network_for_folder(
&self,
namespace_id: &NamespaceId,
) -> Result<Option<String>>
pub fn network_for_folder( &self, namespace_id: &NamespaceId, ) -> Result<Option<String>>
Return the first network ID that contains a given folder, if any.
§Errors
Returns an error if the database query fails.
Sourcepub fn folders_for_network(
&self,
network_id: &NetworkId,
) -> Result<Vec<NamespaceId>>
pub fn folders_for_network( &self, network_id: &NetworkId, ) -> Result<Vec<NamespaceId>>
List all folder namespace IDs associated with a network.
§Errors
Returns an error if the database query fails.
Trait Implementations§
Source§impl Clone for NetworkManager
impl Clone for NetworkManager
Auto Trait Implementations§
impl Freeze for NetworkManager
impl RefUnwindSafe for NetworkManager
impl Send for NetworkManager
impl Sync for NetworkManager
impl Unpin for NetworkManager
impl UnsafeUnpin for NetworkManager
impl UnwindSafe for NetworkManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more