mirror of
https://github.com/logos-storage/easylibstorage.git
synced 2026-05-17 18:39:27 +00:00
docs: update README to reflect current implementation
Add INI config file support, e_storage_spr() usage, nat config field, uploader/downloader examples, and correct project structure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
343e1303ed
commit
7bf64b65b7
77
README.md
77
README.md
@ -1,6 +1,6 @@
|
|||||||
# libeasystorage
|
# libeasystorage
|
||||||
|
|
||||||
A simplified, higher level C wrapper around [libstorage](https://github.com/status-im/logos-storage-nim). Includes
|
A simplified, higher-level C wrapper around [libstorage](https://github.com/status-im/logos-storage-nim). Includes
|
||||||
examples showing how to implement simple filesharing apps.
|
examples showing how to implement simple filesharing apps.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
@ -16,9 +16,10 @@ cmake -B build -DLOGOS_STORAGE_NIM_ROOT=/path/to/logos-storage-nim
|
|||||||
cmake --build build
|
cmake --build build
|
||||||
```
|
```
|
||||||
|
|
||||||
This produces:
|
This produces three example executables:
|
||||||
- `libeasystorage.so` — the shared library
|
- `storageconsole` — interactive CLI for managing a storage node
|
||||||
- `storageconsole` — an example CLI application
|
- `uploader` — uploads a local file and prints the CID and SPR
|
||||||
|
- `downloader` — downloads a file given a bootstrap SPR and CID
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
@ -31,11 +32,16 @@ node_config cfg = {
|
|||||||
.disc_port = 9090,
|
.disc_port = 9090,
|
||||||
.data_dir = "./data",
|
.data_dir = "./data",
|
||||||
.log_level = "INFO",
|
.log_level = "INFO",
|
||||||
.bootstrap_node = "<SPR>"
|
.bootstrap_node = "<SPR>",
|
||||||
|
.nat = "auto"
|
||||||
};
|
};
|
||||||
STORAGE_NODE node = e_storage_new(cfg);
|
STORAGE_NODE node = e_storage_new(cfg);
|
||||||
e_storage_start(node);
|
e_storage_start(node);
|
||||||
|
|
||||||
|
// Get the node's Signed Peer Record
|
||||||
|
char *spr = e_storage_spr(node);
|
||||||
|
free(spr);
|
||||||
|
|
||||||
// Upload a file
|
// Upload a file
|
||||||
char *cid = e_storage_upload(node, "/path/to/file.txt", progress_cb);
|
char *cid = e_storage_upload(node, "/path/to/file.txt", progress_cb);
|
||||||
// Download a file
|
// Download a file
|
||||||
@ -47,9 +53,30 @@ e_storage_stop(node);
|
|||||||
e_storage_destroy(node);
|
e_storage_destroy(node);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example: storageconsole
|
Configuration can also be loaded from an INI file:
|
||||||
|
|
||||||
An interactive CLI is included in `examples/storageconsole.c`:
|
```ini
|
||||||
|
[easystorage]
|
||||||
|
api-port=8080
|
||||||
|
disc-port=9090
|
||||||
|
data-dir=./data
|
||||||
|
log-level=INFO
|
||||||
|
bootstrap-node=spr:...
|
||||||
|
nat=none
|
||||||
|
```
|
||||||
|
|
||||||
|
```c
|
||||||
|
node_config cfg = {0};
|
||||||
|
e_storage_read_config("config.ini", &cfg);
|
||||||
|
// ... use cfg ...
|
||||||
|
e_storage_free_config(&cfg);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### storageconsole
|
||||||
|
|
||||||
|
An interactive CLI included in `examples/storageconsole.c`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./build/storageconsole
|
./build/storageconsole
|
||||||
@ -57,25 +84,45 @@ An interactive CLI is included in `examples/storageconsole.c`:
|
|||||||
|
|
||||||
Commands: `help`, `start`, `stop`, `upload`, `download`, `quit`.
|
Commands: `help`, `start`, `stop`, `upload`, `download`, `quit`.
|
||||||
|
|
||||||
|
### uploader / downloader
|
||||||
|
|
||||||
|
Standalone programs that demonstrate file sharing between two nodes. On one machine, start the uploader:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./build/uploader ./myfile.txt
|
||||||
|
# prints: Run: downloader <SPR> <CID> ./output-file
|
||||||
|
```
|
||||||
|
|
||||||
|
On another (or the same machine), run the downloader with the printed values:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./build/downloader <SPR> <CID> ./output-file
|
||||||
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cmake --build build
|
cmake --build build
|
||||||
./build/test_runner
|
ctest --test-dir build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Tests use a mock libstorage implementation and do not require a running storage node.
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
easystorage/
|
├── easystorage.h # Public API
|
||||||
├── easystorage.h # Public API
|
├── easystorage.c # Implementation
|
||||||
├── easystorage.c # Implementation
|
├── CMakeLists.txt
|
||||||
├── examples/
|
├── examples/
|
||||||
│ └── storageconsole.c # CLI example
|
│ ├── storageconsole.c # Interactive CLI
|
||||||
|
│ ├── uploader.c # File upload example
|
||||||
|
│ └── downloader.c # File download example
|
||||||
├── tests/
|
├── tests/
|
||||||
│ ├── test_runner.c
|
│ ├── test_runner.c # Unit tests
|
||||||
│ └── mock_libstorage.c
|
│ └── mock_libstorage.c # Mock libstorage for testing
|
||||||
└── CMakeLists.txt
|
└── vendor/
|
||||||
|
└── inih/ # Vendored INI file parser
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user