pea2pea
pea2pea copied to clipboard
A simple, low-level, and customizable implementation of a TCP P2P node.
pea2pea
pea2pea is a simple, low-level, and customizable implementation of a TCP P2P node.
The core library only provides the most basic functionalities like starting, ending and maintaining connections; the rest is up to a few low-level, opt-in protocols:
-
Handshake
requires connections to adhere to a handshake protocol before finalizing connections -
Reading
enables the node to receive messages based on the user-supplied Decoder -
Writing
enables the node to send messages based on the user-supplied Encoder -
Disconnect
allows the node to perform specified actions whenever a peer disconnects
goals
- small, simple, non-framework codebase: the entire library is ~1k LOC and there are few dependencies
- ease of use: few objects and traits, no "turboeels" or generics/references that would force all parent objects to adapt
- correctness: builds with stable Rust, there is no
unsafe
code, there's more code intests
than in the actual library - low-level oriented: the user has full control over all connections and every byte sent or received
- good performance: over 10GB/s in favorable scenarios, small memory footprint
how to use it
- define a clonable struct containing a
Node
and any extra state you'd like to carry - implement the trivial
Pea2Pea
trait for it - make it implement any/all of the protocols
- create that struct (or as many of them as you like)
- enable the protocols you'd like them to utilize
That's it!
examples
status
- all the desired functionalities are complete
- the crate follows semver, and some API breakage is still possible before
1.0
- the project is actively developed, with all changes being recorded in the CHANGELOG
- some of the desired features that are not yet available in Rust include associated type defaults
- the project aims to always build with the current stable Rust compiler; legacy version support is not a goal, but they might also work