Example using iroh Sender and Receiver
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Documentation
- Clarity
- Needs clarification
- Activity status
- Active
- Tech stack
- rust
- Domain
- cryptography, documentation
Research direction
Start with the bao-tree documentation and the iroh-blobs usage referenced in the issue, then compare those materials with the shown send_file and receive_file functions. Done means the project has a clear, working example or documented guidance for using Sender and Receiver with bao-tree verification.
Written by the indexing model from the issue text.
Description
Hey everyone,
I am looking for using bao-tree in a project that I am developing using Iroh.
The project at the moment is quite simple: just sending files from one node to another. At the moment, I have a piece of code working, mainly using irpc, but I am missing the hashing part. I was checking iroh-blobs, and I saw that they are using this library, but for me it's not very clear how to implement it.
I was playing a bit with blake3 for doing the hashing, but after reading some of your docs, I think I am doing it wrong. I mainly have two functions:
pub async fn send_file(file: &mut File, tx: Sender<FileChunk>) -> Result<()> {
let mut file_reader = BufReader::new(file);
let mut buf = vec![0; FILE_CHUNK_SIZE];
loop {
tokio::select! {
result = file_reader.read(&mut buf) => {
match result {
Ok(bytes_read_len) => {
if bytes_read_len == 0 {
break;
}
let hash = blake3::hash(bytes_read);
tx.send(FileChunk {
data: bytes_read.to_vec(),
hash: hash.to_string()
}).await?;
},
Err(err) => {
bail!(err);
}
}
},
_ = tx.closed() => {
break;
}
}
}
Ok(())
}
send_file just sents a file over the network using a Sender object. As you can see, I am using blake3:hash to create a hash of every chunk, and sending it to the other node, but as far as I understood there is a better way to do it using bao_tree.
Same think with the receive_file function:
pub async fn receive_file(file: &mut File, mut rx: Receiver<FileChunk>) -> Result<()> {
let mut file_writer = BufWriter::new(file);
let mut hasher = Hasher::new();
while let Ok(Some(chunk)) = rx.recv().await {
let hash = blake3::hash(&chunk.data);
if hash.to_string() != chunk.hash {
let err_message = "UploadFile Error: Invalid hash";
bail!(err_message);
}
file_writer
.write(chunk.data.as_slice())
.await
.context("UploadFile Error: Failed to write data into file")?;
hasher.update(&chunk.data);
}
file_writer
.flush()
.await
.context("UploadFile Error: Failed to flush {:?} file")?;
Ok(())
}
Here I am just generating a hash with the chunk of data sent by the client, and checking if it's the same. I suppose that here it also would be easier to use bao_tree.
Do you have any example or idea how it could be implement it? I would appreciate any guidance here.
Thanks a lot in advance.
- Dominant language
- Rust
- Stars
- 40
- Forks
- 12
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from n0-computer/bao-tree
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
n0-computer/bao-tree#119 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
n0-computer/bao-tree#59 · 6 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
n0-computer/bao-tree#57 · 1 comment ·
-
rename tokio-fsm to just fsmPossibly taken @mempirate claimed this 564 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 55/100
n0-computer/bao-tree#56 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
n0-computer/bao-tree#11 · 1 reaction ·
All issues in n0-computer/bao-tree
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Wait for the IDS correction dialog to settle in the stale-audit testPossibly taken @louistrue claimed this today. Openready
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dutchman-cad/dutchman#874 ·
Maintainers usually reply within 1 day
-
bug good first issue ready
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MartinPTielemans/ilo#3840 ·
Maintainers usually reply within 1 day
-
bug file-compat priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
storytold/wordcraft#7248 · 1 comment ·
Maintainers usually reply within 4 days