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

fix: Increase allowed request body payload size #608

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ libipld = { version = "0.16" }
libipld-core = { version = "0.16" }
libipld-cbor = { version = "0.16" }
pathdiff = { version = "0.2.1" }
rand = { version = "0.8" }
sentry-tracing = { version = "0.31.5" }
serde = { version = "^1" }
serde_json = { version = "^1" }
Expand Down
1 change: 1 addition & 0 deletions rust/noosphere-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cid = { workspace = true }
symlink = { workspace = true }
pathdiff = { workspace = true }
subtext = "0.3.2"
rand = {workspace = true }

serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions rust/noosphere-cli/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(dead_code)]

mod cli;
mod random;

pub use crate::helpers::random::*;
pub use cli::*;

use anyhow::Result;
Expand Down
35 changes: 35 additions & 0 deletions rust/noosphere-cli/tests/helpers/random.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use rand::{rngs::StdRng, Rng, SeedableRng};
use std::sync::Arc;
use tokio::sync::Mutex;

/// A helper to support consistent use of seeded randomness in tests.
/// Its primary purpose is to retain and report the seed in use for a
/// random number generator that can be shared across threads in tests.
/// This is probably not suitable for use outside of tests.
pub struct TestEntropy {
seed: [u8; 32],
rng: Arc<Mutex<StdRng>>,
}

impl Default for TestEntropy {
fn default() -> Self {
Self::from_seed(rand::thread_rng().gen::<[u8; 32]>())
}
}

impl TestEntropy {
pub fn from_seed(seed: [u8; 32]) -> Self {
tracing::info!(?seed, "Initializing test entropy...");
cdata marked this conversation as resolved.
Show resolved Hide resolved

let rng = Arc::new(Mutex::new(SeedableRng::from_seed(seed.clone())));
Self { seed, rng }
}

pub fn to_rng(&self) -> Arc<Mutex<StdRng>> {
self.rng.clone()
}

pub fn seed(&self) -> &[u8] {
&self.seed
}
}
113 changes: 113 additions & 0 deletions rust/noosphere-cli/tests/peer_to_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ use noosphere_sphere::{
SpherePetnameRead, SpherePetnameWrite, SphereReplicaRead, SphereSync, SphereWalker,
SyncRecovery,
};
use rand::Rng;
justinabrahms marked this conversation as resolved.
Show resolved Hide resolved
use std::collections::BTreeSet;
use std::sync::Arc;
use tokio::io::AsyncReadExt;
use tokio_stream::StreamExt;
use url::Url;

use crate::helpers::TestEntropy;

