Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
feat: Improved IPFS Kubo syndication (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdata authored Oct 6, 2023
1 parent 2033a56 commit eeab932
Show file tree
Hide file tree
Showing 32 changed files with 621 additions and 370 deletions.
88 changes: 3 additions & 85 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ resolver = "2"

[workspace.dependencies]
anyhow = { version = "1" }
async-recursion = { version = "1" }
async-stream = { version = "0.3" }
axum = { version = "^0.6.18" }
bytes = { version = "^1" }
Expand All @@ -34,6 +35,8 @@ js-sys = { version = "^0.3" }
libipld = { version = "0.16" }
libipld-core = { version = "0.16" }
libipld-cbor = { version = "0.16" }
libipld-json = { version = "0.16" }
multihash = { version = "0.18" }
pathdiff = { version = "0.2.1" }
rand = { version = "0.8" }
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls", "stream"] }
Expand Down
8 changes: 4 additions & 4 deletions rust/noosphere-cli/src/native/commands/sphere/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub async fn auth_list(tree: bool, as_json: bool, workspace: &Workspace) -> Resu
while let Some((name, identity, link)) = authorization_stream.try_next().await? {
let jwt = Jwt(db.require_token(&link).await?);
max_name_length = max_name_length.max(name.len());
authorization_meta.insert(link.clone(), (name, identity, jwt));
authorization_meta.insert(link, (name, identity, jwt));
}

if tree {
Expand All @@ -162,13 +162,13 @@ pub async fn auth_list(tree: bool, as_json: bool, workspace: &Workspace) -> Resu
if *ucan.issuer() == sphere_identity {
// TODO(#554): Such an authorization ought not have any topical proofs,
// but perhaps we should verify that
authorization_roots.push(link.clone())
authorization_roots.push(*link)
} else {
for proof in proofs {
let items = match authorization_hierarchy.get_mut(&proof) {
Some(items) => items,
None => {
authorization_hierarchy.insert(proof.clone(), Vec::new());
authorization_hierarchy.insert(proof, Vec::new());
authorization_hierarchy.get_mut(&proof).ok_or_else(|| {
anyhow!(
"Could not access list of child authorizations for {}",
Expand All @@ -177,7 +177,7 @@ pub async fn auth_list(tree: bool, as_json: bool, workspace: &Workspace) -> Resu
})?
}
};
items.push(link.clone());
items.push(*link);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-cli/src/native/commands/sphere/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::workspace::Workspace;
pub async fn history(workspace: &Workspace) -> Result<()> {
let sphere_context = workspace.sphere_context().await?;
let sphere = sphere_context.to_sphere().await?;
let latest_version = sphere.cid().clone();
let latest_version = *sphere.cid();
let db = sphere.store().clone();

let history_stream = sphere.into_history_stream(None);
Expand Down
8 changes: 3 additions & 5 deletions rust/noosphere-cli/src/native/render/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ where

// Create a symlink to each peer (they will be rendered later, if
// they haven't been already)
petname_change_buffer.add(name.clone(), (did.clone(), cid.clone().into()))?;
petname_change_buffer.add(name.clone(), (did.clone(), cid.into()))?;

if petname_change_buffer.is_full() {
petname_change_buffer.flush_to_writer(&self.writer).await?;
Expand Down Expand Up @@ -278,10 +278,8 @@ where
Some(identity) => match cursor.get_petname_record(&petname).await? {
Some(link_record) => {
if let Some(version) = link_record.get_link() {
petname_change_buffer.add(
petname.clone(),
(identity.clone(), Cid::from(version.clone())),
)?;
petname_change_buffer
.add(petname.clone(), (identity.clone(), Cid::from(version)))?;

let mut petname_path = self.petname_path.clone();
petname_path.push(petname);
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ forest_hash_utils = "0.1.0"
serde = { workspace = true }
serde_bytes = "0.11"
byteorder = "^1.4"
async-recursion = "^1"
async-recursion = { workspace = true }
libipld-core = { workspace = true }
libipld-cbor = { workspace = true }
noosphere-storage = { version = "0.9.0", path = "../noosphere-storage" }
Expand Down
5 changes: 1 addition & 4 deletions rust/noosphere-common/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ mod tests {
});

let res = client.send(Request::Ping()).await?;
assert!(match res {
Ok(Response::Pong()) => true,
_ => false,
});
matches!(res, Ok(Response::Pong()));

for n in 0..10 {
client.send_oneshot(Request::SetFlag(n))?;
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tracing = { workspace = true }
cid = { workspace = true }
url = { workspace = true, features = ["serde"] }
async-trait = "~0.1"
async-recursion = "^1"
async-recursion = { workspace = true }
async-stream = { workspace = true }

# NOTE: async-once-cell 0.4.0 shipped unstable feature usage
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-core/src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ where
store: S,
push_body: v0alpha2::PushBody,
) -> impl Stream<Item = Result<Bytes, std::io::Error>> + ConditionalSync + 'static {
let root = push_body.local_tip.clone().into();
let root = push_body.local_tip.into();
trace!("Creating push stream...");

let block_stream = try_stream! {
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-core/src/context/content/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where
let hamt = links.get_hamt().await?;

Ok(match hamt.get(&slug.to_string()).await? {
Some(memo) => Some(self.get_file(&revision, memo.clone()).await?),
Some(memo) => Some(self.get_file(&revision, *memo).await?),
None => None,
})
}
Expand Down
12 changes: 6 additions & 6 deletions rust/noosphere-core/src/context/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
SphereCursor {
has_sphere_context,
storage: PhantomData,
sphere_version: Some(sphere_version.clone()),
sphere_version: Some(*sphere_version),
}
}

Expand All @@ -66,7 +66,7 @@ where
/// version it is mounted to even when the latest version of the sphere
/// changes.
pub async fn mount_at(&mut self, sphere_version: &Link<MemoIpld>) -> Result<&Self> {
self.sphere_version = Some(sphere_version.clone());
self.sphere_version = Some(*sphere_version);

Ok(self)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ where

match sphere.get_parent().await? {
Some(parent) => {
self.sphere_version = Some(parent.cid().clone());
self.sphere_version = Some(*parent.cid());
Ok(self.sphere_version.as_ref())
}
None => Ok(None),
Expand Down Expand Up @@ -140,7 +140,7 @@ where
let new_version = self.has_sphere_context.save(additional_headers).await?;

if self.sphere_version.is_some() {
self.sphere_version = Some(new_version.clone());
self.sphere_version = Some(new_version);
}

Ok(new_version)
Expand All @@ -162,7 +162,7 @@ where

async fn version(&self) -> Result<Link<MemoIpld>> {
match &self.sphere_version {
Some(sphere_version) => Ok(sphere_version.clone()),
Some(sphere_version) => Ok(*sphere_version),
None => self.has_sphere_context.version().await,
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ where

async move {
let replicate_parameters = since.as_ref().map(|since| ReplicateParameters {
since: Some(since.clone()),
since: Some(*since),
});
let (db, client) = {
let sphere_context = cursor.sphere_context().await?;
Expand Down
13 changes: 6 additions & 7 deletions rust/noosphere-core/src/context/sync/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ where
.into();
return Ok((
local_sphere_tip,
counterpart_sphere_base
.ok_or_else(|| anyhow!("Counterpart sphere history is missing!"))?
.clone(),
*counterpart_sphere_base
.ok_or_else(|| anyhow!("Counterpart sphere history is missing!"))?,
updated_names,
));
}
Expand Down Expand Up @@ -272,12 +271,12 @@ where
)
.await?;

new_base.clone()
new_base
}
// No new history at all
(Some(current_tip), _, _) => {
info!("Nothing to sync!");
current_tip.clone()
*current_tip
}
// We should have local history but we don't!
_ => {
Expand Down Expand Up @@ -409,8 +408,8 @@ where
.push(&PushBody {
sphere: local_sphere_identity.clone(),
local_base: local_sphere_base,
local_tip: local_sphere_tip.clone(),
counterpart_tip: Some(counterpart_sphere_tip.clone()),
local_tip: *local_sphere_tip,
counterpart_tip: Some(*counterpart_sphere_tip),
name_record: Some(name_record),
})
.await?;
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-core/src/data/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ mod tests {

let (sphere, ucan, _) = Sphere::generate(&owner_did, &mut store).await.unwrap();

let original_cid = sphere.cid().clone();
let original_cid = *sphere.cid();

let foo_key = String::from("foo");
let foo_memo = MemoIpld::for_body(&mut store, b"foo").await.unwrap();
Expand Down
Loading

0 comments on commit eeab932

Please sign in to comment.