A simple peer-to-peer (P2P) file transfer system using HyperDHT and Hyperswarm for decentralized networking. This project demonstrates how to send files between peers over a distributed network, suitable for local or remote (VPS) usage.
- P2P file transfer using HyperDHT and Hyperswarm
- Persistent server keypair for stable public key
- Simple protocol: send file name and file data
- Works on local network or over the internet
- Modular folder structure for client and server
.
├── hyperdht-client/ # Client code (send files)
│ ├── hyperdht-client.js
│ └── ...
├── hyperdht-server/ # Server code (receive files)
│ ├── hyperdht-server-persistent.js
│ └── ...
├── hyperswarmer_p2p/ # Additional P2P examples
├── store-reader/ # Storage (reader)
├── store-writer/ # Storage (writer)
├── sample.txt # Example file to send
└── ...
- Node.js (recommended: v16.x or v18.x LTS)
- npm (Node Package Manager)
- Clone this repository:
git clone <repo-url> cd hyperswarm_fixed
- Install dependencies:
npm install cd hyperdht-client && npm install && cd .. cd hyperdht-server && npm install && cd ..
- Run on your VPS or local machine:
cd hyperdht-server node hyperdht-server-persistent.js - The server will generate a persistent keypair and display its public key.
- Edit
hyperdht-client/hyperdht-client.js:- Set
SERVER_PUBLIC_KEYto the public key shown by the server. - Set
FILE_PATHto the file you want to send (default:./sample.txt).
- Set
cd hyperdht-client
node hyperdht-client.js- The client will connect to the server and send the file.
- HOLEPUNCH_ABORTED: Ensure both server and client use the same Node.js version and compatible
hyperdht/sodium-nativeversions. Try running both on the same machine for testing. - Cannot read properties of undefined (reading 'buffer'): This is usually a Node.js version or native module issue. Use Node.js v16 or v18, reinstall dependencies, and rebuild native modules.
- No connection: Double-check the public key, ensure the server is running and listening, and that both sides are using the same port.
- HyperDHT
- Hyperswarm
- Inspired by the Holepunch P2P ecosystem