From 3f69f6948799382bee7241254b3611b03e66f34a Mon Sep 17 00:00:00 2001 From: Ben-PH Date: Thu, 18 Dec 2025 21:51:27 +0100 Subject: [PATCH] chore: cargo-fmt --- neverust-core/src/advertiser.rs | 4 ++-- neverust-core/src/blockexc.rs | 28 +++++++++++++++++++--------- neverust-core/src/chunker.rs | 1 - neverust-core/src/config.rs | 2 +- neverust-core/src/manifest.rs | 7 ++++++- neverust-core/src/p2p.rs | 5 ++--- neverust-core/src/pending_blocks.rs | 7 ++++++- neverust-core/src/runtime.rs | 11 +++-------- neverust-core/src/traffic.rs | 7 +++++-- tests/integration_test.rs | 28 ++++++++++++---------------- tests/manifest_integration.rs | 10 +++++----- 11 files changed, 61 insertions(+), 49 deletions(-) diff --git a/neverust-core/src/advertiser.rs b/neverust-core/src/advertiser.rs index 553450d..50ea5dc 100644 --- a/neverust-core/src/advertiser.rs +++ b/neverust-core/src/advertiser.rs @@ -184,7 +184,7 @@ impl Advertiser { /// Stop the advertiser engine pub async fn stop(&self) { - { + { let mut running = self.running.write().await; if !*running { return; @@ -192,7 +192,7 @@ impl Advertiser { info!("Stopping advertiser engine"); *running = false; - } + } // Send stop message let _ = self.tx.send(AdvertiseMessage::Stop); diff --git a/neverust-core/src/blockexc.rs b/neverust-core/src/blockexc.rs index 97dfd9a..6dc16fb 100644 --- a/neverust-core/src/blockexc.rs +++ b/neverust-core/src/blockexc.rs @@ -86,7 +86,9 @@ async fn write_length_prefixed( pub enum BlockExcMode { #[default] Altruistic, - MarketPlace{ price_per_byte: u64 }, + MarketPlace { + price_per_byte: u64, + }, } impl std::str::FromStr for BlockExcMode { type Err = &'static str; @@ -95,17 +97,16 @@ impl std::str::FromStr for BlockExcMode { match s { "altruistic" => Ok(Self::Altruistic), "marketplace" => Ok(Self::MarketPlace { price_per_byte: 1 }), - _ => Err("unrecognised mode (options: 'altruistic', 'marketplace')") + _ => Err("unrecognised mode (options: 'altruistic', 'marketplace')"), } } } - impl BlockExcMode { pub fn mode_string(&self) -> String { match self { Self::Altruistic => "altruistic".to_string(), - Self::MarketPlace { price_per_byte } => format!("Market @ {} per byte", price_per_byte) + Self::MarketPlace { price_per_byte } => format!("Market @ {} per byte", price_per_byte), } } fn price_per_byte(&self) -> Option { @@ -115,7 +116,6 @@ impl BlockExcMode { None } } - } /// BlockExc connection handler pub struct BlockExcHandler { @@ -244,7 +244,11 @@ impl ConnectionHandler for BlockExcHandler { let block_store = self.block_store.clone(); let mode = self.mode.clone(); let metrics = self.metrics.clone(); - info!("BlockExc: Fully negotiated inbound stream from {} (mode: {})", peer_id, mode.mode_string()); + info!( + "BlockExc: Fully negotiated inbound stream from {} (mode: {})", + peer_id, + mode.mode_string() + ); // Spawn task to handle the stream - read messages from remote peer tokio::spawn(async move { @@ -364,7 +368,10 @@ impl ConnectionHandler for BlockExcHandler { break; } } - } else if let BlockExcMode::MarketPlace { price_per_byte: _ } = mode { + } else if let BlockExcMode::MarketPlace { + price_per_byte: _, + } = mode + { // MARKETPLACE MODE: Check payment before serving info!("BlockExc: MARKETPLACE MODE - checking payment from {}", peer_id); @@ -443,7 +450,10 @@ impl ConnectionHandler for BlockExcHandler { { let block_price = (block.data.len() as u64) - * mode.price_per_byte().unwrap_or_default(); + * mode + .price_per_byte() + .unwrap_or_default( + ); info!("BlockExc: Block {} available for {} units", cid, block_price); block_presences.push( @@ -481,7 +491,7 @@ impl ConnectionHandler for BlockExcHandler { } } } - } + } } } Err(e) => { diff --git a/neverust-core/src/chunker.rs b/neverust-core/src/chunker.rs index 32ece86..370fd8b 100644 --- a/neverust-core/src/chunker.rs +++ b/neverust-core/src/chunker.rs @@ -63,7 +63,6 @@ impl Chunker { Ok(Some(buffer)) } - } impl Chunker { diff --git a/neverust-core/src/config.rs b/neverust-core/src/config.rs index 90ec7d5..68e02a1 100644 --- a/neverust-core/src/config.rs +++ b/neverust-core/src/config.rs @@ -92,7 +92,7 @@ impl Default for Config { api_port: 8080, log_level: "info".to_string(), bootstrap_nodes: Vec::new(), - mode: BlockExcMode::MarketPlace { price_per_byte: 1 } + mode: BlockExcMode::MarketPlace { price_per_byte: 1 }, } } } diff --git a/neverust-core/src/manifest.rs b/neverust-core/src/manifest.rs index 470dcc5..9992d18 100644 --- a/neverust-core/src/manifest.rs +++ b/neverust-core/src/manifest.rs @@ -227,7 +227,12 @@ impl Manifest { hcodec: self.hcodec as u32, version: self.version, filename: self.filename.clone().unwrap_or_default(), - mimetype: self.mimetype.as_ref().map(|mt| mt.essence_str().to_string()).unwrap_or_default().to_string(), + mimetype: self + .mimetype + .as_ref() + .map(|mt| mt.essence_str().to_string()) + .unwrap_or_default() + .to_string(), ..Default::default() }; diff --git a/neverust-core/src/p2p.rs b/neverust-core/src/p2p.rs index dcbc6c3..258a42b 100644 --- a/neverust-core/src/p2p.rs +++ b/neverust-core/src/p2p.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use std::time::Duration; use thiserror::Error; -use crate::blockexc::{BlockExcMode, BlockExcBehaviour }; +use crate::blockexc::{BlockExcBehaviour, BlockExcMode}; use crate::identify_shim::{IdentifyBehaviour, IdentifyConfig}; use crate::storage::BlockStore; @@ -117,8 +117,7 @@ pub async fn create_swarm( let identify_behaviour = IdentifyBehaviour::new(identify_config); // Create behavior: BlockExc + Identify - let (blockexc_behaviour, block_request_tx) = - BlockExcBehaviour::new(block_store, mode, metrics); + let (blockexc_behaviour, block_request_tx) = BlockExcBehaviour::new(block_store, mode, metrics); let behaviour = Behaviour { blockexc: blockexc_behaviour, identify: identify_behaviour, diff --git a/neverust-core/src/pending_blocks.rs b/neverust-core/src/pending_blocks.rs index 5eff89b..ea8df85 100644 --- a/neverust-core/src/pending_blocks.rs +++ b/neverust-core/src/pending_blocks.rs @@ -236,7 +236,12 @@ impl PendingBlocksManager { /// Get the number of retries remaining for a block pub fn retries_remaining(&self, cid: &Cid) -> Option { - self.state.lock().unwrap().pending.get(cid).map(|p| p.retries_left) + self.state + .lock() + .unwrap() + .pending + .get(cid) + .map(|p| p.retries_left) } /// Check if retries are exhausted for a block diff --git a/neverust-core/src/runtime.rs b/neverust-core/src/runtime.rs index d75f526..187b1e9 100644 --- a/neverust-core/src/runtime.rs +++ b/neverust-core/src/runtime.rs @@ -37,12 +37,8 @@ pub async fn run_node(config: Config) -> Result<(), P2PError> { info!("Initialized metrics collector"); // Create swarm first to get peer ID (pass metrics for P2P traffic tracking) - let (mut swarm, block_request_tx, keypair) = create_swarm( - block_store.clone(), - config.mode.clone(), - metrics.clone(), - ) - .await?; + let (mut swarm, block_request_tx, keypair) = + create_swarm(block_store.clone(), config.mode.clone(), metrics.clone()).await?; let peer_id = swarm.local_peer_id().to_string(); // Initialize BlockExc client for requesting blocks from peers (via channel to swarm) @@ -275,7 +271,6 @@ pub async fn run_node(config: Config) -> Result<(), P2PError> { config.bootstrap_nodes.clone() }; - // Main event loop main_loop(swarm, listen_addrs, bootstrap_addrs, metrics).await; @@ -286,7 +281,7 @@ async fn main_loop( mut swarm: Swarm, listen_addrs: Arc>>, bootstrap_addrs: Vec, - metrics: Metrics + metrics: Metrics, ) { // Track if we've established listen addresses let mut tcp_listening = false; diff --git a/neverust-core/src/traffic.rs b/neverust-core/src/traffic.rs index 6ca7616..c94e991 100644 --- a/neverust-core/src/traffic.rs +++ b/neverust-core/src/traffic.rs @@ -134,13 +134,16 @@ async fn block_upload_loop_p2p( "[TRAFFIC-P2P] Node {} failed to create block: {}", config.node_id, e ); - continue + continue; } }; let cid = block.cid; match block_store.put(block).await { Ok(_) => { - info!("[TRAFFIC-P2P] Node {} generated 1MiB block: {} - advertising to network", config.node_id, cid); + info!( + "[TRAFFIC-P2P] Node {} generated 1MiB block: {} - advertising to network", + config.node_id, cid + ); // Track this CID for P2P discovery known_cids.write().await.insert(cid); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 47d1ee7..25a4340 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -53,10 +53,9 @@ async fn test_create_swarm_and_listen() { let block_store = Arc::new(BlockStore::new()); let metrics = Metrics::new(); - let (mut swarm, _tx, _keypair) = - create_swarm(block_store, BlockExcMode::Altruistic, metrics) - .await - .expect("Failed to create swarm"); + let (mut swarm, _tx, _keypair) = create_swarm(block_store, BlockExcMode::Altruistic, metrics) + .await + .expect("Failed to create swarm"); let peer_id = *swarm.local_peer_id(); info!("✅ Created swarm with peer ID: {}", peer_id); @@ -114,10 +113,9 @@ async fn test_dial_bootstrap_node() { // Create swarm let block_store = Arc::new(BlockStore::new()); let metrics = Metrics::new(); - let (mut swarm, _tx, _keypair) = - create_swarm(block_store, BlockExcMode::Altruistic, metrics) - .await - .expect("Failed to create swarm"); + let (mut swarm, _tx, _keypair) = create_swarm(block_store, BlockExcMode::Altruistic, metrics) + .await + .expect("Failed to create swarm"); let local_peer_id = *swarm.local_peer_id(); info!("📝 Local peer ID: {}", local_peer_id); @@ -254,10 +252,9 @@ async fn test_connect_and_verify_all_protocols() { // Create swarm let block_store = Arc::new(BlockStore::new()); let metrics = Metrics::new(); - let (mut swarm, _tx, _keypair) = - create_swarm(block_store, BlockExcMode::Altruistic, metrics) - .await - .expect("Failed to create swarm"); + let (mut swarm, _tx, _keypair) = create_swarm(block_store, BlockExcMode::Altruistic, metrics) + .await + .expect("Failed to create swarm"); info!("📝 Local peer: {}", swarm.local_peer_id()); // Listen @@ -509,10 +506,9 @@ async fn test_blockexc_protocol_detailed() { // Create swarm let block_store = Arc::new(BlockStore::new()); let metrics = Metrics::new(); - let (mut swarm, _tx, _keypair) = - create_swarm(block_store, BlockExcMode::Altruistic, metrics) - .await - .expect("Failed to create swarm"); + let (mut swarm, _tx, _keypair) = create_swarm(block_store, BlockExcMode::Altruistic, metrics) + .await + .expect("Failed to create swarm"); let local_peer_id = *swarm.local_peer_id(); info!("📝 Local peer: {}", local_peer_id); diff --git a/tests/manifest_integration.rs b/tests/manifest_integration.rs index cdc90a8..aa8630a 100644 --- a/tests/manifest_integration.rs +++ b/tests/manifest_integration.rs @@ -76,10 +76,10 @@ async fn test_manifest_with_metadata() { tree_cid, DEFAULT_BLOCK_SIZE as u64, test_data.len() as u64, - Some(0xcd02), // codex-block codec - Some(0x12), // sha2-256 codec - Some(1), // version - None, // filename + Some(0xcd02), // codex-block codec + Some(0x12), // sha2-256 codec + Some(1), // version + None, // filename Some(mime::TEXT_PLAIN), // mimetype ); @@ -145,7 +145,7 @@ async fn test_manifest_encoding_decoding() { Some(0xcd02), Some(0x12), Some(1), - None, // filename + None, // filename Some(mime::APPLICATION_OCTET_STREAM), // mimetype );