Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: leave and drop docs #1589

Merged
merged 12 commits into from
Oct 10, 2023
8 changes: 4 additions & 4 deletions iroh-sync/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ impl fmt::Debug for Author {

impl fmt::Debug for NamespacePublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "NamespaceId({})", self)
write!(f, "NamespacePublicKey({})", self)
}
}

impl fmt::Debug for AuthorPublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "AuthorId({})", self)
write!(f, "AuthorPublicKey({})", self)
}
}

Expand Down Expand Up @@ -410,7 +410,7 @@ impl AuthorId {
/// Convert into [`AuthorPublicKey`].
///
/// Fails if the bytes of this [`AuthorId`] are not a valid [`ed25519_dalek`] curve point.
pub fn into_public_key<S: PublicKeyStore>(&self) -> Result<AuthorPublicKey, SignatureError> {
pub fn into_public_key(&self) -> Result<AuthorPublicKey, SignatureError> {
AuthorPublicKey::from_bytes(&self.0)
}
}
Expand Down Expand Up @@ -439,7 +439,7 @@ impl NamespaceId {
/// Convert into [`NamespacePublicKey`].
///
/// Fails if the bytes of this [`NamespaceId`] are not a valid [`ed25519_dalek`] curve point.
pub fn into_public_key<S: PublicKeyStore>(&self) -> Result<NamespacePublicKey, SignatureError> {
pub fn into_public_key(&self) -> Result<NamespacePublicKey, SignatureError> {
NamespacePublicKey::from_bytes(&self.0)
}
}
Expand Down
6 changes: 6 additions & 0 deletions iroh-sync/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ pub trait Store: std::fmt::Debug + Clone + Send + Sync + 'static {
/// instance from the store's cache.
fn close_replica(&self, namespace: &NamespaceId);

/// Remove a replica.
///
/// Completely removes a replica and deletes both the namespace private key and all document
/// entries.
fn remove_replica(&self, namespace: &NamespaceId) -> Result<()>;

/// Create a new author key and persist it in the store.
fn new_author<R: CryptoRngCore + ?Sized>(&self, rng: &mut R) -> Result<Author> {
let author = Author::new(rng);
Expand Down
22 changes: 19 additions & 3 deletions iroh-sync/src/store/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl super::Store for Store {

fn close_replica(&self, namespace_id: &NamespaceId) {
if let Some(replica) = self.replicas.write().remove(namespace_id) {
replica.unsubscribe();
replica.close();
}
}

Expand Down Expand Up @@ -193,6 +193,22 @@ impl super::Store for Store {
Ok(replica)
}

fn remove_replica(&self, namespace: &NamespaceId) -> Result<()> {
self.close_replica(namespace);
self.replicas.write().remove(namespace);
let start = range_start(namespace);
let end = range_end(namespace);
let write_tx = self.db.begin_write()?;
{
let mut record_table = write_tx.open_table(RECORDS_TABLE)?;
record_table.drain(start..=end)?;
let mut namespace_table = write_tx.open_table(NAMESPACES_TABLE)?;
namespace_table.remove(namespace.as_bytes())?;
}
write_tx.commit()?;
Ok(())
}

fn get_many(
&self,
namespace: NamespaceId,
Expand Down Expand Up @@ -445,7 +461,7 @@ impl crate::ranger::Store<SignedEntry> for StoreInstance {
// iterator for all entries in replica
let iter = RangeIterator::with_range(
&self.store.db,
|table| table.range(start..end),
|table| table.range(start..=end),
RangeFilter::None,
)?;
// empty iterator, returns nothing
Expand Down Expand Up @@ -481,7 +497,7 @@ impl crate::ranger::Store<SignedEntry> for StoreInstance {
// iterator for entries from range.x to end
let iter2 = RangeIterator::with_range(
&self.store.db,
|table| table.range(start..end),
|table| table.range(start..=end),
RangeFilter::None,
)?;
iter.chain(iter2)
Expand Down
9 changes: 8 additions & 1 deletion iroh-sync/src/store/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl super::Store for Store {

fn close_replica(&self, namespace_id: &NamespaceId) {
if let Some(replica) = self.replicas.read().get(namespace_id) {
replica.unsubscribe();
replica.close();
}
}

Expand Down Expand Up @@ -95,6 +95,13 @@ impl super::Store for Store {
Ok(replica)
}

fn remove_replica(&self, namespace: &NamespaceId) -> Result<()> {
self.close_replica(namespace);
self.replicas.write().remove(namespace);
self.replica_records.write().remove(namespace);
Ok(())
}

fn get_many(
&self,
namespace: NamespaceId,
Expand Down
Loading