A modern C++23 peer-to-peer mesh networking library built on UDP and io_uring, featuring coroutines for asynchronous operations.
- Modern C++20 implementation
- Asynchronous I/O using io_uring
- Coroutine support for clean async code
- UDP-based communication
- Automatic peer discovery
- Message routing with TTL
- Dead peer detection
- Example applications included
- C++23 compatible compiler
- CMake 3.15 or higher
- liburing development files
- Linux operating system (due to io_uring dependency)
sudo apt install cmake build-essential liburing-dev
sudo dnf install cmake gcc-c++ liburing-devel
# Clone the repository
git clone https://github.com/yourusername/mesh-network.git
cd mesh-network
# Create build directory
mkdir build && cd build
# Configure
cmake ..
# Build
cmake --build .
# Run tests (optional)
ctest
# Install (optional)
sudo cmake --install .
.
├── CMakeLists.txt
├── README.md
├── mesh/ # P2P Mesh library
├── include/ # Core UDP networking library
│ ├── libudp/
│ │ └── ...
│ └── CMakeLists.txt
├── examples/ # Example applications
│ ├── ...
│ └── CMakeLists.txt
├── deps/ # External dependencies like liburing etc.
│ └── install/
├── src/ # Core UDP networking library
│ └── ...
└── tests/ # Unit tests
├── ...
└── CMakeLists.txt
#include <libudp/socket.h>
// Create a UDP socket
Socket socket(8080);
// Send data
std::vector data = {1, 2, 3, 4};
co_await socket.send_async("127.0.0.1", 8081, data);
// Receive data
std::vector buffer(1024);
auto bytes_received = co_await socket.receive_async(buffer);
#include <mesh/node.hpp>
// Create a mesh node
Node node(8080, "node1");
// Set up message handler
node.on_message([](const Message& msg) {
std::cout << "Received: " << msg.payload.size() << " bytes\n";
});
// Start the node
co_await node.start();
// Connect to a peer
node.add_bootstrap_peer("127.0.0.1", 8081);
// Broadcast a message
std::vector data = {'H', 'e', 'l', 'l', 'o'};
co_await node.broadcast(data);
# Terminal 1
./examples/echo.cc
# Type messages to see them echoed back
# Terminal 1 - Start first node
./examples/p2p_chat 8001 alice
# Terminal 2 - Start second node
./examples/p2p_chat 8002 bob
> /connect 127.0.0.1 8001
# Available commands:
# /connect - Connect to a peer
# /peers - List connected peers
# /quit - Exit application
# Just type to send a message
find_package(libudp REQUIRED)
target_link_libraries(your_target
PRIVATE
libudp_network_project::udp_library
libudp_network_project::mesh
)
#include <ulibudp/socket.h>
#include <mesh/mesh.h>
The library can be configured through CMake options:
cmake .. \
-DBUILD_EXAMPLES=ON \
-DBUILD_TESTS=ON
- TODO
- Uses io_uring for efficient async I/O
- Minimal memory allocations in critical paths
- Built-in message deduplication
- Configurable TTL for message propagation
- Automatic peer cleanup for dead connections
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Linux io_uring developers
- Compilation Errors
# Make sure you have a C++20 compatible compiler
g++ --version
cmake --version
- io_uring Issues
# Check if io_uring is available
ls /usr/include/liburing*
- Port Already in Use
# Check if ports are available
sudo netstat -tulpn | grep
cmake -DCMAKE_BUILD_TYPE=Debug ..
For issues, questions, or contributions, please create an issue on the GitHub repository.