Add remote and local peer connection instructions

This commit is contained in:
E M 2026-02-23 21:24:51 +11:00
parent 89ddbe3866
commit 2855c57363
No known key found for this signature in database

View File

@ -95,7 +95,7 @@ Optionally generate a file to upload. For example, using `dd` on nix-based syste
dd if=/dev/urandom of=myfile.txt bs=1048576 count=500
```
On one machine, start the uploader, passing in the path to a file to upload:
In one terminal, start the uploader, passing in the path to a file to upload:
```bash
./build/uploader ./myfile.txt
@ -108,6 +108,64 @@ In another terminal, run the downloader with the printed values:
./build/downloader <SPR> <CID> ./output-file
```
#### Connecting to remote peers
To run the uploader/downloader example, but connect to peers remotely, the config will need to be updated before it will work.
##### UPnP / PMP
The easiest way to connect to remote peers is to enable UPnP or PMP in your router. Once this is enabled, update the config to:
```c
// uploader.c
node_config cfg = {
.api_port = 8080,
.disc_port = 9090,
.data_dir = "./uploader-data",
.log_level = "TRACE",
.bootstrap_node = "spr:CiUIAhIhApIj9p6zJDRbw2NoCo-tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEGgsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
.nat = "upnp" // or "pmp" or "any",
};
// downlaoder.c
node_config cfg = {
.api_port = 8081,
.disc_port = 9091,
.data_dir = "./downloader-data",
.log_level = "TRACE",
.bootstrap_node = "spr:CiUIAhIhApIj9p6zJDRbw2NoCo-tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEGgsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
.nat = "upnp" // or "pmp" or "any",
};
```
By specifying a common bootstrap node, the uploader and downloader will be able to share DHT entries. Specifically, the uploader will announce itself as a provider for the CID in the DHT to its closes neighbours (the bootstrap node), and the downloader will be able to traverse its closest peers when finding a provider for the CID.
#### Connecting to peers on the same network or machine
To connect to peers locally, the same config updates need to be made, except now, `nat` should be set to `none`:
```c
// uploader.c
node_config cfg = {
.api_port = 8080,
.disc_port = 9090,
.data_dir = "./uploader-data",
.log_level = "TRACE",
.bootstrap_node = "spr:CiUIAhIhApIj9p6zJDRbw2NoCo-tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEGgsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
.nat = "none"
};
// downlaoder.c
node_config cfg = {
.api_port = 8081,
.disc_port = 9091,
.data_dir = "./downloader-data",
.log_level = "TRACE",
.bootstrap_node = "spr:CiUIAhIhApIj9p6zJDRbw2NoCo-tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEGgsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
.nat = "none"
};
```
## Testing
```bash