This is a command-line tool for transferring files between two machines on the same network, without a central server. The tool can function as both sender and receiver.
The project is organized into 4 modules:
protocol.rs: Communication protocol definition, where all protocol commands are declared and defined for "peer-to-peer" communication.listener.rs: File reception management, it listens for incoming connections and handle them.sender.rs: File sending management, it tries to connect to a listener in order to send a file.main.rs: Entry point & command-line interface declaration
The protocol uses four commands:
- HELLO filename size: The sender proposes a file to the receiver
filename: name of the file to transfersize: file size in bytes
- ACK: The receiver accepts the proposed file
- NACK: The receiver refuses the proposed file
- SEND size: The sender starts sending the file
size: must match the size announced in HELLO
All commands end with a newline character (\n) which serves as a delimiter for the program.
- The receiver listens on a specified port (or by default 9000)
- For each incoming connection, a new thread is created
- The receiver waits for a HELLO command indicating a filename and its size
- If the file doesn't already exist, it sends ACK, otherwise NACK
- It waits for the SEND command with the corresponding size
- It receives the file data and writes it to the output directory
- The sender connects to the receiver's IP address and port
- It sends a HELLO command with the file name and size
- It waits for the receiver's response (ACK or NACK)
- If ACK is received, it sends the SEND command followed by the file data
- If NACK is received, the transfer is cancelled
Command examples use
peerile, but you can usecargo run --instead. (the--is important!)
peerile listen --port 9000 --output ./shared--port | -p: Port on which the program will listen for incoming file transfers--output | -o: destination for received files
peerile send --file document.pdf --to 192.168.1.100 --port 9000--file | -f: Path to the file to send--to | -t: Receiver's IP address--port | -p: Port on which the receiver is listening