7 releases
0.1.6 | Mar 21, 2022 |
---|---|
0.1.5 | Mar 20, 2022 |
#28 in #file-sharing
Used in mork
30KB
654 lines
Dovepipe
Rust crate for sending files p2p over udp
Getting started
You can look in the /examples folder for examples
You can also look in the official documentation
Usage
This is used in my other project
License
This software is dual-licenced under MIT and Apache-2.0.
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
lib.rs
:
Usage
\
Sender example
let port = 3456;
println!("my ip: 127.0.0.1:{}", port);
// Send the file with the send_file funciton
send_file(
Source::Port(port),
"./examples/file_to_send.txt",
"127.0.0.1:7890",
)
.await
.expect("error when sending file");
\
Reciever example
let port = 7890;
println!("my ip: 127.0.0.1:{}", port);
recv_file(
Source::Port(port),
&mut File::create("output_from_recv.txt").expect("could not create output file"),
"127.0.0.1:3456",
ProgressTracking::Memory,
)
.await
.expect("error when sending file");
Sending files
Messages
Messages are 508 bytes in size. This is because that is the biggest message you can send over udp without getting dropped.
The first 8 bytes or 64 bits in the message are used for telling what message this is. The counting starts at 0.
The rest is content of the file
Hole punch
A hole punch is a way for clients to communicate without requireing a port-forward.
Here is a wikipedia article about it.
But it works like this
- Client A sends a udp message to client B:s ip-address and port.
- Client B does the same as client A but with client A:s ip-address and port.
- Now they are able to send messages over udp from where they have hole-punched to.
Progress tracking
When recieving the reciever remembers what messages have been sent. It also knows how many that should be sent. With that info it can tell the sender what messages are unsent.
The progress tracking can be stored in memory and on file if the messages are to many.
You can calculate the memory required for recieving a file, file size / 500 / 8 = size of progress tracker.
Example: 64gb = 64 000 000 000 / 500 / 8 = 16 000 000 = 16mb
The progress tracker for 64gb is 16mb.
Sending
It sends the file by sending many messages. When it's done it will send a message telling the reciever that it's done. If any messages got dropped the reciever will send a list of those. If the file was recieved correctly the reciever will send a message.
Dependencies
~2.6–8.5MB
~76K SLoC