Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit 3427eac

Browse files
authored
Various fixes from testing v0.6.4 (#66)
### Added - Added `DagExported` and `DagExportFailed` responses to `ExportDag` command. - Added `DagTransmissionComplete` response when a DAG has been completely transmitted. ### Changed - MTU is now an optional flag on `controller` - Added `block_size` as a `myceli` config option for controlling IPFS block size in file chunking - Changed default `block_size` to 3072 bytes - Fixed cases where responses inside of dag transfer session weren't sent to original target address
1 parent 67011ec commit 3427eac

File tree

18 files changed

+197
-87
lines changed

18 files changed

+197
-87
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
# Changelog
22

3+
## [0.6.5] - Unreleased
34

4-
## [0.6.4] - Unreleased
5+
### Added
6+
7+
- Added `DagExported` and `DagExportFailed` responses to `ExportDag` command.
8+
- Added `DagTransmissionComplete` response when a DAG has been completely transmitted.
9+
10+
### Changed
11+
12+
- MTU is now an optional flag on `controller`
13+
- Added `block_size` as a `myceli` config option for controlling IPFS block size in file chunking
14+
- Changed default `block_size` to 3072 bytes
15+
- Fixed cases where responses inside of dag transfer session weren't sent to original target address
16+
17+
## [0.6.4] - 2023-05-15
518

619
### Added
720

Cargo.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ members = [
1111
]
1212

1313
[workspace.package]
14-
version = "0.6.3"
14+
version = "0.6.5"
1515
edition = "2021"
1616
license = "Apache-2.0/MIT"
1717
rust-version = "1.68.1"

controller/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use transports::{Transport, UdpTransport};
88
#[clap(about = "Control a Myceli instance")]
99
pub struct Cli {
1010
instance_addr: String,
11+
#[arg(short, long, default_value = "512")]
12+
mtu: u16,
1113
#[arg(short, long)]
1214
listen_mode: bool,
1315
#[arg(short, long, default_value = "0.0.0.0:8090")]
@@ -18,7 +20,7 @@ pub struct Cli {
1820

1921
impl Cli {
2022
pub async fn run(&self) -> Result<()> {
21-
let transport = UdpTransport::new(&self.bind_address, 512)?;
23+
let transport = UdpTransport::new(&self.bind_address, self.mtu)?;
2224

2325
let command = Message::ApplicationAPI(self.command.clone());
2426
let cmd_str = serde_json::to_string(&command)?;

ipfs-unixfs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ multihash.workspace = true
2020
num_enum.workspace = true
2121
prost.workspace = true
2222
tokio = { workspace = true, features = ["fs"] }
23+
tokio-util = { workspace = true, features = ["io-util"] }
2324

2425
[dev-dependencies]
2526
# criterion = { workspace = true, features = ["async_tokio"] }

local-storage/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ipfs-unixfs.workspace = true
1515
rusqlite.workspace = true
1616
thiserror.workspace = true
1717
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
18+
tokio-util = { workspace = true, features = ["io-util"] }
1819
tracing.workspace = true
1920

2021
[dev-dependencies]

local-storage/src/block.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use anyhow::{anyhow, bail, Result};
33
use bytes::Bytes;
44
use cid::Cid;
55
use ipfs_unixfs::Block;
6+
use std::fmt;
67
use std::str::FromStr;
78

8-
#[derive(Debug, PartialEq)]
9+
#[derive(PartialEq)]
910
pub struct StoredBlock {
1011
pub cid: String,
1112
pub data: Vec<u8>,
@@ -21,6 +22,20 @@ impl StoredBlock {
2122
}
2223
}
2324

25+
impl fmt::Debug for StoredBlock {
26+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27+
let cid_str = Cid::try_from(self.cid.clone())
28+
.map(|c| c.to_string())
29+
.unwrap();
30+
31+
f.debug_struct("StoredBlock")
32+
.field("cid", &cid_str)
33+
.field("data", &self.data.len())
34+
.field("links", &self.links.len())
35+
.finish()
36+
}
37+
}
38+
2439
impl TryInto<Block> for &StoredBlock {
2540
type Error = anyhow::Error;
2641

@@ -40,9 +55,6 @@ pub fn validate_dag(stored_blocks: &[StoredBlock]) -> Result<()> {
4055
if stored_blocks.is_empty() {
4156
bail!("No blocks found in dag")
4257
}
43-
for block in stored_blocks.iter() {
44-
block.validate()?;
45-
}
4658
verify_dag(stored_blocks)?;
4759
Ok(())
4860
}

local-storage/src/storage.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ use tracing::{error, info};
1515

1616
pub struct Storage {
1717
pub provider: Box<dyn StorageProvider>,
18+
block_size: u32,
1819
}
1920

20-
// TODO: Make this configurable
21-
// Changing to 1MB to optimize for larger files
22-
const BLOCK_SIZE: usize = 1024 * 100;
23-
2421
impl Storage {
25-
pub fn new(provider: Box<dyn StorageProvider>) -> Self {
26-
Storage { provider }
22+
pub fn new(provider: Box<dyn StorageProvider>, block_size: u32) -> Self {
23+
Storage {
24+
provider,
25+
block_size,
26+
}
2727
}
2828

2929
pub fn import_path(&self, path: &Path) -> Result<String> {
3030
let rt = tokio::runtime::Runtime::new()?;
3131
let blocks: Result<Vec<Block>> = rt.block_on(async {
3232
let file: File = FileBuilder::new()
3333
.path(path)
34-
.fixed_chunker(BLOCK_SIZE)
34+
.fixed_chunker(self.block_size.try_into()?)
3535
.build()
3636
.await?;
3737
let blocks: Vec<_> = file.encode().await?.try_collect().await?;
@@ -40,8 +40,6 @@ impl Storage {
4040
let blocks = blocks?;
4141
let mut root_cid: Option<String> = None;
4242

43-
let mut stored_blocks = vec![];
44-
4543
blocks.iter().for_each(|b| {
4644
let links = b
4745
.links()
@@ -61,14 +59,9 @@ impl Storage {
6159
error!("Failed to import block {e}");
6260
}
6361
if !stored.links.is_empty() {
64-
root_cid = Some(stored.cid.clone());
62+
root_cid = Some(stored.cid);
6563
}
66-
stored_blocks.push(stored);
6764
});
68-
info!("Validating imported blocks {}", blocks.len());
69-
if let Err(e) = crate::block::validate_dag(&stored_blocks) {
70-
error!("Failed to validate dag on import: {e}");
71-
}
7265
if blocks.len() == 1 {
7366
if let Some(first) = blocks.first() {
7467
root_cid = Some(first.cid().to_string());
@@ -141,7 +134,6 @@ impl Storage {
141134
window_size: u32,
142135
window_num: u32,
143136
) -> Result<Vec<StoredBlock>> {
144-
println!("offset = {} * {}", window_size, window_num);
145137
let offset = window_size * window_num;
146138

147139
self.provider
@@ -156,6 +148,8 @@ pub mod tests {
156148
use assert_fs::{fixture::FileWriteBin, fixture::PathChild, TempDir};
157149
use rand::{thread_rng, RngCore};
158150

151+
const BLOCK_SIZE: usize = 1024 * 10;
152+
159153
struct TestHarness {
160154
storage: Storage,
161155
_db_dir: TempDir,
@@ -167,7 +161,7 @@ pub mod tests {
167161
let db_path = db_dir.child("storage.db");
168162
let provider = SqliteStorageProvider::new(db_path.path().to_str().unwrap()).unwrap();
169163
provider.setup().unwrap();
170-
let storage = Storage::new(Box::new(provider));
164+
let storage = Storage::new(Box::new(provider), BLOCK_SIZE.try_into().unwrap());
171165
TestHarness {
172166
storage,
173167
_db_dir: db_dir,
@@ -264,17 +258,14 @@ pub mod tests {
264258
let cid = harness.storage.import_path(test_file.path()).unwrap();
265259

266260
let window_size: u32 = 10;
267-
let mut window_num = 0;
268-
269261
let all_dag_blocks = harness.storage.get_all_dag_blocks(&cid).unwrap();
270262

271-
for chunk in all_dag_blocks.chunks(window_size as usize).into_iter() {
263+
for (window_num, chunk) in all_dag_blocks.chunks(window_size as usize).enumerate() {
272264
let window_blocks = harness
273265
.storage
274-
.get_dag_blocks_by_window(&cid, window_size, window_num)
266+
.get_dag_blocks_by_window(&cid, window_size, window_num.try_into().unwrap())
275267
.unwrap();
276268
assert_eq!(chunk, &window_blocks);
277-
window_num += 1;
278269
}
279270
}
280271

local-storage/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(crate) fn verify_dag(blocks: &[StoredBlock]) -> Result<()> {
5151
while !queue.is_empty() {
5252
// this is a safe unwrap as the queue is not empty
5353
let node: &StoredBlock = queue.pop_front().unwrap();
54-
// ignore a visite node
54+
// ignore a visited node
5555
if visited.contains(&node.cid.as_str()) {
5656
continue;
5757
}

messages/src/api.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ pub enum ApplicationAPI {
1818
cid: String,
1919
path: String,
2020
},
21+
/// Used to indicate the failure of a dag export
22+
DagExportFailed {
23+
cid: String,
24+
path: String,
25+
error: String,
26+
},
27+
/// Used to indicate a successful dag export
28+
DagExported {
29+
cid: String,
30+
path: String,
31+
},
2132
/// Sets current connected state
2233
SetConnected {
2334
#[arg(action(clap::ArgAction::Set), required(true))]
@@ -44,6 +55,10 @@ pub enum ApplicationAPI {
4455
target_addr: String,
4556
retries: u8,
4657
},
58+
/// Indicates that a Dag has been transmitted completely successfully
59+
DagTransmissionComplete {
60+
cid: String,
61+
},
4762
/// Initiates transmission of block corresponding to the given CID
4863
TransmitBlock {
4964
cid: String,

0 commit comments

Comments
 (0)