Skip to content

Commit

Permalink
Move more into glue.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Oct 21, 2024
1 parent ee341f8 commit d7a154d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
24 changes: 24 additions & 0 deletions iroh-willow/src/store/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ pub(crate) fn blobseq_successor(blobseq: &BlobSeq) -> BlobSeq {
)
}

pub(crate) fn blobseq_below(blobseq: &BlobSeq) -> Option<BlobSeq> {
let mut path = blobseq
.components()
.map(|slice| slice.to_vec())
.collect::<Vec<_>>();

if path
.last_mut()
.map(|last_path| match last_path.last_mut() {
Some(255) | None => {
last_path.push(0);
}
Some(i) => {
*i += 1;
}
})
.is_some()
{
Some(BlobSeq::from(path))
} else {
None
}
}

pub(crate) fn to_query(range3d: &Range3d) -> QueryRange3d<IrohWillowParams> {
let path_start = path_to_blobseq(&range3d.paths().start);
let path_end = match &range3d.paths().end {
Expand Down
37 changes: 7 additions & 30 deletions iroh-willow/src/store/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use futures_lite::ready;
use futures_util::Stream;
use tracing::debug;
use willow_data_model::SubspaceId as _;
use willow_store::{BlobSeq, QueryRange, QueryRange3d};
use willow_store::{QueryRange, QueryRange3d};

use crate::proto::data_model::{AuthorisationToken, PathExt};
use crate::proto::grouping::Area;
use crate::store::glue::StoredAuthorisedEntry;
use crate::store::glue::{blobseq_below, StoredAuthorisedEntry};
use crate::{
interest::{CapSelector, CapabilityPack},
proto::{
Expand Down Expand Up @@ -136,6 +136,7 @@ impl Clone for NamespaceStore {
fn clone(&self) -> Self {
Self {
entries: self.entries.clone(),
// TODO(matheus23): This is hacky!
events: Default::default(),
}
}
Expand Down Expand Up @@ -304,30 +305,6 @@ impl traits::EntryReader for Rc<RefCell<EntryStore>> {
}
}

fn blobseq_below(blobseq: &BlobSeq) -> Option<BlobSeq> {
let mut path = blobseq
.components()
.map(|slice| slice.to_vec())
.collect::<Vec<_>>();

if path
.last_mut()
.map(|last_path| match last_path.last_mut() {
Some(255) | None => {
last_path.push(0);
}
Some(i) => {
*i += 1;
}
})
.is_some()
{
Some(BlobSeq::from(path))
} else {
None
}
}

impl EntryStore {
fn ingest_entry(&mut self, entry: &AuthorisedEntry, origin: EntryOrigin) -> Result<bool> {
let namespace = *entry.entry().namespace_id();
Expand Down Expand Up @@ -513,7 +490,7 @@ impl Stream for EventStream {
// TODO: This would be quite a bit more efficient if we filtered the waker with a closure
// that is set from the last poll, to not wake everyone for each new event.
#[derive(Debug)]
struct EventQueue<T> {
pub(super) struct EventQueue<T> {
events: VecDeque<T>,
offset: u64,
wakers: VecDeque<Waker>,
Expand All @@ -538,7 +515,7 @@ impl<T> Default for EventQueue<T> {
}

impl<T: Clone> EventQueue<T> {
fn insert(&mut self, f: impl FnOnce(u64) -> T) {
pub(super) fn insert(&mut self, f: impl FnOnce(u64) -> T) {
let progress_id = self.next_progress_id();
let event = f(progress_id);
self.events.push_back(event);
Expand All @@ -547,11 +524,11 @@ impl<T: Clone> EventQueue<T> {
}
}

fn next_progress_id(&self) -> u64 {
pub(super) fn next_progress_id(&self) -> u64 {
self.offset + self.events.len() as u64
}

fn get(&self, progress_id: u64) -> Option<&T> {
pub(super) fn get(&self, progress_id: u64) -> Option<&T> {
let index = progress_id.checked_sub(self.offset)?;
self.events.get(index as usize)
}
Expand Down

0 comments on commit d7a154d

Please sign in to comment.