A peer-to-peer distributed recipe-sharing system built in Rust. Nodes can store, replicate, and retrieve recipes over a lightweight TCP-based P2P protocol. The project includes full Docker support, multi-node Compose testing, and a clean multi-stage build.
- Build a minimal but functional P2P protocol in Rust
- Support recipe storage, retrieval, discovery, and propagation
- Run multiple nodes locally with Docker Compose
- Use a production-ready Dockerfile with efficient build caching
- Provide a scalable architecture suitable for future features
- TCP peer listener
- Connect to initial peers
- Broadcast new recipes
- Store recipes in a JSON file
- Respond to GET/SET requests
p2p/mod.rs→ message protocol (PING, STORE, GET, RECIPE)storage.rs→ JSON file read/writepeer.rs→ manage peer listserver.rs→ TCP listenerclient.rs→ outgoing messages
- Cache dependencies correctly
- Avoid missing
src/main.rsduringcargo fetch - Minimize final image size
- Multi-stage builder (Rust)
- runtime (Debian slim) layer containing only the binary
- Includes SSL + CA certificates
- Run 3+ nodes
- Each node has its own data folder
- Nodes know each other using environment variables
- Expose ports but run isolated networks
docker compose up --build
Each container will run a P2P node that joins the network automatically.
docker build -t p2p-recipe .
docker run -p 4001:4001 p2p-recipe
docker compose up --build
docker compose logs -f peer1
Variable Description
P2P_PORT Port to listen on
STORAGE_FILE_PATH Path to recipes.json file
PEERS Comma-separated list of peer addresses
With Compose running:
echo '{"title":"Soup"}' | nc localhost 4001
echo 'GET Soup' | nc localhost 4002
docker exec peer3 cat /data/recipes.json