Struct Database

Source
pub struct Database {
    pub db: Arc<ConnectionThreadSafe>,
}
Expand description

A file-backed database storing information about the network.

Fields§

§db: Arc<ConnectionThreadSafe>

Implementations§

Source§

impl Database

Source

pub fn open<P>(path: P) -> Result<Database, Error>
where P: AsRef<Path>,

Open a database at the given path. Creates a new database if it doesn’t exist.

Source

pub fn reader<P>(path: P) -> Result<Database, Error>
where P: AsRef<Path>,

Same as Self::open, but in read-only mode. This is useful to have multiple open databases, as no locking is required.

Source

pub fn journal_mode(self, mode: JournalMode) -> Result<Database, Error>

Set journal mode.

Source

pub fn init<'a>( self, node: &PublicKey, features: Features, alias: &Alias, agent: &UserAgent, timestamp: Timestamp, addrs: impl IntoIterator<Item = &'a Address>, ) -> Result<Database, Error>

Initialize by adding our local node to the database.

Source

pub fn memory() -> Result<Database, Error>

Create a new in-memory database.

Source

pub fn version(&self) -> Result<usize, Error>

Get the database version. This is updated on schema changes.

Source

pub fn bump(&self) -> Result<usize, Error>

Bump the database version.

Methods from Deref<Target = Connection>§

Source

pub fn execute<T>(&self, statement: T) -> Result<(), Error>
where T: AsRef<str>,

Execute a statement without processing the resulting rows if any.

Source

pub fn iterate<T, F>(&self, statement: T, callback: F) -> Result<(), Error>
where T: AsRef<str>, F: FnMut(&[(&str, Option<&str>)]) -> bool,

Execute a statement and process the resulting rows as plain text.

The callback is triggered for each row. If the callback returns false, no more rows will be processed. For large queries and non-string data types, prepared statement are highly preferable; see prepare.

Source

pub fn prepare<T>(&self, statement: T) -> Result<Statement<'_>, Error>
where T: AsRef<str>,

Create a prepared statement.

Source

pub fn set_busy_handler<F>(&mut self, callback: F) -> Result<(), Error>
where F: FnMut(usize) -> bool + Send + 'static,

Set a callback for handling busy events.

The callback is triggered when the database cannot perform an operation due to processing of some other request. If the callback returns true, the operation will be repeated.

Source

pub fn set_busy_timeout(&mut self, milliseconds: usize) -> Result<(), Error>

Set an implicit callback for handling busy events that tries to repeat rejected operations until a timeout expires.

Source

pub fn remove_busy_handler(&mut self) -> Result<(), Error>

Remove the callback handling busy events.

Source

pub fn change_count(&self) -> usize

Return the number of rows inserted, updated, or deleted by the most recent INSERT, UPDATE, or DELETE statement.

Source

pub fn total_change_count(&self) -> usize

Return the total number of rows inserted, updated, and deleted by all INSERT, UPDATE, and DELETE statements since the connection was opened.

Trait Implementations§

Source§

impl Clone for Database

Source§

fn clone(&self) -> Database

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Database

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for Database

Source§

type Target = ConnectionThreadSafe

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Database as Deref>::Target

Dereferences the value.
Source§

impl From<ConnectionThreadSafe> for Database

Source§

fn from(db: ConnectionThreadSafe) -> Database

Converts to this type from the input type.
Source§

impl Store for Database

Source§

fn get(&self, node: &PublicKey) -> Result<Option<Node>, Error>

Get the information we have about a node.
Source§

fn is_addr_banned(&self, addr: &Address) -> Result<bool, Error>

Check if an address is banned. Also returns true if the node this address belongs to is banned.
Source§

fn is_ip_banned(&self, ip: IpAddr) -> Result<bool, Error>

Check if an IP is banned.
Source§

fn addresses_of(&self, node: &PublicKey) -> Result<Vec<KnownAddress>, Error>

Get the addresses of a node.
Source§

fn len(&self) -> Result<usize, Error>

Returns the number of addresses.
Source§

fn nodes(&self) -> Result<usize, Error>

Return the number of nodes.
Source§

fn insert( &mut self, node: &PublicKey, version: u8, features: Features, alias: &Alias, pow: u32, agent: &UserAgent, timestamp: Timestamp, addrs: impl IntoIterator<Item = KnownAddress>, ) -> Result<bool, Error>

Insert a node with associated addresses into the store. Read more
Source§

fn remove(&mut self, node: &PublicKey) -> Result<bool, Error>

Remove a node from the store.
Source§

fn entries(&self) -> Result<Box<dyn Iterator<Item = AddressEntry>>, Error>

Get the address entries in the store.
Source§

fn attempted( &self, nid: &PublicKey, addr: &Address, time: Timestamp, ) -> Result<(), Error>

Mark a node as attempted at a certain time.
Source§

fn connected( &self, nid: &PublicKey, addr: &Address, time: Timestamp, ) -> Result<(), Error>

Mark a node as successfully connected at a certain time.
Source§

fn record_ip( &self, nid: &PublicKey, ip: IpAddr, time: Timestamp, ) -> Result<(), Error>

Record a node IP address and connection time.
Source§

fn disconnected( &mut self, nid: &PublicKey, addr: &Address, severity: Severity, ) -> Result<(), Error>

Mark a node as disconnected.
Source§

