
Next-generation P2P messaging and file transfer in C++ with military-grade encryption
Cut the middleman. Own your data. Never compromise on security.
LinkNet is a high-performance C++ application that enables direct peer-to-peer communication between users for both text messaging and file sharing. Built with security in mind, all communications are end-to-end encrypted to ensure complete privacy and data integrity.
This project demonstrates advanced C++ programming concepts including:
- Network programming using Boost.Asio
- Cryptographic implementations with OpenSSL and libsodium
- Multithreaded programming for concurrent operations
- Modern C++17 features and best practices
Peer-to-peer Architecture | Direct communication without centralized servers, ensuring greater privacy and eliminating single points of failure |
Text Chat | Real-time messaging between peers with delivery confirmation and history tracking |
File Sharing | Transfer files directly between peers with progress tracking and integrity verification |
End-to-End Encryption | Secure communications using modern cryptographic algorithms (AES-256, ChaCha20-Poly1305) |
Peer Discovery | Automatic discovery of peers on local networks using multicast DNS |
NAT Traversal | Advanced techniques to establish connections through firewalls/NATs using UDP hole punching |
Dependencies
Dependency | Version | Purpose |
---|---|---|
C++ Compiler | GCC 8+, Clang 6+, MSVC 2019+ | C++17 compatible compiler |
CMake | 3.15+ | Build system |
Boost | 1.70+ | Networking (Asio), synchronization primitives |
OpenSSL | 1.1.1+ | Cryptographic operations |
Protocol Buffers | 3.0+ | Data serialization |
libsodium | 1.0.18+ | Advanced cryptographic functions |
# Clone the repository
git clone https://github.com/tejas242/LinkNet.git
cd LinkNet
# Create build directory
mkdir -p build && cd build
# Configure and build
cmake ..
make -j$(nproc) # Use multiple cores for faster build
# Run tests
ctest -V
# Run the application
./bin/linknet --port=8080
LinkNet can be easily built and run using Docker, which eliminates the need to install dependencies locally.
# Build the Docker images
docker compose build
# Run two LinkNet nodes in separate containers
docker compose up -d
# Connect to the containers
docker attach linknet-node1 # In terminal 1
docker attach linknet-node2 # In terminal 2
# Connect the nodes (from inside node1)
/connect 172.28.0.3:8081
# Exit containers with Ctrl+P, Ctrl+Q to detach (without stopping)
# To stop the containers when done
docker compose down
# Run with default port (8080)
./bin/linknet
# Run with a specific port
./bin/linknet --port=8081
# Disable automatic peer connection
./bin/linknet --no-auto-connect
Once running, LinkNet provides an intuitive command-line interface:
Command | Description | Example |
---|---|---|
/connect <ip:port> |
Connect to a specific peer | /connect 192.168.1.5:8081 |
/chat <peer_id> <message> |
Send a chat message to a specific peer | /chat abc123 Hello there! |
/send <peer_id> <file_path> |
Send a file to a peer | /send abc123 ~/Documents/report.pdf |
/peers |
List all connected peers | /peers |
/transfers |
Show ongoing file transfers | /transfers |
/help |
Display available commands | /help |
/exit |
Exit the application | /exit |
You can also just type a message directly and press Enter to broadcast it to all connected peers.
- Can't discover peers: Make sure both instances are on the same network and multicast is supported
- Connection refused: Verify the target port is correct and not blocked by firewalls
- Messages not sending: Ensure a successful connection has been established with
/peers
- Peer discovery not working: Some networks block multicast packets; use direct
/connect
instead
Directory Organization
LinkNet/
├── include/ # Public header files
│ └── linknet/
│ ├── network.h # Network interface definitions
│ ├── message.h # Message types and serialization
│ ├── chat_manager.h # Chat functionality
│ ├── file_transfer.h # File transfer operations
│ ├── crypto.h # Cryptographic operations
│ └── ...
├── src/ # Implementation files
│ ├── network/ # Network implementations (Asio, etc.)
│ ├── chat/ # Chat system implementation
│ ├── file/ # File sharing implementation
│ ├── crypto/ # Cryptographic implementations
│ ├── discovery/ # Peer discovery mechanisms
│ ├── common/ # Common utilities
│ └── ui/ # User interface code
├── test/ # Unit and integration tests
├── docs/ # Documentation
├── examples/ # Example use cases
├── third_party/ # Third-party libraries
└── docker-compose.yml # Docker configuration for testing
LinkNet follows a modular, layered architecture that separates concerns and promotes maintainability:
User Interface Layer | Console UI, commands processing, display formatting |
Application Layer | Chat Manager, File Transfer Manager, high-level operations |
Security Layer | Encryption, Message Authentication, Key Management |
Session Layer | Connection Management, Peer Sessions, Message Routing |
Transport Layer | TCP/IP Communication, Socket Management, Packet Handling |
Discovery Layer | Peer Discovery, Multicast Management, Network Scanning |
- NetworkManager: Handles all network communication, using Boost.Asio for asynchronous I/O
- ChatManager: Manages messaging between peers, including history tracking
- FileTransferManager: Handles chunked file transfers with progress tracking and verification
- PeerDiscovery: Implements automatic peer discovery on local networks
- Message: Base class for all message types with serialization/deserialization
Network Communication
LinkNet uses Boost.Asio for asynchronous network I/O, providing:
- Non-blocking socket operations
- Completion handlers for event-driven architecture
- Support for both IPv4 and IPv6
- Efficient thread management
Example of asynchronous accept operation:
void StartAccept() {
_acceptor.async_accept(
[this](const boost::system::error_code& ec, tcp::socket socket) {
if (!ec) {
// Handle new connection
auto session = std::make_shared<PeerSession>(std::move(socket), ...);
session->Start();
}
// Continue accepting connections
StartAccept();
});
}
Message Protocol
Messages use a simple binary protocol:
- Message Type (1 byte)
- Sender ID (32 bytes)
- Message ID (16 bytes)
- Timestamp (8 bytes)
- Payload Length (4 bytes)
- Payload (variable length)
All multi-byte integers are transmitted in network byte order.
Cryptographic Security
LinkNet employs several cryptographic mechanisms:
- AES-256-GCM for symmetric encryption
- X25519 for key exchange
- Ed25519 for digital signatures
- BLAKE2b for hashing
- ChaCha20-Poly1305 as an alternative cipher
Keys are rotated periodically to maintain forward secrecy.
LinkNet includes comprehensive testing:
# Run all tests
cd build && ctest
# Run specific test category
cd build && ctest -R crypto_tests
# Run with verbose output
cd build && ctest -V
Contributions are welcome and appreciated! Here's how you can contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Please make sure your code follows the Google C++ Style Guide.
This project is licensed under the MIT License - see the LICENSE file for details.