#[tokio::test]
async fn gateway_publishes_and_resolves_petnames_configured_by_the_client() -> Result<()> {
initialize_tracing(None);
Expand Down Expand Up @@ -669,3 +672,113 @@ async fn local_lineage_remains_sparse_as_graph_changes_accrue_over_time() -> Res
ns_task.abort();
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn clients_can_sync_when_there_is_a_lot_of_content() -> Result<()> {
initialize_tracing(None);

let entropy = TestEntropy::default();
let rng = entropy.to_rng();

let ipfs_url = Url::parse("http://127.0.0.1:5001").unwrap();
let (ns_url, ns_task) = start_name_system_server(&ipfs_url).await.unwrap();

let mut pair_1 = SpherePair::new("ONE", &ipfs_url, &ns_url).await?;
let mut pair_2 = SpherePair::new("TWO", &ipfs_url, &ns_url).await?;

pair_1.start_gateway().await?;
pair_2.start_gateway().await?;

let peer_2_identity = pair_2.client.workspace.sphere_identity().await?;
let pair_2_rng = rng.clone();

pair_2
.spawn(|mut ctx| async move {
let mut rng = pair_2_rng.lock().await;

// Long history, small-ish files
for _ in 0..1000 {
let random_index = rng.gen_range(0..100);
let mut random_bytes = Vec::from(rng.gen::<[u8; 32]>());
let slug = format!("slug{}", random_index);

let next_bytes = if let Some(mut file) = ctx.read(&slug).await? {
let mut file_bytes = Vec::new();
file.contents.read_to_end(&mut file_bytes).await?;
file_bytes.append(&mut random_bytes);
file_bytes
} else {
random_bytes
};

ctx.write(&slug, &ContentType::Bytes, next_bytes.as_ref(), None)
.await?;
ctx.save(None).await?;
}

Ok(ctx.sync(SyncRecovery::Retry(3)).await?)
})
.await?;

let pair_1_rng = rng.clone();

pair_1
.spawn(|mut ctx| async move {
let mut rng = pair_1_rng.lock().await;

// Modest history, large-ish files
for _ in 0..100 {
let mut random_bytes = (0..1000).fold(Vec::new(), |mut bytes, _| {
bytes.append(&mut Vec::from(rng.gen::<[u8; 32]>()));
bytes
});
let random_index = rng.gen_range(0..10);
let slug = format!("slug{}", random_index);

let next_bytes = if let Some(mut file) = ctx.read(&slug).await? {
let mut file_bytes = Vec::new();
file.contents.read_to_end(&mut file_bytes).await?;
file_bytes.append(&mut random_bytes);
file_bytes
} else {
random_bytes
};

ctx.write(&slug, &ContentType::Bytes, next_bytes.as_ref(), None)
.await?;

ctx.save(None).await?;
}

ctx.sync(SyncRecovery::Retry(3)).await?;

ctx.set_petname("peer2", Some(peer_2_identity)).await?;

ctx.save(None).await?;

ctx.sync(SyncRecovery::Retry(3)).await?;

// TODO(#606): Implement this part of the test when we "fix" latency asymmetry between
// name system and syndication workers. We should be able to test traversing to a peer
// after a huge update as been added to the name system.
/*
wait(1).await;

ctx.sync(SyncRecovery::Retry(3)).await?;

wait(1).await;

let cursor = SphereCursor::latest(ctx);
let _peer2_ctx = cursor
.traverse_by_petnames(&["peer2".into()])
.await?
.unwrap();
*/
Ok(())
})
.await?;

ns_task.abort();

Ok(())
}
4 changes: 4 additions & 0 deletions rust/noosphere-gateway/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use axum::extract::DefaultBodyLimit;
use axum::http::{HeaderValue, Method};
use axum::routing::{get, put};
use axum::{Extension, Router, Server};
Expand All @@ -23,6 +24,8 @@ use crate::{

use noosphere_core::tracing::initialize_tracing;

pub const DEFAULT_BODY_LENGTH_LIMIT: usize = 100 /* MB */ * 1000 * 1000;

#[derive(Clone, Debug)]
pub struct GatewayScope {
/// Identity of gateway sphere.
Expand Down Expand Up @@ -99,6 +102,7 @@ where
.layer(Extension(gateway_key_did))
.layer(Extension(syndication_tx))
.layer(Extension(name_system_tx))
.layer(DefaultBodyLimit::max(DEFAULT_BODY_LENGTH_LIMIT))
.layer(cors)
.layer(TraceLayer::new_for_http());

Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-ipfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ipfs-api-prelude = "0.6"
[dev-dependencies]

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
rand = "~0.8"
rand = { workspace = true }
iroh-car = { workspace = true }
libipld-cbor = { workspace = true }
noosphere-core = { version = "0.15.1", path = "../noosphere-core" }
2 changes: 1 addition & 1 deletion rust/noosphere-ns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ url = { version = "^2", features = [ "serde" ], optional = true }
[dev-dependencies]

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
rand = { version = "0.8.5" }
rand = { workspace = true }
libipld-cbor = { workspace = true }
tempfile = { workspace = true }

Expand Down
7 changes: 7 additions & 0 deletions rust/noosphere-sphere/src/sync/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ where
.bundle_until_ancestor(local_sphere_base.as_ref())
.await?;

let mut byte_count = 0;
for bytes in bundle.map().values() {
byte_count += bytes.len();
}

trace!("Total bytes in bundle to be pushed: {}", byte_count);

let client = context.client().await?;

let local_sphere_identity = context.identity();
Expand Down
3 changes: 3 additions & 0 deletions rust/noosphere/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// TODO(getditto/safer_ffi#181): Re-enable this lint
#![allow(clippy::incorrect_clone_impl_on_copy_type)]

mod authority;
mod context;
mod error;
Expand Down