fn is_empty(&self) -> Result<bool, Error>

Returns true if there are no addresses.
Source§

impl Store for Database

Source§

fn set( &mut self, repo: &RepoId, namespace: &PublicKey, refname: &Qualified<'_>, oid: Oid, timestamp: LocalTime, ) -> Result<bool, Error>

Set a reference under a remote namespace to the given Oid.
Source§

fn get( &self, repo: &RepoId, namespace: &PublicKey, refname: &Qualified<'_>, ) -> Result<Option<(Oid, LocalTime)>, Error>

Get a reference’s Oid and timestamp.
Source§

fn delete( &mut self, repo: &RepoId, namespace: &PublicKey, refname: &Qualified<'_>, ) -> Result<bool, Error>

Delete a reference.
Source§

fn count(&self) -> Result<usize, Error>

Return the number of references.
Source§

fn populate<S>(&mut self, storage: &S) -> Result<(), Error>
where S: ReadStorage,

Populate the database from storage.
Source§

fn is_empty(&self) -> Result<bool, Error>

Check if there are any references.
Source§

impl Store for Database

Source§

fn get(&self, id: &RepoId) -> Result<HashSet<PublicKey>, Error>

Get the nodes seeding the given id.
Source§

fn get_inventory(&self, node: &PublicKey) -> Result<HashSet<RepoId>, Error>

Get the inventory seeded by the given node.
Source§

fn entry( &self, id: &RepoId, node: &PublicKey, ) -> Result<Option<Timestamp>, Error>

Get a specific entry.
Source§

fn add_inventory<'a>( &mut self, ids: impl IntoIterator<Item = &'a RepoId>, node: PublicKey, time: Timestamp, ) -> Result<Vec<(RepoId, InsertResult)>, Error>

Add a new node seeding the given id.
Source§

fn entries( &self, ) -> Result<Box<dyn Iterator<Item = (RepoId, PublicKey)>>, Error>

Iterate over all entries in the routing table.
Source§

fn remove_inventory( &mut self, id: &RepoId, node: &PublicKey, ) -> Result<bool, Error>

Remove an inventory from the given node.
Source§

fn remove_inventories<'a>( &mut self, rids: impl IntoIterator<Item = &'a RepoId>, nid: &PublicKey, ) -> Result<(), Error>

Remove multiple inventories from the given node.
Source§

fn len(&self) -> Result<usize, Error>

Get the total number of routing entries.
Source§

fn prune( &mut self, oldest: Timestamp, limit: Option<usize>, ignore: &PublicKey, ) -> Result<usize, Error>

Prune entries older than the given timestamp.
Source§

fn count(&self, id: &RepoId) -> Result<usize, Error>

Count the number of routes for a specific repo RID.
Source§

fn is_empty(&self) -> Result<bool, Error>

Checks if any entries are available.
Source§

impl Store for Database

Source§

fn synced( &mut self, rid: &RepoId, nid: &PublicKey, at: Oid, timestamp: Timestamp, ) -> Result<bool, Error>

Mark a repo as synced on the given node.
Source§

fn seeds_for( &self, rid: &RepoId, ) -> Result<Box<dyn Iterator<Item = Result<SyncedSeed, Error>> + '_>, Error>

Get nodes that have synced the given repo.
Source§

fn seeded_by( &self, nid: &PublicKey, ) -> Result<Box<dyn Iterator<Item = Result<(RepoId, SyncedAt), Error>> + '_>, Error>

Get the repos seeded by the given node.
Source§

impl Store for Database

Source§

fn prune(&mut self, cutoff: Timestamp) -> Result<usize, Error>

Prune announcements older than the cutoff time.
Source§

fn last(&self) -> Result<Option<Timestamp>, Error>

Get the timestamp of the last announcement in the store.
Source§

fn announced( &mut self, nid: &PublicKey, ann: &Announcement, ) -> Result<Option<u64>, Error>

Process an announcement for the given node. Returns true if the timestamp was updated or the announcement wasn’t there before.
Source§

fn set_relay(&mut self, id: u64, relay: RelayStatus) -> Result<(), Error>

Set whether a message should be relayed or not.
Source§

fn relays(&mut self, now: Timestamp) -> Result<Vec<(u64, Announcement)>, Error>

Return messages that should be relayed.
Source§

fn filtered<'a>( &'a self, filter: &'a Filter, from: Timestamp, to: Timestamp, ) -> Result<Box<dyn Iterator<Item = Result<Announcement, Error>> + 'a>, Error>

Get all the latest gossip messages of all nodes, filtered by inventory filter and announcement timestamps. Read more
Source§

impl StoreExt for Database

Source§

type NodeAlias<'a> = NodeAliasIter<'a> where Database: 'a

Source§

fn nodes_by_alias<'a>( &'a self, alias: &Alias, ) -> Result<<Database as StoreExt>::NodeAlias<'a>, Error>

Source§

impl Store for Database

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AliasStore for T
where T: Store + StoreExt,

Source§

fn alias(&self, nid: &PublicKey) -> Option<Alias>

Retrieve alias of given node. Calls Self::get under the hood.

Source§

fn reverse_lookup(&self, alias: &Alias) -> BTreeMap<Alias, BTreeSet<PublicKey>>

Return all the NodeIds that match the alias. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoInit<ZeroInit> for T

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,