mirror of
https://github.com/logos-storage/easylibstorage.git
synced 2026-05-18 02:49:35 +00:00
Merge 2855c573630a71cea2b2de10123cadb0541c4cf3 into 41f5bb42d7171bc20bf32d0e96ea766e022a5fcd
This commit is contained in:
commit
f749ccbb1c
71
README.md
71
README.md
@ -86,19 +86,86 @@ Commands: `help`, `start`, `stop`, `upload`, `download`, `quit`.
|
|||||||
|
|
||||||
### uploader / downloader
|
### uploader / downloader
|
||||||
|
|
||||||
Standalone programs that demonstrate file sharing between two nodes. On one machine, start the uploader:
|
Standalone programs that demonstrate file sharing between two nodes.
|
||||||
|
|
||||||
|
Optionally generate a file to upload. For example, using `dd` on nix-based systems:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# generate a 500MB file with random contents
|
||||||
|
dd if=/dev/urandom of=myfile.txt bs=1048576 count=500
|
||||||
|
```
|
||||||
|
|
||||||
|
In one terminal, start the uploader, passing in the path to a file to upload:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./build/uploader ./myfile.txt
|
./build/uploader ./myfile.txt
|
||||||
# prints: Run: downloader <SPR> <CID> ./output-file
|
# prints: Run: downloader <SPR> <CID> ./output-file
|
||||||
```
|
```
|
||||||
|
|
||||||
On another (or the same machine), run the downloader with the printed values:
|
In another terminal, run the downloader with the printed values:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./build/downloader <SPR> <CID> ./output-file
|
./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
|
## Testing
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@ -180,6 +180,10 @@ STORAGE_NODE e_storage_new(node_config config) {
|
|||||||
pos += snprintf(json + pos, sizeof(json) - pos, ",\"bootstrap-node\":[\"%s\"]", config.bootstrap_node);
|
pos += snprintf(json + pos, sizeof(json) - pos, ",\"bootstrap-node\":[\"%s\"]", config.bootstrap_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.listen_addr) {
|
||||||
|
pos += snprintf(json + pos, sizeof(json) - pos, ",\"listen-addrs\":[\"%s\"]", config.listen_addr);
|
||||||
|
}
|
||||||
|
|
||||||
if (config.nat) {
|
if (config.nat) {
|
||||||
pos += snprintf(json + pos, sizeof(json) - pos, ",\"nat\":\"%s\"", config.nat);
|
pos += snprintf(json + pos, sizeof(json) - pos, ",\"nat\":\"%s\"", config.nat);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ typedef struct {
|
|||||||
char *data_dir;
|
char *data_dir;
|
||||||
char *log_level;
|
char *log_level;
|
||||||
char *bootstrap_node;
|
char *bootstrap_node;
|
||||||
|
char *listen_addr;
|
||||||
char *nat;
|
char *nat;
|
||||||
} node_config;
|
} node_config;
|
||||||
|
|
||||||
|
|||||||
@ -28,9 +28,9 @@ int main(int argc, char *argv[]) {
|
|||||||
.api_port = 8081,
|
.api_port = 8081,
|
||||||
.disc_port = 9091,
|
.disc_port = 9091,
|
||||||
.data_dir = "./downloader-data",
|
.data_dir = "./downloader-data",
|
||||||
.log_level = "INFO",
|
.log_level = "TRACE",
|
||||||
.bootstrap_node = spr,
|
.bootstrap_node = "spr:CiUIAhIhApIj9p6zJDRbw2NoCo-tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEGgsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
|
||||||
.nat = "none",
|
.listen_addr = "/ip4/0.0.0.0/tcp/65032",
|
||||||
};
|
};
|
||||||
|
|
||||||
STORAGE_NODE node = e_storage_new(cfg);
|
STORAGE_NODE node = e_storage_new(cfg);
|
||||||
|
|||||||
@ -24,9 +24,9 @@ int main(int argc, char *argv[]) {
|
|||||||
.api_port = 8080,
|
.api_port = 8080,
|
||||||
.disc_port = 9090,
|
.disc_port = 9090,
|
||||||
.data_dir = "./uploader-data",
|
.data_dir = "./uploader-data",
|
||||||
.log_level = "INFO",
|
.log_level = "TRACE",
|
||||||
.bootstrap_node = NULL,
|
.bootstrap_node = "spr:CiUIAhIhApIj9p6zJDRbw2NoCo-tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEGgsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
|
||||||
.nat = "none",
|
.listen_addr = "/ip4/0.0.0.0/tcp/65032",
|
||||||
};
|
};
|
||||||
|
|
||||||
char *filepath = argv[1];
|
char *filepath = argv[1];
|
||||||
@ -40,8 +40,8 @@ int main(int argc, char *argv[]) {
|
|||||||
char *spr = e_storage_spr(node);
|
char *spr = e_storage_spr(node);
|
||||||
if (spr == NULL) panic("Failed to obtain node's Signed Peer Record (SPR)");
|
if (spr == NULL) panic("Failed to obtain node's Signed Peer Record (SPR)");
|
||||||
|
|
||||||
printf("Run: downloader %s %s ./output-file\n", spr, cid);
|
printf("Run: ./build/downloader %s %s ./output-file\n", spr, cid);
|
||||||
printf("\nPress Enter to exit\n");
|
printf("\nKeep running while downloading.\n\nPress Enter to exit when finished.\n");
|
||||||
getchar();
|
getchar();
|
||||||
|
|
||||||
printf("Deleting file (this could take a while)...");
|
printf("Deleting file (this could take a while)...");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user