chore: rename codex to logos storage (#1359)

This commit is contained in:
Arnaud 2025-12-18 18:23:09 +01:00 committed by GitHub
parent 49e801803f
commit 60861d6af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
130 changed files with 835 additions and 814 deletions

View File

@ -218,7 +218,7 @@ runs:
run: | run: |
git config --global core.symlinks false git config --global core.symlinks false
- name: Build Nim and Codex dependencies - name: Build Nim and Logos Storage dependencies
shell: ${{ inputs.shell }} {0} shell: ${{ inputs.shell }} {0}
run: | run: |
which gcc which gcc

View File

@ -70,7 +70,7 @@ runners busy for longer on a workflow that you know is going to fail anyway.
Consequent runs will therefore take longer to start. Fail fast is most likely Consequent runs will therefore take longer to start. Fail fast is most likely
better for overall development speed. better for overall development speed.
[usage]: https://github.com/codex-storage/nim-codex/actions/runs/3462031231/usage [usage]: https://github.com/logos-storage/logos-storage-nim/actions/runs/3462031231/usage
[composite]: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action [composite]: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
[reusable]: https://docs.github.com/en/actions/using-workflows/reusing-workflows [reusable]: https://docs.github.com/en/actions/using-workflows/reusing-workflows
[cache]: https://github.com/actions/cache/blob/main/workarounds.md#update-a-cache [cache]: https://github.com/actions/cache/blob/main/workarounds.md#update-a-cache

View File

@ -54,9 +54,9 @@ jobs:
with: with:
node-version: 22 node-version: 22
- name: Start Ethereum node with Codex contracts - name: Start Ethereum node with Logos Storage contracts
if: matrix.tests == 'contract' || matrix.tests == 'integration' || matrix.tests == 'tools' || matrix.tests == 'all' if: matrix.tests == 'contract' || matrix.tests == 'integration' || matrix.tests == 'tools' || matrix.tests == 'all'
working-directory: vendor/codex-contracts-eth working-directory: vendor/logos-storage-contracts-eth
env: env:
MSYS2_PATH_TYPE: inherit MSYS2_PATH_TYPE: inherit
run: | run: |

View File

@ -70,7 +70,7 @@ on:
type: string type: string
outputs: outputs:
codex_image: codex_image:
description: Codex Docker image tag description: Logos Storage Docker image tag
value: ${{ jobs.publish.outputs.codex_image }} value: ${{ jobs.publish.outputs.codex_image }}
@ -87,7 +87,7 @@ env:
TAG_SUFFIX: ${{ inputs.tag_suffix }} TAG_SUFFIX: ${{ inputs.tag_suffix }}
CONTRACT_IMAGE: ${{ inputs.contract_image }} CONTRACT_IMAGE: ${{ inputs.contract_image }}
# Tests # Tests
TESTS_SOURCE: codex-storage/cs-codex-dist-tests TESTS_SOURCE: logos-storage/logos-storage-nim-cs-dist-tests
TESTS_BRANCH: master TESTS_BRANCH: master
CONTINUOUS_TESTS_LIST: ${{ inputs.continuous_tests_list }} CONTINUOUS_TESTS_LIST: ${{ inputs.continuous_tests_list }}
CONTINUOUS_TESTS_DURATION: ${{ inputs.continuous_tests_duration }} CONTINUOUS_TESTS_DURATION: ${{ inputs.continuous_tests_duration }}
@ -316,7 +316,7 @@ jobs:
max-parallel: 1 max-parallel: 1
matrix: matrix:
tests: ${{ fromJSON(needs.compute-continuous-tests-inputs.outputs.continuous_tests_list) }} tests: ${{ fromJSON(needs.compute-continuous-tests-inputs.outputs.continuous_tests_list) }}
uses: codex-storage/cs-codex-dist-tests/.github/workflows/run-continuous-tests.yaml@master uses: logos-storage/logos-storage-nim-cs-dist-tests/.github/workflows/run-continuous-tests.yaml@master
with: with:
source: ${{ needs.compute-tests-inputs.outputs.source }} source: ${{ needs.compute-tests-inputs.outputs.source }}
branch: ${{ needs.compute-tests-inputs.outputs.branch }} branch: ${{ needs.compute-tests-inputs.outputs.branch }}
@ -333,7 +333,7 @@ jobs:
name: Run Release Tests name: Run Release Tests
needs: [compute-tests-inputs] needs: [compute-tests-inputs]
if: ${{ inputs.run_release_tests == 'true' }} if: ${{ inputs.run_release_tests == 'true' }}
uses: codex-storage/cs-codex-dist-tests/.github/workflows/run-release-tests.yaml@master uses: logos-storage/logos-storage-nim-cs-dist-tests/.github/workflows/run-release-tests.yaml@master
with: with:
source: ${{ needs.compute-tests-inputs.outputs.source }} source: ${{ needs.compute-tests-inputs.outputs.source }}
branch: ${{ needs.compute-tests-inputs.outputs.branch }} branch: ${{ needs.compute-tests-inputs.outputs.branch }}

View File

@ -31,7 +31,7 @@ jobs:
- name: Get submodule short hash - name: Get submodule short hash
id: get-hash id: get-hash
run: | run: |
hash=$(git rev-parse --short HEAD:vendor/codex-contracts-eth) hash=$(git rev-parse --short HEAD:vendor/logos-storage-contracts-eth)
echo "hash=$hash" >> $GITHUB_OUTPUT echo "hash=$hash" >> $GITHUB_OUTPUT
build-and-push: build-and-push:
name: Build and Push name: Build and Push

View File

@ -52,7 +52,7 @@ jobs:
node-version: 18 node-version: 18
- name: Build OpenAPI - name: Build OpenAPI
run: npx @redocly/cli build-docs openapi.yaml --output openapi/index.html --title "Codex API" run: npx @redocly/cli build-docs openapi.yaml --output openapi/index.html --title "Logos Storage API"
- name: Build Postman Collection - name: Build Postman Collection
run: npx -y openapi-to-postmanv2 -s openapi.yaml -o openapi/postman.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false run: npx -y openapi-to-postmanv2 -s openapi.yaml -o openapi/postman.json -p -O folderStrategy=Tags,includeAuthInfoInExample=false

View File

@ -12,7 +12,7 @@ env:
cache_nonce: 0 # Allows for easily busting actions/cache caches cache_nonce: 0 # Allows for easily busting actions/cache caches
nim_version: pinned nim_version: pinned
rust_version: 1.79.0 rust_version: 1.79.0
codex_binary_base: codex storage_binary_base: storage
cirdl_binary_base: cirdl cirdl_binary_base: cirdl
build_dir: build build_dir: build
nim_flags: '' nim_flags: ''
@ -73,18 +73,18 @@ jobs:
windows*) os_name="windows" ;; windows*) os_name="windows" ;;
esac esac
github_ref_name="${GITHUB_REF_NAME/\//-}" github_ref_name="${GITHUB_REF_NAME/\//-}"
codex_binary="${{ env.codex_binary_base }}-${github_ref_name}-${os_name}-${{ matrix.cpu }}" storage_binary="${{ env.storage_binary_base }}-${github_ref_name}-${os_name}-${{ matrix.cpu }}"
cirdl_binary="${{ env.cirdl_binary_base }}-${github_ref_name}-${os_name}-${{ matrix.cpu }}" cirdl_binary="${{ env.cirdl_binary_base }}-${github_ref_name}-${os_name}-${{ matrix.cpu }}"
if [[ ${os_name} == "windows" ]]; then if [[ ${os_name} == "windows" ]]; then
codex_binary="${codex_binary}.exe" storage_binary="${storage_binary}.exe"
cirdl_binary="${cirdl_binary}.exe" cirdl_binary="${cirdl_binary}.exe"
fi fi
echo "codex_binary=${codex_binary}" >>$GITHUB_ENV echo "storage_binary=${storage_binary}" >>$GITHUB_ENV
echo "cirdl_binary=${cirdl_binary}" >>$GITHUB_ENV echo "cirdl_binary=${cirdl_binary}" >>$GITHUB_ENV
- name: Release - Build - name: Release - Build
run: | run: |
make NIMFLAGS="--out:${{ env.build_dir }}/${{ env.codex_binary }} ${{ env.nim_flags }}" make NIMFLAGS="--out:${{ env.build_dir }}/${{ env.storage_binary }} ${{ env.nim_flags }}"
make cirdl NIMFLAGS="--out:${{ env.build_dir }}/${{ env.cirdl_binary }} ${{ env.nim_flags }}" make cirdl NIMFLAGS="--out:${{ env.build_dir }}/${{ env.cirdl_binary }} ${{ env.nim_flags }}"
- name: Release - Libraries - name: Release - Libraries
@ -95,11 +95,11 @@ jobs:
done done
fi fi
- name: Release - Upload codex build artifacts - name: Release - Upload Logos Storage build artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: release-${{ env.codex_binary }} name: release-${{ env.storage_binary }}
path: ${{ env.build_dir }}/${{ env.codex_binary_base }}* path: ${{ env.build_dir }}/${{ env.storage_binary_base }}*
retention-days: 30 retention-days: 30
- name: Release - Upload cirdl build artifacts - name: Release - Upload cirdl build artifacts
@ -139,7 +139,7 @@ jobs:
} }
# Compress and prepare # Compress and prepare
for file in ${{ env.codex_binary_base }}* ${{ env.cirdl_binary_base }}*; do for file in ${{ env.storage_binary_base }}* ${{ env.cirdl_binary_base }}*; do
if [[ "${file}" == *".exe"* ]]; then if [[ "${file}" == *".exe"* ]]; then
# Windows - binary only # Windows - binary only
@ -212,6 +212,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
with: with:
token: ${{ secrets.DISPATCH_PAT }} token: ${{ secrets.DISPATCH_PAT }}
repository: codex-storage/py-codex-api-client repository: logos-storage/logos-storage-py-api-client
event-type: generate event-type: generate
client-payload: '{"openapi_url": "https://raw.githubusercontent.com/codex-storage/nim-codex/${{ github.ref }}/openapi.yaml"}' client-payload: '{"openapi_url": "https://raw.githubusercontent.com/logos-storage/logos-storage-nim/${{ github.ref }}/openapi.yaml"}'

32
.gitmodules vendored
View File

@ -159,9 +159,9 @@
[submodule "vendor/nim-leopard"] [submodule "vendor/nim-leopard"]
path = vendor/nim-leopard path = vendor/nim-leopard
url = https://github.com/status-im/nim-leopard.git url = https://github.com/status-im/nim-leopard.git
[submodule "vendor/nim-codex-dht"] [submodule "vendor/logos-storage-nim-dht"]
path = vendor/nim-codex-dht path = vendor/logos-storage-nim-dht
url = https://github.com/codex-storage/nim-codex-dht.git url = https://github.com/logos-storage/logos-storage-nim-dht.git
ignore = untracked ignore = untracked
branch = master branch = master
[submodule "vendor/nim-datastore"] [submodule "vendor/nim-datastore"]
@ -173,9 +173,11 @@
[submodule "vendor/nim-eth"] [submodule "vendor/nim-eth"]
path = vendor/nim-eth path = vendor/nim-eth
url = https://github.com/status-im/nim-eth url = https://github.com/status-im/nim-eth
[submodule "vendor/codex-contracts-eth"] [submodule "vendor/logos-storage-contracts-eth"]
path = vendor/codex-contracts-eth path = vendor/logos-storage-contracts-eth
url = https://github.com/status-im/codex-contracts-eth url = https://github.com/logos-storage/logos-storage-contracts-eth.git
ignore = untracked
branch = master
[submodule "vendor/nim-protobuf-serialization"] [submodule "vendor/nim-protobuf-serialization"]
path = vendor/nim-protobuf-serialization path = vendor/nim-protobuf-serialization
url = https://github.com/status-im/nim-protobuf-serialization url = https://github.com/status-im/nim-protobuf-serialization
@ -190,26 +192,28 @@
url = https://github.com/zevv/npeg url = https://github.com/zevv/npeg
[submodule "vendor/nim-poseidon2"] [submodule "vendor/nim-poseidon2"]
path = vendor/nim-poseidon2 path = vendor/nim-poseidon2
url = https://github.com/codex-storage/nim-poseidon2.git url = https://github.com/logos-storage/nim-poseidon2.git
ignore = untracked
branch = master
[submodule "vendor/constantine"] [submodule "vendor/constantine"]
path = vendor/constantine path = vendor/constantine
url = https://github.com/mratsim/constantine.git url = https://github.com/mratsim/constantine.git
[submodule "vendor/nim-circom-compat"] [submodule "vendor/nim-circom-compat"]
path = vendor/nim-circom-compat path = vendor/nim-circom-compat
url = https://github.com/codex-storage/nim-circom-compat.git url = https://github.com/logos-storage/nim-circom-compat.git
ignore = untracked ignore = untracked
branch = master branch = master
[submodule "vendor/codex-storage-proofs-circuits"] [submodule "vendor/logos-storage-proofs-circuits"]
path = vendor/codex-storage-proofs-circuits path = vendor/logos-storage-proofs-circuits
url = https://github.com/codex-storage/codex-storage-proofs-circuits.git url = https://github.com/logos-storage/logos-storage-proofs-circuits.git
ignore = untracked ignore = untracked
branch = master branch = master
[submodule "vendor/nim-serde"] [submodule "vendor/nim-serde"]
path = vendor/nim-serde path = vendor/nim-serde
url = https://github.com/codex-storage/nim-serde.git url = https://github.com/logos-storage/nim-serde.git
[submodule "vendor/nim-leveldbstatic"] [submodule "vendor/nim-leveldbstatic"]
path = vendor/nim-leveldbstatic path = vendor/nim-leveldbstatic
url = https://github.com/codex-storage/nim-leveldb.git url = https://github.com/logos-storage/nim-leveldb.git
[submodule "vendor/nim-zippy"] [submodule "vendor/nim-zippy"]
path = vendor/nim-zippy path = vendor/nim-zippy
url = https://github.com/status-im/nim-zippy.git url = https://github.com/status-im/nim-zippy.git
@ -225,4 +229,4 @@
path = vendor/nim-ngtcp2 path = vendor/nim-ngtcp2
url = https://github.com/vacp2p/nim-ngtcp2.git url = https://github.com/vacp2p/nim-ngtcp2.git
ignore = untracked ignore = untracked
branch = main branch = main

2
Jenkinsfile vendored
View File

@ -25,7 +25,7 @@ pipeline {
stage('Check') { stage('Check') {
steps { steps {
script { script {
sh './result/bin/codex --version' sh './result/bin/storage --version'
} }
} }
} }

View File

@ -93,10 +93,10 @@ else # "variables.mk" was included. Business as usual until the end of this file
# default target, because it's the first one that doesn't start with '.' # default target, because it's the first one that doesn't start with '.'
# Builds the codex binary # Builds the Logos Storage binary
all: | build deps all: | build deps
echo -e $(BUILD_MSG) "build/$@" && \ echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim codex $(NIM_PARAMS) build.nims $(ENV_SCRIPT) nim storage $(NIM_PARAMS) build.nims
# Build tools/cirdl # Build tools/cirdl
cirdl: | deps cirdl: | deps
@ -246,29 +246,29 @@ clean: | clean-nph
################ ################
## C Bindings ## ## C Bindings ##
################ ################
.PHONY: libcodex .PHONY: libstorage
STATIC ?= 0 STATIC ?= 0
ifneq ($(strip $(CODEX_LIB_PARAMS)),) ifneq ($(strip $(STORAGE_LIB_PARAMS)),)
NIM_PARAMS := $(NIM_PARAMS) $(CODEX_LIB_PARAMS) NIM_PARAMS := $(NIM_PARAMS) $(STORAGE_LIB_PARAMS)
endif endif
libcodex: libstorage:
$(MAKE) deps $(MAKE) deps
rm -f build/libcodex* rm -f build/libstorage*
ifeq ($(STATIC), 1) ifeq ($(STATIC), 1)
echo -e $(BUILD_MSG) "build/$@.a" && \ echo -e $(BUILD_MSG) "build/$@.a" && \
$(ENV_SCRIPT) nim libcodexStatic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release\"" codex.nims $(ENV_SCRIPT) nim libstorageStatic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release\"" codex.nims
else ifeq ($(detected_OS),Windows) else ifeq ($(detected_OS),Windows)
echo -e $(BUILD_MSG) "build/$@.dll" && \ echo -e $(BUILD_MSG) "build/$@.dll" && \
$(ENV_SCRIPT) nim libcodexDynamic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-G \\\"MSYS Makefiles\\\" -DCMAKE_BUILD_TYPE=Release\"" codex.nims $(ENV_SCRIPT) nim libstorageDynamic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-G \\\"MSYS Makefiles\\\" -DCMAKE_BUILD_TYPE=Release\"" codex.nims
else ifeq ($(detected_OS),macOS) else ifeq ($(detected_OS),macOS)
echo -e $(BUILD_MSG) "build/$@.dylib" && \ echo -e $(BUILD_MSG) "build/$@.dylib" && \
$(ENV_SCRIPT) nim libcodexDynamic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release\"" codex.nims $(ENV_SCRIPT) nim libstorageDynamic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release\"" codex.nims
else else
echo -e $(BUILD_MSG) "build/$@.so" && \ echo -e $(BUILD_MSG) "build/$@.so" && \
$(ENV_SCRIPT) nim libcodexDynamic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release\"" codex.nims $(ENV_SCRIPT) nim libstorageDynamic $(NIM_PARAMS) -d:LeopardCmakeFlags="\"-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release\"" codex.nims
endif endif
endif # "variables.mk" was not included endif # "variables.mk" was not included

View File

@ -1,22 +1,22 @@
# Codex Decentralized Durability Engine # Logos Storage Decentralized Engine
> The Codex project aims to create a decentralized durability engine that allows persisting data in p2p networks. In other words, it allows storing files and data with predictable durability guarantees for later retrieval. > The Logos Storage project aims to create a decentralized engine that allows persisting data in p2p networks.
> WARNING: This project is under active development and is considered pre-alpha. > WARNING: This project is under active development and is considered pre-alpha.
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](#stability) [![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](#stability)
[![CI](https://github.com/codex-storage/nim-codex/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/codex-storage/nim-codex/actions/workflows/ci.yml?query=branch%3Amaster) [![CI](https://github.com/logos-storage/logos-storage-nim/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/logos-storage/logos-storage-nim/actions/workflows/ci.yml?query=branch%3Amaster)
[![Docker](https://github.com/codex-storage/nim-codex/actions/workflows/docker.yml/badge.svg?branch=master)](https://github.com/codex-storage/nim-codex/actions/workflows/docker.yml?query=branch%3Amaster) [![Docker](https://github.com/logos-storage/logos-storage-nim/actions/workflows/docker.yml/badge.svg?branch=master)](https://github.com/logos-storage/logos-storage-nim/actions/workflows/docker.yml?query=branch%3Amaster)
[![Codecov](https://codecov.io/gh/codex-storage/nim-codex/branch/master/graph/badge.svg?token=XFmCyPSNzW)](https://codecov.io/gh/codex-storage/nim-codex) [![Codecov](https://codecov.io/gh/logos-storage/logos-storage-nim/branch/master/graph/badge.svg?token=XFmCyPSNzW)](https://codecov.io/gh/logos-storage/logos-storage-nim)
[![Discord](https://img.shields.io/discord/895609329053474826)](https://discord.gg/CaJTh24ddQ) [![Discord](https://img.shields.io/discord/895609329053474826)](https://discord.gg/CaJTh24ddQ)
![Docker Pulls](https://img.shields.io/docker/pulls/codexstorage/nim-codex) ![Docker Pulls](https://img.shields.io/docker/pulls/codexstorage/nim-codex)
## Build and Run ## Build and Run
For detailed instructions on preparing to build nim-codex see [*Build Codex*](https://docs.codex.storage/learn/build). For detailed instructions on preparing to build logos-storagenim see [*Build Logos Storage*](https://docs.codex.storage/learn/build).
To build the project, clone it and run: To build the project, clone it and run:
@ -29,12 +29,12 @@ The executable will be placed under the `build` directory under the project root
Run the client with: Run the client with:
```bash ```bash
build/codex build/storage
``` ```
## Configuration ## Configuration
It is possible to configure a Codex node in several ways: It is possible to configure a Logos Storage node in several ways:
1. CLI options 1. CLI options
2. Environment variables 2. Environment variables
3. Configuration file 3. Configuration file
@ -45,9 +45,9 @@ Please check [documentation](https://docs.codex.storage/learn/run#configuration)
## Guides ## Guides
To get acquainted with Codex, consider: To get acquainted with Logos Storage, consider:
* running the simple [Codex Two-Client Test](https://docs.codex.storage/learn/local-two-client-test) for a start, and; * running the simple [Logos Storage Two-Client Test](https://docs.codex.storage/learn/local-two-client-test) for a start, and;
* if you are feeling more adventurous, try [Running a Local Codex Network with Marketplace Support](https://docs.codex.storage/learn/local-marketplace) using a local blockchain as well. * if you are feeling more adventurous, try [Running a Local Logos Storage Network with Marketplace Support](https://docs.codex.storage/learn/local-marketplace) using a local blockchain as well.
## API ## API
@ -55,13 +55,13 @@ The client exposes a REST API that can be used to interact with the clients. Ove
## Bindings ## Bindings
Codex provides a C API that can be wrapped by other languages. The bindings is located in the `library` folder. Logos Storage provides a C API that can be wrapped by other languages. The bindings is located in the `library` folder.
Currently, only a Go binding is included. Currently, only a Go binding is included.
### Build the C library ### Build the C library
```bash ```bash
make libcodex make libstorage
``` ```
This produces the shared library under `build/`. This produces the shared library under `build/`.
@ -71,7 +71,7 @@ This produces the shared library under `build/`.
Build the Go example: Build the Go example:
```bash ```bash
go build -o codex-go examples/golang/codex.go go build -o storage-go examples/golang/storage.go
``` ```
Export the library path: Export the library path:
@ -83,20 +83,20 @@ export LD_LIBRARY_PATH=build
Run the example: Run the example:
```bash ```bash
./codex-go ./storage-go
``` ```
### Static vs Dynamic build ### Static vs Dynamic build
By default, Codex builds a dynamic library (`libcodex.so`), which you can load at runtime. By default, Logos Storage builds a dynamic library (`libstorage.so`), which you can load at runtime.
If you prefer a static library (`libcodex.a`), set the `STATIC` flag: If you prefer a static library (`libstorage.a`), set the `STATIC` flag:
```bash ```bash
# Build dynamic (default) # Build dynamic (default)
make libcodex make libstorage
# Build static # Build static
make STATIC=1 libcodex make STATIC=1 libstorage
``` ```
### Limitation ### Limitation
@ -109,7 +109,7 @@ Feel free to dive in, contributions are welcomed! Open an issue or submit PRs.
### Linting and formatting ### Linting and formatting
`nim-codex` uses [nph](https://github.com/arnetheduck/nph) for formatting our code and it is required to adhere to its styling. `logos-storage-nim` uses [nph](https://github.com/arnetheduck/nph) for formatting our code and it is required to adhere to its styling.
If you are setting up fresh setup, in order to get `nph` run `make build-nph`. If you are setting up fresh setup, in order to get `nph` run `make build-nph`.
In order to format files run `make nph/<file/folder you want to format>`. In order to format files run `make nph/<file/folder you want to format>`.
If you want you can install Git pre-commit hook using `make install-nph-commit`, which will format modified files prior committing them. If you want you can install Git pre-commit hook using `make install-nph-commit`, which will format modified files prior committing them.

View File

@ -10,17 +10,17 @@ nim c -r run_benchmarks
``` ```
By default all circuit files for each combinations of circuit args will be generated in a unique folder named like: By default all circuit files for each combinations of circuit args will be generated in a unique folder named like:
nim-codex/benchmarks/circuit_bench_depth32_maxslots256_cellsize2048_blocksize65536_nsamples9_entropy1234567_seed12345_nslots11_ncells512_index3 logos-storage-nim/benchmarks/circuit_bench_depth32_maxslots256_cellsize2048_blocksize65536_nsamples9_entropy1234567_seed12345_nslots11_ncells512_index3
Generating the circuit files often takes longer than running benchmarks, so caching the results allows re-running the benchmark as needed. Generating the circuit files often takes longer than running benchmarks, so caching the results allows re-running the benchmark as needed.
You can modify the `CircuitArgs` and `CircuitEnv` objects in `runAllBenchMarks` to suite your needs. See `create_circuits.nim` for their definition. You can modify the `CircuitArgs` and `CircuitEnv` objects in `runAllBenchMarks` to suite your needs. See `create_circuits.nim` for their definition.
The runner executes all commands relative to the `nim-codex` repo. This simplifies finding the correct circuit includes paths, etc. `CircuitEnv` sets all of this. The runner executes all commands relative to the `logos-storage-nim` repo. This simplifies finding the correct circuit includes paths, etc. `CircuitEnv` sets all of this.
## Codex Ark Circom CLI ## Logos Storage Ark Circom CLI
Runs Codex's prover setup with Ark / Circom. Runs Logos Storage's prover setup with Ark / Circom.
Compile: Compile:
```sh ```sh

View File

@ -29,10 +29,10 @@ proc findCodexProjectDir(): string =
func default*(tp: typedesc[CircuitEnv]): CircuitEnv = func default*(tp: typedesc[CircuitEnv]): CircuitEnv =
let codexDir = findCodexProjectDir() let codexDir = findCodexProjectDir()
result.nimCircuitCli = result.nimCircuitCli =
codexDir / "vendor" / "codex-storage-proofs-circuits" / "reference" / "nim" / codexDir / "vendor" / "logos-storage-proofs-circuits" / "reference" / "nim" /
"proof_input" / "cli" "proof_input" / "cli"
result.circuitDirIncludes = result.circuitDirIncludes =
codexDir / "vendor" / "codex-storage-proofs-circuits" / "circuit" codexDir / "vendor" / "logos-storage-proofs-circuits" / "circuit"
result.ptauPath = result.ptauPath =
codexDir / "benchmarks" / "ceremony" / "powersOfTau28_hez_final_23.ptau" codexDir / "benchmarks" / "ceremony" / "powersOfTau28_hez_final_23.ptau"
result.ptauUrl = "https://storage.googleapis.com/zkevm/ptau".parseUri result.ptauUrl = "https://storage.googleapis.com/zkevm/ptau".parseUri
@ -118,7 +118,7 @@ proc createCircuit*(
## ##
## All needed circuit files will be generated as needed. ## All needed circuit files will be generated as needed.
## They will be located in `circBenchDir` which defaults to a folder like: ## They will be located in `circBenchDir` which defaults to a folder like:
## `nim-codex/benchmarks/circuit_bench_depth32_maxslots256_cellsize2048_blocksize65536_nsamples9_entropy1234567_seed12345_nslots11_ncells512_index3` ## `logos-storage-nim/benchmarks/circuit_bench_depth32_maxslots256_cellsize2048_blocksize65536_nsamples9_entropy1234567_seed12345_nslots11_ncells512_index3`
## with all the given CircuitArgs. ## with all the given CircuitArgs.
## ##
let circdir = circBenchDir let circdir = circBenchDir

View File

@ -3,7 +3,7 @@ mode = ScriptMode.Verbose
import std/os except commandLineParams import std/os except commandLineParams
### Helper functions ### Helper functions
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = proc buildBinary(srcName: string, outName = os.lastPathPart(srcName), srcDir = "./", params = "", lang = "c") =
if not dirExists "build": if not dirExists "build":
mkDir "build" mkDir "build"
@ -18,10 +18,9 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
let let
# Place build output in 'build' folder, even if name includes a longer path. # Place build output in 'build' folder, even if name includes a longer path.
outName = os.lastPathPart(name)
cmd = cmd =
"nim " & lang & " --out:build/" & outName & " " & extra_params & " " & srcDir & "nim " & lang & " --out:build/" & outName & " " & extra_params & " " & srcDir &
name & ".nim" srcName & ".nim"
exec(cmd) exec(cmd)
@ -37,62 +36,64 @@ proc buildLibrary(name: string, srcDir = "./", params = "", `type` = "dynamic")
) )
exec "nim c" & " --out:build/" & lib_name & exec "nim c" & " --out:build/" & lib_name &
" --threads:on --app:lib --opt:size --noMain --mm:refc --header --d:metrics " & " --threads:on --app:lib --opt:size --noMain --mm:refc --header --d:metrics " &
"--nimMainPrefix:libcodex -d:noSignalHandler " & "--nimMainPrefix:libstorage -d:noSignalHandler " &
"-d:LeopardExtraCompilerFlags=-fPIC " & "-d:chronicles_runtime_filtering " & "-d:LeopardExtraCompilerFlags=-fPIC " & "-d:chronicles_runtime_filtering " &
"-d:chronicles_log_level=TRACE " & params & " " & srcDir & name & ".nim" "-d:chronicles_log_level=TRACE " & params & " " & srcDir & name & ".nim"
else: else:
exec "nim c" & " --out:build/" & name & exec "nim c" & " --out:build/" & name &
".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --d:metrics " & ".a --threads:on --app:staticlib --opt:size --noMain --mm:refc --header --d:metrics " &
"--nimMainPrefix:libcodex -d:noSignalHandler " & "--nimMainPrefix:libstorage -d:noSignalHandler " &
"-d:LeopardExtraCompilerFlags=-fPIC " & "-d:LeopardExtraCompilerFlags=-fPIC " &
"-d:chronicles_runtime_filtering " & "-d:chronicles_runtime_filtering " &
"-d:chronicles_log_level=TRACE " & "-d:chronicles_log_level=TRACE " &
params & " " & srcDir & name & ".nim" params & " " & srcDir & name & ".nim"
proc test(name: string, srcDir = "tests/", params = "", lang = "c") = proc test(name: string, outName = name, srcDir = "tests/", params = "", lang = "c") =
buildBinary name, srcDir, params buildBinary name, outName, srcDir, params
exec "build/" & name exec "build/" & outName
task codex, "build codex binary": task storage, "build logos storage binary":
buildBinary "codex", buildBinary "codex",
outname = "storage",
params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE" params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE"
task toolsCirdl, "build tools/cirdl binary": task toolsCirdl, "build tools/cirdl binary":
buildBinary "tools/cirdl/cirdl" buildBinary "tools/cirdl/cirdl"
task testCodex, "Build & run Codex tests": task testStorage, "Build & run Logos Storage tests":
test "testCodex", params = "-d:codex_enable_proof_failures=true" test "testCodex", outName = "testStorage", params = "-d:storage_enable_proof_failures=true"
task testContracts, "Build & run Codex Contract tests": task testContracts, "Build & run Logos Storage Contract tests":
test "testContracts" test "testContracts"
task testIntegration, "Run integration tests": task testIntegration, "Run integration tests":
buildBinary "codex", buildBinary "codex",
outName = "storage",
params = params =
"-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE -d:codex_enable_proof_failures=true" "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE -d:storage_enable_proof_failures=true"
test "testIntegration" test "testIntegration"
# use params to enable logging from the integration test executable # use params to enable logging from the integration test executable
# test "testIntegration", params = "-d:chronicles_sinks=textlines[notimestamps,stdout],textlines[dynamic] " & # test "testIntegration", params = "-d:chronicles_sinks=textlines[notimestamps,stdout],textlines[dynamic] " &
# "-d:chronicles_enabled_topics:integration:TRACE" # "-d:chronicles_enabled_topics:integration:TRACE"
task build, "build codex binary": task build, "build Logos Storage binary":
codexTask() storageTask()
task test, "Run tests": task test, "Run tests":
testCodexTask() testStorageTask()
task testTools, "Run Tools tests": task testTools, "Run Tools tests":
toolsCirdlTask() toolsCirdlTask()
test "testTools" test "testTools"
task testAll, "Run all tests (except for Taiko L2 tests)": task testAll, "Run all tests (except for Taiko L2 tests)":
testCodexTask() testStorageTask()
testContractsTask() testContractsTask()
testIntegrationTask() testIntegrationTask()
testToolsTask() testToolsTask()
task testTaiko, "Run Taiko L2 tests": task testTaiko, "Run Taiko L2 tests":
codexTask() storageTask()
test "testTaiko" test "testTaiko"
import strutils import strutils
@ -125,7 +126,7 @@ task coverage, "generates code coverage report":
test "coverage", test "coverage",
srcDir = "tests/", srcDir = "tests/",
params = params =
" --nimcache:nimcache/coverage -d:release -d:codex_enable_proof_failures=true" " --nimcache:nimcache/coverage -d:release -d:storage_enable_proof_failures=true"
exec("rm nimcache/coverage/*.c") exec("rm nimcache/coverage/*.c")
rmDir("coverage") rmDir("coverage")
mkDir("coverage") mkDir("coverage")
@ -146,22 +147,22 @@ task showCoverage, "open coverage html":
if findExe("open") != "": if findExe("open") != "":
exec("open coverage/report/index.html") exec("open coverage/report/index.html")
task libcodexDynamic, "Generate bindings": task libstorageDynamic, "Generate bindings":
var params = "" var params = ""
when compiles(commandLineParams): when compiles(commandLineParams):
for param in commandLineParams(): for param in commandLineParams():
if param.len > 0 and param.startsWith("-"): if param.len > 0 and param.startsWith("-"):
params.add " " & param params.add " " & param
let name = "libcodex" let name = "libstorage"
buildLibrary name, "library/", params, "dynamic" buildLibrary name, "library/", params, "dynamic"
task libcodexStatic, "Generate bindings": task libstorageStatic, "Generate bindings":
var params = "" var params = ""
when compiles(commandLineParams): when compiles(commandLineParams):
for param in commandLineParams(): for param in commandLineParams():
if param.len > 0 and param.startsWith("-"): if param.len > 0 and param.startsWith("-"):
params.add " " & param params.add " " & param
let name = "libcodex" let name = "libstorage"
buildLibrary name, "library/", params, "static" buildLibrary name, "library/", params, "static"

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
@ -45,7 +45,7 @@ when isMainModule:
let config = CodexConf.load( let config = CodexConf.load(
version = codexFullVersion, version = codexFullVersion,
envVarsPrefix = "codex", envVarsPrefix = "storage",
secondarySources = proc( secondarySources = proc(
config: CodexConf, sources: auto config: CodexConf, sources: auto
) {.gcsafe, raises: [ConfigurationError].} = ) {.gcsafe, raises: [ConfigurationError].} =
@ -99,7 +99,7 @@ when isMainModule:
try: try:
CodexServer.new(config, privateKey) CodexServer.new(config, privateKey)
except Exception as exc: except Exception as exc:
error "Failed to start Codex", msg = exc.msg error "Failed to start Logos Storage", msg = exc.msg
quit QuitFailure quit QuitFailure
## Ctrl+C handling ## Ctrl+C handling
@ -107,7 +107,7 @@ when isMainModule:
shutdown = server.shutdown() shutdown = server.shutdown()
state = CodexStatus.Stopping state = CodexStatus.Stopping
notice "Stopping Codex" notice "Stopping Logos Storage"
proc controlCHandler() {.noconv.} = proc controlCHandler() {.noconv.} =
when defined(windows): when defined(windows):
@ -138,7 +138,7 @@ when isMainModule:
try: try:
waitFor server.start() waitFor server.start()
except CatchableError as error: except CatchableError as error:
error "Codex failed to start", error = error.msg error "Logos Storage failed to start", error = error.msg
# XXX ideally we'd like to issue a stop instead of quitting cold turkey, # XXX ideally we'd like to issue a stop instead of quitting cold turkey,
# but this would mean we'd have to fix the implementation of all # but this would mean we'd have to fix the implementation of all
# services so they won't crash if we attempt to stop them before they # services so they won't crash if we attempt to stop them before they
@ -159,7 +159,7 @@ when isMainModule:
# be assigned before state switches to Stopping # be assigned before state switches to Stopping
waitFor shutdown waitFor shutdown
except CatchableError as error: except CatchableError as error:
error "Codex didn't shutdown correctly", error = error.msg error "Logos Storage didn't shutdown correctly", error = error.msg
quit QuitFailure quit QuitFailure
notice "Exited codex" notice "Exited Storage"

View File

@ -1,5 +1,5 @@
version = "0.1.0" version = "0.1.0"
author = "Codex Team" author = "Logos Storage Team"
description = "p2p data durability engine" description = "p2p data durability engine"
license = "MIT" license = "MIT"
binDir = "build" binDir = "build"

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
# Protocol of data exchange between Codex nodes # Protocol of data exchange between Logos Storage nodes
# and Protobuf encoder/decoder for these messages. # and Protobuf encoder/decoder for these messages.
# #
# Eventually all this code should be auto-generated from message.proto. # Eventually all this code should be auto-generated from message.proto.

View File

@ -1,4 +1,4 @@
// Protocol of data exchange between Codex nodes. // Protocol of data exchange between Logos Storage nodes.
// Extended version of https://github.com/ipfs/specs/blob/main/BITSWAP.md // Extended version of https://github.com/ipfs/specs/blob/main/BITSWAP.md
syntax = "proto3"; syntax = "proto3";

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
@ -138,7 +138,7 @@ proc bootstrapInteractions(s: CodexServer): Future[void] {.async.} =
# This is used for simulation purposes. Normal nodes won't be compiled with this flag # This is used for simulation purposes. Normal nodes won't be compiled with this flag
# and hence the proof failure will always be 0. # and hence the proof failure will always be 0.
when codex_enable_proof_failures: when storage_enable_proof_failures:
let proofFailures = config.simulateProofFailures let proofFailures = config.simulateProofFailures
if proofFailures > 0: if proofFailures > 0:
warn "Enabling proof failure simulation!" warn "Enabling proof failure simulation!"
@ -170,10 +170,10 @@ proc bootstrapInteractions(s: CodexServer): Future[void] {.async.} =
proc start*(s: CodexServer) {.async.} = proc start*(s: CodexServer) {.async.} =
if s.isStarted: if s.isStarted:
warn "Codex server already started, skipping" warn "Storage server already started, skipping"
return return
trace "Starting codex node", config = $s.config trace "Starting Storage node", config = $s.config
await s.repoStore.start() await s.repoStore.start()
s.maintenance.start() s.maintenance.start()
@ -197,10 +197,10 @@ proc start*(s: CodexServer) {.async.} =
proc stop*(s: CodexServer) {.async.} = proc stop*(s: CodexServer) {.async.} =
if not s.isStarted: if not s.isStarted:
warn "Codex is not started" warn "Storage is not started"
return return
notice "Stopping codex node" notice "Stopping Storage node"
var futures = var futures =
@[ @[
@ -216,8 +216,8 @@ proc stop*(s: CodexServer) {.async.} =
let res = await noCancel allFinishedFailed[void](futures) let res = await noCancel allFinishedFailed[void](futures)
if res.failure.len > 0: if res.failure.len > 0:
error "Failed to stop codex node", failures = res.failure.len error "Failed to stop Storage node", failures = res.failure.len
raiseAssert "Failed to stop codex node" raiseAssert "Failed to stop Storage node"
proc close*(s: CodexServer) {.async.} = proc close*(s: CodexServer) {.async.} =
var futures = @[s.codexNode.close(), s.repoStore.close()] var futures = @[s.codexNode.close(), s.repoStore.close()]
@ -232,8 +232,8 @@ proc close*(s: CodexServer) {.async.} =
raiseAssert("Failure in taskpool shutdown:" & exc.msg) raiseAssert("Failure in taskpool shutdown:" & exc.msg)
if res.failure.len > 0: if res.failure.len > 0:
error "Failed to close codex node", failures = res.failure.len error "Failed to close Storage node", failures = res.failure.len
raiseAssert "Failed to close codex node" raiseAssert "Failed to close Storage node"
proc shutdown*(server: CodexServer) {.async.} = proc shutdown*(server: CodexServer) {.async.} =
await server.stop() await server.stop()

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
@ -63,18 +63,18 @@ proc `==`*(a, b: ThreadCount): bool {.borrow.}
proc defaultDataDir*(): string = proc defaultDataDir*(): string =
let dataDir = let dataDir =
when defined(windows): when defined(windows):
"AppData" / "Roaming" / "Codex" "AppData" / "Roaming" / "Storage"
elif defined(macosx): elif defined(macosx):
"Library" / "Application Support" / "Codex" "Library" / "Application Support" / "Storage"
else: else:
".cache" / "codex" ".cache" / "storage"
getHomeDir() / dataDir getHomeDir() / dataDir
const const
codex_enable_api_debug_peers* {.booldefine.} = false storage_enable_api_debug_peers* {.booldefine.} = false
codex_enable_proof_failures* {.booldefine.} = false storage_enable_proof_failures* {.booldefine.} = false
codex_enable_log_counter* {.booldefine.} = false storage_enable_log_counter* {.booldefine.} = false
DefaultThreadCount* = ThreadCount(0) DefaultThreadCount* = ThreadCount(0)
@ -137,7 +137,7 @@ type
.}: Port .}: Port
dataDir* {. dataDir* {.
desc: "The directory where codex will store configuration and data", desc: "The directory where Storage will store configuration and data",
defaultValue: defaultDataDir(), defaultValue: defaultDataDir(),
defaultValueDesc: "", defaultValueDesc: "",
abbr: "d", abbr: "d",
@ -198,7 +198,7 @@ type
.}: ThreadCount .}: ThreadCount
agentString* {. agentString* {.
defaultValue: "Codex", defaultValue: "Logos Storage",
desc: "Node agent string which is used as identifier in network", desc: "Node agent string which is used as identifier in network",
name: "agent-string" name: "agent-string"
.}: string .}: string
@ -391,7 +391,7 @@ type
case persistenceCmd* {.defaultValue: noCmd, command.}: PersistenceCmd case persistenceCmd* {.defaultValue: noCmd, command.}: PersistenceCmd
of PersistenceCmd.prover: of PersistenceCmd.prover:
circuitDir* {. circuitDir* {.
desc: "Directory where Codex will store proof circuit data", desc: "Directory where Storage will store proof circuit data",
defaultValue: defaultDataDir() / "circuits", defaultValue: defaultDataDir() / "circuits",
defaultValueDesc: "data/circuits", defaultValueDesc: "data/circuits",
abbr: "cd", abbr: "cd",
@ -496,7 +496,8 @@ proc getCodexRevision(): string =
return res return res
proc getCodexContractsRevision(): string = proc getCodexContractsRevision(): string =
let res = strip(staticExec("git rev-parse --short HEAD:vendor/codex-contracts-eth")) let res =
strip(staticExec("git rev-parse --short HEAD:vendor/logos-storage-contracts-eth"))
return res return res
proc getNimBanner(): string = proc getNimBanner(): string =
@ -509,8 +510,8 @@ const
nimBanner* = getNimBanner() nimBanner* = getNimBanner()
codexFullVersion* = codexFullVersion* =
"Codex version: " & codexVersion & "\p" & "Codex revision: " & codexRevision & "\p" & "Storage version: " & codexVersion & "\p" & "Storage revision: " & codexRevision &
"Codex contracts revision: " & codexContractsRevision & "\p" & nimBanner "\p" & "Storage contracts revision: " & codexContractsRevision & "\p" & nimBanner
proc parseCmdArg*( proc parseCmdArg*(
T: typedesc[MultiAddress], input: string T: typedesc[MultiAddress], input: string
@ -803,7 +804,7 @@ proc setupLogging*(conf: CodexConf) =
of LogKind.None: of LogKind.None:
noOutput noOutput
when codex_enable_log_counter: when storage_enable_log_counter:
var counter = 0.uint64 var counter = 0.uint64
proc numberedWriter(logLevel: LogLevel, msg: LogOutputStr) = proc numberedWriter(logLevel: LogLevel, msg: LogOutputStr) =
inc(counter) inc(counter)

View File

@ -1,13 +1,13 @@
Codex Contracts in Nim Logos Storage Contracts in Nim
======================= =======================
Nim API for the [Codex smart contracts][1]. Nim API for the [Logos Storage smart contracts][1].
Usage Usage
----- -----
For a global overview of the steps involved in starting and fulfilling a For a global overview of the steps involved in starting and fulfilling a
storage contract, see [Codex Contracts][1]. storage contract, see [Logos Storage Contracts][1].
Smart contract Smart contract
-------------- --------------
@ -144,5 +144,5 @@ await storage
.markProofAsMissing(id, period) .markProofAsMissing(id, period)
``` ```
[1]: https://github.com/status-im/codex-contracts-eth/ [1]: https://github.com/logos-storage/logos-storage-contracts-eth/
[2]: https://github.com/status-im/codex-research/blob/main/design/storage-proof-timing.md [2]: https://github.com/logos-storage/logos-storage-research/blob/master/design/storage-proof-timing.md

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -11,7 +11,7 @@
## 4. Remove usages of `nim-json-serialization` from the codebase ## 4. Remove usages of `nim-json-serialization` from the codebase
## 5. Remove need to declare `writeValue` for new types ## 5. Remove need to declare `writeValue` for new types
## 6. Remove need to [avoid importing or exporting `toJson`, `%`, `%*` to prevent ## 6. Remove need to [avoid importing or exporting `toJson`, `%`, `%*` to prevent
## conflicts](https://github.com/codex-storage/nim-codex/pull/645#issuecomment-1838834467) ## conflicts](https://github.com/logos-storage/logos-storage-nim/pull/645#issuecomment-1838834467)
## ##
## When declaring a new type, one should consider importing the `codex/logutils` ## When declaring a new type, one should consider importing the `codex/logutils`
## module, and specifying `formatIt`. If textlines log output and json log output ## module, and specifying `formatIt`. If textlines log output and json log output

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -4,7 +4,7 @@ import poseidon2
proc sha2_256hash_constantine(data: openArray[byte], output: var openArray[byte]) = proc sha2_256hash_constantine(data: openArray[byte], output: var openArray[byte]) =
# Using Constantine's SHA256 instead of mhash for optimal performance on 32-byte merkle node hashing # Using Constantine's SHA256 instead of mhash for optimal performance on 32-byte merkle node hashing
# See: https://github.com/codex-storage/nim-codex/issues/1162 # See: https://github.com/logos-storage/logos-storage-nim/issues/1162
if len(output) > 0: if len(output) > 0:
let digest = hashes.sha256.hash(data) let digest = hashes.sha256.hash(data)
copyMem(addr output[0], addr digest[0], 32) copyMem(addr output[0], addr digest[0], 32)

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
@ -881,7 +881,7 @@ proc start*(self: CodexNodeRef) {.async.} =
self.contracts.validator = ValidatorInteractions.none self.contracts.validator = ValidatorInteractions.none
self.networkId = self.switch.peerInfo.peerId self.networkId = self.switch.peerInfo.peerId
notice "Started codex node", id = self.networkId, addrs = self.switch.peerInfo.addrs notice "Started Storage node", id = self.networkId, addrs = self.switch.peerInfo.addrs
proc stop*(self: CodexNodeRef) {.async.} = proc stop*(self: CodexNodeRef) {.async.} =
trace "Stopping node" trace "Stopping node"

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
@ -180,7 +180,7 @@ proc getFilenameFromContentDisposition(contentDisposition: string): ?string =
proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRouter) = proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRouter) =
let allowedOrigin = router.allowedOrigin # prevents capture inside of api defintion let allowedOrigin = router.allowedOrigin # prevents capture inside of api defintion
router.api(MethodOptions, "/api/codex/v1/data") do( router.api(MethodOptions, "/api/storage/v1/data") do(
resp: HttpResponseRef resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
if corsOrigin =? allowedOrigin: if corsOrigin =? allowedOrigin:
@ -192,7 +192,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
resp.status = Http204 resp.status = Http204
await resp.sendBody("") await resp.sendBody("")
router.rawApi(MethodPost, "/api/codex/v1/data") do() -> RestApiResponse: router.rawApi(MethodPost, "/api/storage/v1/data") do() -> RestApiResponse:
## Upload a file in a streaming manner ## Upload a file in a streaming manner
## ##
@ -254,11 +254,11 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
finally: finally:
await reader.closeWait() await reader.closeWait()
router.api(MethodGet, "/api/codex/v1/data") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/data") do() -> RestApiResponse:
let json = await formatManifestBlocks(node) let json = await formatManifestBlocks(node)
return RestApiResponse.response($json, contentType = "application/json") return RestApiResponse.response($json, contentType = "application/json")
router.api(MethodOptions, "/api/codex/v1/data/{cid}") do( router.api(MethodOptions, "/api/storage/v1/data/{cid}") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
if corsOrigin =? allowedOrigin: if corsOrigin =? allowedOrigin:
@ -267,7 +267,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
resp.status = Http204 resp.status = Http204
await resp.sendBody("") await resp.sendBody("")
router.api(MethodGet, "/api/codex/v1/data/{cid}") do( router.api(MethodGet, "/api/storage/v1/data/{cid}") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
@ -283,7 +283,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
await node.retrieveCid(cid.get(), local = true, resp = resp) await node.retrieveCid(cid.get(), local = true, resp = resp)
router.api(MethodDelete, "/api/codex/v1/data/{cid}") do( router.api(MethodDelete, "/api/storage/v1/data/{cid}") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
## Deletes either a single block or an entire dataset ## Deletes either a single block or an entire dataset
@ -304,7 +304,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
resp.status = Http204 resp.status = Http204
await resp.sendBody("") await resp.sendBody("")
router.api(MethodPost, "/api/codex/v1/data/{cid}/network") do( router.api(MethodPost, "/api/storage/v1/data/{cid}/network") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
## Download a file from the network to the local node ## Download a file from the network to the local node
@ -325,7 +325,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
let json = %formatManifest(cid.get(), manifest) let json = %formatManifest(cid.get(), manifest)
return RestApiResponse.response($json, contentType = "application/json") return RestApiResponse.response($json, contentType = "application/json")
router.api(MethodGet, "/api/codex/v1/data/{cid}/network/stream") do( router.api(MethodGet, "/api/storage/v1/data/{cid}/network/stream") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
## Download a file from the network in a streaming ## Download a file from the network in a streaming
@ -344,7 +344,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
resp.setHeader("Access-Control-Expose-Headers", "Content-Disposition") resp.setHeader("Access-Control-Expose-Headers", "Content-Disposition")
await node.retrieveCid(cid.get(), local = false, resp = resp) await node.retrieveCid(cid.get(), local = false, resp = resp)
router.api(MethodGet, "/api/codex/v1/data/{cid}/network/manifest") do( router.api(MethodGet, "/api/storage/v1/data/{cid}/network/manifest") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
## Download only the manifest. ## Download only the manifest.
@ -362,7 +362,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
let json = %formatManifest(cid.get(), manifest) let json = %formatManifest(cid.get(), manifest)
return RestApiResponse.response($json, contentType = "application/json") return RestApiResponse.response($json, contentType = "application/json")
router.api(MethodGet, "/api/codex/v1/data/{cid}/exists") do( router.api(MethodGet, "/api/storage/v1/data/{cid}/exists") do(
cid: Cid, resp: HttpResponseRef cid: Cid, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
## Only test if the give CID is available in the local store ## Only test if the give CID is available in the local store
@ -378,7 +378,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
let json = %*{$cid: hasCid} let json = %*{$cid: hasCid}
return RestApiResponse.response($json, contentType = "application/json") return RestApiResponse.response($json, contentType = "application/json")
router.api(MethodGet, "/api/codex/v1/space") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/space") do() -> RestApiResponse:
let json = let json =
%RestRepoStore( %RestRepoStore(
totalBlocks: repoStore.totalBlocks, totalBlocks: repoStore.totalBlocks,
@ -391,7 +391,7 @@ proc initDataApi(node: CodexNodeRef, repoStore: RepoStore, router: var RestRoute
proc initSalesApi(node: CodexNodeRef, router: var RestRouter) = proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
let allowedOrigin = router.allowedOrigin let allowedOrigin = router.allowedOrigin
router.api(MethodGet, "/api/codex/v1/sales/slots") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/sales/slots") do() -> RestApiResponse:
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
## Returns active slots for the host ## Returns active slots for the host
@ -409,7 +409,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodGet, "/api/codex/v1/sales/slots/{slotId}") do( router.api(MethodGet, "/api/storage/v1/sales/slots/{slotId}") do(
slotId: SlotId slotId: SlotId
) -> RestApiResponse: ) -> RestApiResponse:
## Returns active slot with id {slotId} for the host. Returns 404 if the ## Returns active slot with id {slotId} for the host. Returns 404 if the
@ -439,7 +439,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
restAgent.toJson, contentType = "application/json", headers = headers restAgent.toJson, contentType = "application/json", headers = headers
) )
router.api(MethodGet, "/api/codex/v1/sales/availability") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/sales/availability") do() -> RestApiResponse:
## Returns storage that is for sale ## Returns storage that is for sale
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
@ -461,7 +461,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.rawApi(MethodPost, "/api/codex/v1/sales/availability") do() -> RestApiResponse: router.rawApi(MethodPost, "/api/storage/v1/sales/availability") do() -> RestApiResponse:
## Add available storage to sell. ## Add available storage to sell.
## Every time Availability's offer finishes, its capacity is ## Every time Availability's offer finishes, its capacity is
## returned to the availability. ## returned to the availability.
@ -541,7 +541,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodOptions, "/api/codex/v1/sales/availability/{id}") do( router.api(MethodOptions, "/api/storage/v1/sales/availability/{id}") do(
id: AvailabilityId, resp: HttpResponseRef id: AvailabilityId, resp: HttpResponseRef
) -> RestApiResponse: ) -> RestApiResponse:
if corsOrigin =? allowedOrigin: if corsOrigin =? allowedOrigin:
@ -550,7 +550,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
resp.status = Http204 resp.status = Http204
await resp.sendBody("") await resp.sendBody("")
router.rawApi(MethodPatch, "/api/codex/v1/sales/availability/{id}") do( router.rawApi(MethodPatch, "/api/storage/v1/sales/availability/{id}") do(
id: AvailabilityId id: AvailabilityId
) -> RestApiResponse: ) -> RestApiResponse:
## Updates Availability. ## Updates Availability.
@ -638,7 +638,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500) return RestApiResponse.error(Http500)
router.rawApi(MethodGet, "/api/codex/v1/sales/availability/{id}/reservations") do( router.rawApi(MethodGet, "/api/storage/v1/sales/availability/{id}/reservations") do(
id: AvailabilityId id: AvailabilityId
) -> RestApiResponse: ) -> RestApiResponse:
## Gets Availability's reservations. ## Gets Availability's reservations.
@ -682,7 +682,7 @@ proc initSalesApi(node: CodexNodeRef, router: var RestRouter) =
proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) = proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
let allowedOrigin = router.allowedOrigin let allowedOrigin = router.allowedOrigin
router.rawApi(MethodPost, "/api/codex/v1/storage/request/{cid}") do( router.rawApi(MethodPost, "/api/storage/v1/storage/request/{cid}") do(
cid: Cid cid: Cid
) -> RestApiResponse: ) -> RestApiResponse:
var headers = buildCorsHeaders("POST", allowedOrigin) var headers = buildCorsHeaders("POST", allowedOrigin)
@ -792,7 +792,7 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodGet, "/api/codex/v1/storage/purchases/{id}") do( router.api(MethodGet, "/api/storage/v1/storage/purchases/{id}") do(
id: PurchaseId id: PurchaseId
) -> RestApiResponse: ) -> RestApiResponse:
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
@ -824,7 +824,7 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodGet, "/api/codex/v1/storage/purchases") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/storage/purchases") do() -> RestApiResponse:
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
try: try:
@ -846,7 +846,7 @@ proc initNodeApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
## various node management api's ## various node management api's
## ##
router.api(MethodGet, "/api/codex/v1/spr") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/spr") do() -> RestApiResponse:
## Returns node SPR in requested format, json or text. ## Returns node SPR in requested format, json or text.
## ##
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
@ -869,7 +869,7 @@ proc initNodeApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodGet, "/api/codex/v1/peerid") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/peerid") do() -> RestApiResponse:
## Returns node's peerId in requested format, json or text. ## Returns node's peerId in requested format, json or text.
## ##
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
@ -888,7 +888,7 @@ proc initNodeApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodGet, "/api/codex/v1/connect/{peerId}") do( router.api(MethodGet, "/api/storage/v1/connect/{peerId}") do(
peerId: PeerId, addrs: seq[MultiAddress] peerId: PeerId, addrs: seq[MultiAddress]
) -> RestApiResponse: ) -> RestApiResponse:
## Connect to a peer ## Connect to a peer
@ -926,7 +926,7 @@ proc initNodeApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) = proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
let allowedOrigin = router.allowedOrigin let allowedOrigin = router.allowedOrigin
router.api(MethodGet, "/api/codex/v1/debug/info") do() -> RestApiResponse: router.api(MethodGet, "/api/storage/v1/debug/info") do() -> RestApiResponse:
## Print rudimentary node information ## Print rudimentary node information
## ##
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)
@ -946,7 +946,7 @@ proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
"", "",
"announceAddresses": node.discovery.announceAddrs, "announceAddresses": node.discovery.announceAddrs,
"table": table, "table": table,
"codex": { "storage": {
"version": $codexVersion, "version": $codexVersion,
"revision": $codexRevision, "revision": $codexRevision,
"contracts": $codexContractsRevision, "contracts": $codexContractsRevision,
@ -961,7 +961,7 @@ proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
router.api(MethodPost, "/api/codex/v1/debug/chronicles/loglevel") do( router.api(MethodPost, "/api/storage/v1/debug/chronicles/loglevel") do(
level: Option[string] level: Option[string]
) -> RestApiResponse: ) -> RestApiResponse:
## Set log level at run time ## Set log level at run time
@ -987,8 +987,8 @@ proc initDebugApi(node: CodexNodeRef, conf: CodexConf, router: var RestRouter) =
trace "Excepting processing request", exc = exc.msg trace "Excepting processing request", exc = exc.msg
return RestApiResponse.error(Http500, headers = headers) return RestApiResponse.error(Http500, headers = headers)
when codex_enable_api_debug_peers: when storage_enable_api_debug_peers:
router.api(MethodGet, "/api/codex/v1/debug/peer/{peerId}") do( router.api(MethodGet, "/api/storage/v1/debug/peer/{peerId}") do(
peerId: PeerId peerId: PeerId
) -> RestApiResponse: ) -> RestApiResponse:
var headers = buildCorsHeaders("GET", allowedOrigin) var headers = buildCorsHeaders("GET", allowedOrigin)

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -22,7 +22,7 @@ import ./utils/exceptions
## Sales holds a list of available storage that it may sell. ## Sales holds a list of available storage that it may sell.
## ##
## When storage is requested on the market that matches availability, the Sales ## When storage is requested on the market that matches availability, the Sales
## object will instruct the Codex node to persist the requested data. Once the ## object will instruct the Logos Storage node to persist the requested data. Once the
## data has been persisted, it uploads a proof of storage to the market in an ## data has been persisted, it uploads a proof of storage to the market in an
## attempt to win a storage contract. ## attempt to win a storage contract.
## ##

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -11,7 +11,7 @@ import ./cancelled
import ./failed import ./failed
import ./proving import ./proving
when codex_enable_proof_failures: when storage_enable_proof_failures:
import ./provingsimulated import ./provingsimulated
logScope: logScope:
@ -59,7 +59,7 @@ method run*(
if err =? (await onExpiryUpdate(request.content.cid, requestEnd)).errorOption: if err =? (await onExpiryUpdate(request.content.cid, requestEnd)).errorOption:
return some State(SaleErrored(error: err)) return some State(SaleErrored(error: err))
when codex_enable_proof_failures: when storage_enable_proof_failures:
if context.simulateProofFailures > 0: if context.simulateProofFailures > 0:
info "Proving with failure rate", rate = context.simulateProofFailures info "Proving with failure rate", rate = context.simulateProofFailures
return some State( return some State(

View File

@ -61,7 +61,7 @@ method run*(
return some State(SaleIgnored(reprocessSlot: false)) return some State(SaleIgnored(reprocessSlot: false))
# TODO: Once implemented, check to ensure the host is allowed to fill the slot, # TODO: Once implemented, check to ensure the host is allowed to fill the slot,
# due to the [sliding window mechanism](https://github.com/codex-storage/codex-research/blob/master/design/marketplace.md#dispersal) # due to the [sliding window mechanism](https://github.com/logos-storage/logos-storage-research/blob/master/design/marketplace.md#dispersal)
logScope: logScope:
slotIndex = data.slotIndex slotIndex = data.slotIndex

View File

@ -1,5 +1,5 @@
import ../../conf import ../../conf
when codex_enable_proof_failures: when storage_enable_proof_failures:
import std/strutils import std/strutils
import pkg/stint import pkg/stint
import pkg/ethers import pkg/ethers

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2024 Status Research & Development GmbH ## Copyright (c) 2024 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2021 Status Research & Development GmbH ## Copyright (c) 2021 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2022 Status Research & Development GmbH ## Copyright (c) 2022 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2025 Status Research & Development GmbH ## Copyright (c) 2025 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,4 +1,4 @@
## Nim-Codex ## Logos Storage
## Copyright (c) 2023 Status Research & Development GmbH ## Copyright (c) 2023 Status Research & Development GmbH
## Licensed under either of ## Licensed under either of
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) ## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))

View File

@ -1,18 +1,18 @@
## Pre-requisite ## Pre-requisite
libcodex.so is needed to be compiled and present in build folder. libstorage.so is needed to be compiled and present in build folder.
## Compilation ## Compilation
From the codex root folder: From the Logos Storage root folder:
```code ```code
go build -o codex-go examples/golang/codex.go go build -o storage-go examples/golang/storage.go
``` ```
## Run ## Run
From the codex root folder: From the storage root folder:
```code ```code
@ -20,5 +20,5 @@ export LD_LIBRARY_PATH=build
``` ```
```code ```code
./codex-go ./storage-go
``` ```

View File

@ -1,12 +1,12 @@
package main package main
/* /*
#cgo LDFLAGS: -L../../build/ -lcodex #cgo LDFLAGS: -L../../build/ -lstorage
#cgo LDFLAGS: -L../../ -Wl,-rpath,../../ #cgo LDFLAGS: -L../../ -Wl,-rpath,../../
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "../../library/libcodex.h" #include "../../library/libstorage.h"
typedef struct { typedef struct {
int ret; int ret;
@ -35,83 +35,83 @@ package main
return m->ret; return m->ret;
} }
void libcodexNimMain(void); void libstorageNimMain(void);
static void codex_host_init_once(void){ static void storage_host_init_once(void){
static int done; static int done;
if (!__atomic_exchange_n(&done, 1, __ATOMIC_SEQ_CST)) libcodexNimMain(); if (!__atomic_exchange_n(&done, 1, __ATOMIC_SEQ_CST)) libstorageNimMain();
} }
// resp must be set != NULL in case interest on retrieving data from the callback // resp must be set != NULL in case interest on retrieving data from the callback
void callback(int ret, char* msg, size_t len, void* resp); void callback(int ret, char* msg, size_t len, void* resp);
static void* cGoCodexNew(const char* configJson, void* resp) { static void* cGoStorageNew(const char* configJson, void* resp) {
void* ret = codex_new(configJson, (CodexCallback) callback, resp); void* ret = storage_new(configJson, (StorageCallback) callback, resp);
return ret; return ret;
} }
static int cGoCodexStart(void* codexCtx, void* resp) { static int cGoStorageStart(void* storageCtx, void* resp) {
return codex_start(codexCtx, (CodexCallback) callback, resp); return storage_start(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexStop(void* codexCtx, void* resp) { static int cGoStorageStop(void* storageCtx, void* resp) {
return codex_stop(codexCtx, (CodexCallback) callback, resp); return storage_stop(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexClose(void* codexCtx, void* resp) { static int cGoStorageClose(void* storageCtx, void* resp) {
return codex_close(codexCtx, (CodexCallback) callback, resp); return storage_close(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexDestroy(void* codexCtx, void* resp) { static int cGoStorageDestroy(void* storageCtx, void* resp) {
return codex_destroy(codexCtx, (CodexCallback) callback, resp); return storage_destroy(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexVersion(void* codexCtx, void* resp) { static int cGoStorageVersion(void* storageCtx, void* resp) {
return codex_version(codexCtx, (CodexCallback) callback, resp); return storage_version(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexRevision(void* codexCtx, void* resp) { static int cGoStorageRevision(void* storageCtx, void* resp) {
return codex_revision(codexCtx, (CodexCallback) callback, resp); return storage_revision(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexRepo(void* codexCtx, void* resp) { static int cGoStorageRepo(void* storageCtx, void* resp) {
return codex_repo(codexCtx, (CodexCallback) callback, resp); return storage_repo(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexSpr(void* codexCtx, void* resp) { static int cGoStorageSpr(void* storageCtx, void* resp) {
return codex_spr(codexCtx, (CodexCallback) callback, resp); return storage_spr(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexPeerId(void* codexCtx, void* resp) { static int cGoStoragePeerId(void* storageCtx, void* resp) {
return codex_peer_id(codexCtx, (CodexCallback) callback, resp); return storage_peer_id(storageCtx, (StorageCallback) callback, resp);
} }
static int cGoCodexUploadInit(void* codexCtx, char* filepath, size_t chunkSize, void* resp) { static int cGoStorageUploadInit(void* storageCtx, char* filepath, size_t chunkSize, void* resp) {
return codex_upload_init(codexCtx, filepath, chunkSize, (CodexCallback) callback, resp); return storage_upload_init(storageCtx, filepath, chunkSize, (StorageCallback) callback, resp);
} }
static int cGoCodexUploadChunk(void* codexCtx, char* sessionId, const uint8_t* chunk, size_t len, void* resp) { static int cGoStorageUploadChunk(void* storageCtx, char* sessionId, const uint8_t* chunk, size_t len, void* resp) {
return codex_upload_chunk(codexCtx, sessionId, chunk, len, (CodexCallback) callback, resp); return storage_upload_chunk(storageCtx, sessionId, chunk, len, (StorageCallback) callback, resp);
} }
static int cGoCodexUploadFinalize(void* codexCtx, char* sessionId, void* resp) { static int cGoStorageUploadFinalize(void* storageCtx, char* sessionId, void* resp) {
return codex_upload_finalize(codexCtx, sessionId, (CodexCallback) callback, resp); return storage_upload_finalize(storageCtx, sessionId, (StorageCallback) callback, resp);
} }
static int cGoCodexUploadCancel(void* codexCtx, char* sessionId, void* resp) { static int cGoStorageUploadCancel(void* storageCtx, char* sessionId, void* resp) {
return codex_upload_cancel(codexCtx, sessionId, (CodexCallback) callback, resp); return storage_upload_cancel(storageCtx, sessionId, (StorageCallback) callback, resp);
} }
static int cGoCodexUploadFile(void* codexCtx, char* sessionId, void* resp) { static int cGoStorageUploadFile(void* storageCtx, char* sessionId, void* resp) {
return codex_upload_file(codexCtx, sessionId, (CodexCallback) callback, resp); return storage_upload_file(storageCtx, sessionId, (StorageCallback) callback, resp);
} }
static int cGoCodexLogLevel(void* codexCtx, char* logLevel, void* resp) { static int cGoStorageLogLevel(void* storageCtx, char* logLevel, void* resp) {
return codex_log_level(codexCtx, logLevel, (CodexCallback) callback, resp); return storage_log_level(storageCtx, logLevel, (StorageCallback) callback, resp);
} }
static int cGoCodexExists(void* codexCtx, char* cid, void* resp) { static int cGoStorageExists(void* storageCtx, char* cid, void* resp) {
return codex_storage_exists(codexCtx, cid, (CodexCallback) callback, resp); return storage_exists(storageCtx, cid, (StorageCallback) callback, resp);
} }
*/ */
import "C" import "C"
@ -169,11 +169,11 @@ type Config struct {
// Default: 8008 // Default: 8008
MetricsPort int `json:"metrics-port,omitempty"` MetricsPort int `json:"metrics-port,omitempty"`
// The directory where codex will store configuration and data // The directory where logos storage will store configuration and data
// Default: // Default:
// $HOME\AppData\Roaming\Codex on Windows // $HOME\AppData\Roaming\Logos Storage on Windows
// $HOME/Library/Application Support/Codex on macOS // $HOME/Library/Application Support/Logos Storage on macOS
// $HOME/.cache/codex on Linux // $HOME/.cache/logos_storage on Linux
DataDir string `json:"data-dir,omitempty"` DataDir string `json:"data-dir,omitempty"`
// Multi Addresses to listen on // Multi Addresses to listen on
@ -205,7 +205,7 @@ type Config struct {
NumThreads int `json:"num-threads,omitempty"` NumThreads int `json:"num-threads,omitempty"`
// Node agent string which is used as identifier in network // Node agent string which is used as identifier in network
// Default: "Codex" // Default: "Logos Storage"
AgentString string `json:"agent-string,omitempty"` AgentString string `json:"agent-string,omitempty"`
// Backend for main repo store (fs, sqlite, leveldb) // Backend for main repo store (fs, sqlite, leveldb)
@ -242,7 +242,7 @@ type Config struct {
LogFile string `json:"log-file,omitempty"` LogFile string `json:"log-file,omitempty"`
} }
type CodexNode struct { type StorageNode struct {
ctx unsafe.Pointer ctx unsafe.Pointer
} }
@ -383,7 +383,7 @@ type UploadOptions struct {
// It is used to detect the mimetype. // It is used to detect the mimetype.
Filepath string Filepath string
// ChunkSize is the size of each upload chunk, passed as `blockSize` to the Codex node // ChunkSize is the size of each upload chunk, passed as `blockSize` to the Logos Storage node
// store. Default is to 64 KB. // store. Default is to 64 KB.
ChunkSize ChunkSize ChunkSize ChunkSize
@ -416,12 +416,12 @@ func getReaderSize(r io.Reader) int64 {
} }
} }
// New creates a new Codex node with the provided configuration. // New creates a new Logos Storage node with the provided configuration.
// The node is not started automatically; you need to call CodexStart // The node is not started automatically; you need to call StorageStart
// to start it. // to start it.
// It returns a Codex node that can be used to interact // It returns a Logos Storage node that can be used to interact
// with the Codex network. // with the Logos Storage network.
func New(config Config) (*CodexNode, error) { func New(config Config) (*StorageNode, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
@ -433,22 +433,22 @@ func New(config Config) (*CodexNode, error) {
cJsonConfig := C.CString(string(jsonConfig)) cJsonConfig := C.CString(string(jsonConfig))
defer C.free(unsafe.Pointer(cJsonConfig)) defer C.free(unsafe.Pointer(cJsonConfig))
ctx := C.cGoCodexNew(cJsonConfig, bridge.resp) ctx := C.cGoStorageNew(cJsonConfig, bridge.resp)
if _, err := bridge.wait(); err != nil { if _, err := bridge.wait(); err != nil {
return nil, bridge.err return nil, bridge.err
} }
return &CodexNode{ctx: ctx}, bridge.err return &StorageNode{ctx: ctx}, bridge.err
} }
// Start starts the Codex node. // Start starts the Logos Storage node.
func (node CodexNode) Start() error { func (node StorageNode) Start() error {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexStart(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageStart(node.ctx, bridge.resp) != C.RET_OK {
return bridge.callError("cGoCodexStart") return bridge.callError("cGoStorageStart")
} }
_, err := bridge.wait() _, err := bridge.wait()
@ -456,34 +456,34 @@ func (node CodexNode) Start() error {
} }
// StartAsync is the asynchronous version of Start. // StartAsync is the asynchronous version of Start.
func (node CodexNode) StartAsync(onDone func(error)) { func (node StorageNode) StartAsync(onDone func(error)) {
go func() { go func() {
err := node.Start() err := node.Start()
onDone(err) onDone(err)
}() }()
} }
// Stop stops the Codex node. // Stop stops the Logos Storage node.
func (node CodexNode) Stop() error { func (node StorageNode) Stop() error {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexStop(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageStop(node.ctx, bridge.resp) != C.RET_OK {
return bridge.callError("cGoCodexStop") return bridge.callError("cGoStorageStop")
} }
_, err := bridge.wait() _, err := bridge.wait()
return err return err
} }
// Destroy destroys the Codex node, freeing all resources. // Destroy destroys the Logos Storage node, freeing all resources.
// The node must be stopped before calling this method. // The node must be stopped before calling this method.
func (node CodexNode) Destroy() error { func (node StorageNode) Destroy() error {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexClose(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageClose(node.ctx, bridge.resp) != C.RET_OK {
return bridge.callError("cGoCodexClose") return bridge.callError("cGoStorageClose")
} }
_, err := bridge.wait() _, err := bridge.wait()
@ -491,65 +491,65 @@ func (node CodexNode) Destroy() error {
return err return err
} }
if C.cGoCodexDestroy(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageDestroy(node.ctx, bridge.resp) != C.RET_OK {
return errors.New("Failed to destroy the codex node.") return errors.New("Failed to destroy the Logos Storage node.")
} }
return err return err
} }
// Version returns the version of the Codex node. // Version returns the version of the Logos Storage node.
func (node CodexNode) Version() (string, error) { func (node StorageNode) Version() (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexVersion(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageVersion(node.ctx, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexVersion") return "", bridge.callError("cGoStorageVersion")
} }
return bridge.wait() return bridge.wait()
} }
func (node CodexNode) Revision() (string, error) { func (node StorageNode) Revision() (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexRevision(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageRevision(node.ctx, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexRevision") return "", bridge.callError("cGoStorageRevision")
} }
return bridge.wait() return bridge.wait()
} }
// Repo returns the path of the data dir folder. // Repo returns the path of the data dir folder.
func (node CodexNode) Repo() (string, error) { func (node StorageNode) Repo() (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexRepo(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageRepo(node.ctx, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexRepo") return "", bridge.callError("cGoStorageRepo")
} }
return bridge.wait() return bridge.wait()
} }
func (node CodexNode) Spr() (string, error) { func (node StorageNode) Spr() (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexSpr(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStorageSpr(node.ctx, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexSpr") return "", bridge.callError("cGoStorageSpr")
} }
return bridge.wait() return bridge.wait()
} }
func (node CodexNode) PeerId() (string, error) { func (node StorageNode) PeerId() (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
if C.cGoCodexPeerId(node.ctx, bridge.resp) != C.RET_OK { if C.cGoStoragePeerId(node.ctx, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexPeerId") return "", bridge.callError("cGoStoragePeerId")
} }
return bridge.wait() return bridge.wait()
@ -559,26 +559,26 @@ func (node CodexNode) PeerId() (string, error) {
// It returns a session ID that can be used for subsequent upload operations. // It returns a session ID that can be used for subsequent upload operations.
// This function is called by UploadReader and UploadFile internally. // This function is called by UploadReader and UploadFile internally.
// You should use this function only if you need to manage the upload session manually. // You should use this function only if you need to manage the upload session manually.
func (node CodexNode) UploadInit(options *UploadOptions) (string, error) { func (node StorageNode) UploadInit(options *UploadOptions) (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
var cFilename = C.CString(options.Filepath) var cFilename = C.CString(options.Filepath)
defer C.free(unsafe.Pointer(cFilename)) defer C.free(unsafe.Pointer(cFilename))
if C.cGoCodexUploadInit(node.ctx, cFilename, options.ChunkSize.toSizeT(), bridge.resp) != C.RET_OK { if C.cGoStorageUploadInit(node.ctx, cFilename, options.ChunkSize.toSizeT(), bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexUploadInit") return "", bridge.callError("cGoStorageUploadInit")
} }
return bridge.wait() return bridge.wait()
} }
// UploadChunk uploads a chunk of data to the Codex node. // UploadChunk uploads a chunk of data to the Logos Storage node.
// It takes the session ID returned by UploadInit // It takes the session ID returned by UploadInit
// and a byte slice containing the chunk data. // and a byte slice containing the chunk data.
// This function is called by UploadReader internally. // This function is called by UploadReader internally.
// You should use this function only if you need to manage the upload session manually. // You should use this function only if you need to manage the upload session manually.
func (node CodexNode) UploadChunk(sessionId string, chunk []byte) error { func (node StorageNode) UploadChunk(sessionId string, chunk []byte) error {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
@ -590,8 +590,8 @@ func (node CodexNode) UploadChunk(sessionId string, chunk []byte) error {
cChunkPtr = (*C.uint8_t)(unsafe.Pointer(&chunk[0])) cChunkPtr = (*C.uint8_t)(unsafe.Pointer(&chunk[0]))
} }
if C.cGoCodexUploadChunk(node.ctx, cSessionId, cChunkPtr, C.size_t(len(chunk)), bridge.resp) != C.RET_OK { if C.cGoStorageUploadChunk(node.ctx, cSessionId, cChunkPtr, C.size_t(len(chunk)), bridge.resp) != C.RET_OK {
return bridge.callError("cGoCodexUploadChunk") return bridge.callError("cGoStorageUploadChunk")
} }
_, err := bridge.wait() _, err := bridge.wait()
@ -602,15 +602,15 @@ func (node CodexNode) UploadChunk(sessionId string, chunk []byte) error {
// It takes the session ID returned by UploadInit. // It takes the session ID returned by UploadInit.
// This function is called by UploadReader and UploadFile internally. // This function is called by UploadReader and UploadFile internally.
// You should use this function only if you need to manage the upload session manually. // You should use this function only if you need to manage the upload session manually.
func (node CodexNode) UploadFinalize(sessionId string) (string, error) { func (node StorageNode) UploadFinalize(sessionId string) (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
var cSessionId = C.CString(sessionId) var cSessionId = C.CString(sessionId)
defer C.free(unsafe.Pointer(cSessionId)) defer C.free(unsafe.Pointer(cSessionId))
if C.cGoCodexUploadFinalize(node.ctx, cSessionId, bridge.resp) != C.RET_OK { if C.cGoStorageUploadFinalize(node.ctx, cSessionId, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexUploadFinalize") return "", bridge.callError("cGoStorageUploadFinalize")
} }
return bridge.wait() return bridge.wait()
@ -619,31 +619,31 @@ func (node CodexNode) UploadFinalize(sessionId string) (string, error) {
// UploadCancel cancels an ongoing upload session. // UploadCancel cancels an ongoing upload session.
// It can be only if the upload session is managed manually. // It can be only if the upload session is managed manually.
// It doesn't work with UploadFile. // It doesn't work with UploadFile.
func (node CodexNode) UploadCancel(sessionId string) error { func (node StorageNode) UploadCancel(sessionId string) error {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
var cSessionId = C.CString(sessionId) var cSessionId = C.CString(sessionId)
defer C.free(unsafe.Pointer(cSessionId)) defer C.free(unsafe.Pointer(cSessionId))
if C.cGoCodexUploadCancel(node.ctx, cSessionId, bridge.resp) != C.RET_OK { if C.cGoStorageUploadCancel(node.ctx, cSessionId, bridge.resp) != C.RET_OK {
return bridge.callError("cGoCodexUploadCancel") return bridge.callError("cGoStorageUploadCancel")
} }
_, err := bridge.wait() _, err := bridge.wait()
return err return err
} }
// UploadReader uploads data from an io.Reader to the Codex node. // UploadReader uploads data from an io.Reader to the Logos Storage node.
// It takes the upload options and the reader as parameters. // It takes the upload options and the reader as parameters.
// It returns the CID of the uploaded file or an error. // It returns the CID of the uploaded file or an error.
// //
// Internally, it calls: // Internally, it calls:
// - UploadInit to create the upload session. // - UploadInit to create the upload session.
// - UploadChunk to upload a chunk to codex. // - UploadChunk to upload a chunk to Logos Storage.
// - UploadFinalize to finalize the upload session. // - UploadFinalize to finalize the upload session.
// - UploadCancel if an error occurs. // - UploadCancel if an error occurs.
func (node CodexNode) UploadReader(options UploadOptions, r io.Reader) (string, error) { func (node StorageNode) UploadReader(options UploadOptions, r io.Reader) (string, error) {
sessionId, err := node.UploadInit(&options) sessionId, err := node.UploadInit(&options)
if err != nil { if err != nil {
return "", err return "", err
@ -701,20 +701,20 @@ func (node CodexNode) UploadReader(options UploadOptions, r io.Reader) (string,
} }
// UploadReaderAsync is the asynchronous version of UploadReader using a goroutine. // UploadReaderAsync is the asynchronous version of UploadReader using a goroutine.
func (node CodexNode) UploadReaderAsync(options UploadOptions, r io.Reader, onDone func(cid string, err error)) { func (node StorageNode) UploadReaderAsync(options UploadOptions, r io.Reader, onDone func(cid string, err error)) {
go func() { go func() {
cid, err := node.UploadReader(options, r) cid, err := node.UploadReader(options, r)
onDone(cid, err) onDone(cid, err)
}() }()
} }
// UploadFile uploads a file to the Codex node. // UploadFile uploads a file to the Logos Storage node.
// It takes the upload options as parameter. // It takes the upload options as parameter.
// It returns the CID of the uploaded file or an error. // It returns the CID of the uploaded file or an error.
// //
// The options parameter contains the following fields: // The options parameter contains the following fields:
// - filepath: the full path of the file to upload. // - filepath: the full path of the file to upload.
// - chunkSize: the size of each upload chunk, passed as `blockSize` to the Codex node // - chunkSize: the size of each upload chunk, passed as `blockSize` to the Logos Storage node
// store. Default is to 64 KB. // store. Default is to 64 KB.
// - onProgress: a callback function that is called after each chunk is uploaded with: // - onProgress: a callback function that is called after each chunk is uploaded with:
// - read: the number of bytes read in the last chunk. // - read: the number of bytes read in the last chunk.
@ -728,7 +728,7 @@ func (node CodexNode) UploadReaderAsync(options UploadOptions, r io.Reader, onDo
// is sent to the stream. // is sent to the stream.
// //
// Internally, it calls UploadInit to create the upload session. // Internally, it calls UploadInit to create the upload session.
func (node CodexNode) UploadFile(options UploadOptions) (string, error) { func (node StorageNode) UploadFile(options UploadOptions) (string, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
@ -768,45 +768,45 @@ func (node CodexNode) UploadFile(options UploadOptions) (string, error) {
var cSessionId = C.CString(sessionId) var cSessionId = C.CString(sessionId)
defer C.free(unsafe.Pointer(cSessionId)) defer C.free(unsafe.Pointer(cSessionId))
if C.cGoCodexUploadFile(node.ctx, cSessionId, bridge.resp) != C.RET_OK { if C.cGoStorageUploadFile(node.ctx, cSessionId, bridge.resp) != C.RET_OK {
return "", bridge.callError("cGoCodexUploadFile") return "", bridge.callError("cGoStorageUploadFile")
} }
return bridge.wait() return bridge.wait()
} }
// UploadFileAsync is the asynchronous version of UploadFile using a goroutine. // UploadFileAsync is the asynchronous version of UploadFile using a goroutine.
func (node CodexNode) UploadFileAsync(options UploadOptions, onDone func(cid string, err error)) { func (node StorageNode) UploadFileAsync(options UploadOptions, onDone func(cid string, err error)) {
go func() { go func() {
cid, err := node.UploadFile(options) cid, err := node.UploadFile(options)
onDone(cid, err) onDone(cid, err)
}() }()
} }
func (node CodexNode) UpdateLogLevel(logLevel string) error { func (node StorageNode) UpdateLogLevel(logLevel string) error {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
var cLogLevel = C.CString(string(logLevel)) var cLogLevel = C.CString(string(logLevel))
defer C.free(unsafe.Pointer(cLogLevel)) defer C.free(unsafe.Pointer(cLogLevel))
if C.cGoCodexLogLevel(node.ctx, cLogLevel, bridge.resp) != C.RET_OK { if C.cGoStorageLogLevel(node.ctx, cLogLevel, bridge.resp) != C.RET_OK {
return bridge.callError("cGoCodexLogLevel") return bridge.callError("cGoStorageLogLevel")
} }
_, err := bridge.wait() _, err := bridge.wait()
return err return err
} }
func (node CodexNode) Exists(cid string) (bool, error) { func (node StorageNode) Exists(cid string) (bool, error) {
bridge := newBridgeCtx() bridge := newBridgeCtx()
defer bridge.free() defer bridge.free()
var cCid = C.CString(cid) var cCid = C.CString(cid)
defer C.free(unsafe.Pointer(cCid)) defer C.free(unsafe.Pointer(cCid))
if C.cGoCodexExists(node.ctx, cCid, bridge.resp) != C.RET_OK { if C.cGoStorageExists(node.ctx, cCid, bridge.resp) != C.RET_OK {
return false, bridge.callError("cGoCodexUploadCancel") return false, bridge.callError("cGoStorageUploadCancel")
} }
result, err := bridge.wait() result, err := bridge.wait()
@ -822,20 +822,20 @@ func main() {
DataDir: dataDir, DataDir: dataDir,
}) })
if err != nil { if err != nil {
log.Fatalf("Failed to create Codex node: %v", err) log.Fatalf("Failed to create Logos Storage node: %v", err)
} }
defer os.RemoveAll(dataDir) defer os.RemoveAll(dataDir)
if err := node.Start(); err != nil { if err := node.Start(); err != nil {
log.Fatalf("Failed to start Codex node: %v", err) log.Fatalf("Failed to start Logos Storage node: %v", err)
} }
log.Println("Codex node started") log.Println("Logos Storage node started")
version, err := node.Version() version, err := node.Version()
if err != nil { if err != nil {
log.Fatalf("Failed to get Codex version: %v", err) log.Fatalf("Failed to get Logos Storage version: %v", err)
} }
log.Printf("Codex version: %s", version) log.Printf("Logos Storage version: %s", version)
err = node.UpdateLogLevel("ERROR") err = node.UpdateLogLevel("ERROR")
if err != nil { if err != nil {
@ -875,11 +875,11 @@ func main() {
<-ch <-ch
if err := node.Stop(); err != nil { if err := node.Stop(); err != nil {
log.Fatalf("Failed to stop Codex node: %v", err) log.Fatalf("Failed to stop Storage node: %v", err)
} }
log.Println("Codex node stopped") log.Println("Logos Storage node stopped")
if err := node.Destroy(); err != nil { if err := node.Destroy(); err != nil {
log.Fatalf("Failed to destroy Codex node: %v", err) log.Fatalf("Failed to destroy Logos Storage node: %v", err)
} }
} }

4
flake.lock generated
View File

@ -9,13 +9,13 @@
"locked": { "locked": {
"lastModified": 1736521871, "lastModified": 1736521871,
"narHash": "sha256-d34XNLg9NGPEOARHW+BIOAWalkHdEUAwsv3mpLZQxds=", "narHash": "sha256-d34XNLg9NGPEOARHW+BIOAWalkHdEUAwsv3mpLZQxds=",
"owner": "codex-storage", "owner": "logos-storage",
"repo": "circom-compat-ffi", "repo": "circom-compat-ffi",
"rev": "8cd4ed44fdafe59d4ec1184420639cae4c4dbab9", "rev": "8cd4ed44fdafe59d4ec1184420639cae4c4dbab9",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "codex-storage", "owner": "logos-storage",
"repo": "circom-compat-ffi", "repo": "circom-compat-ffi",
"type": "github" "type": "github"
} }

View File

@ -1,10 +1,10 @@
{ {
description = "Nim Codex build flake"; description = "Logos Storage build flake";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
circom-compat = { circom-compat = {
url = "github:codex-storage/circom-compat-ffi"; url = "github:logos-storage/circom-compat-ffi";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
@ -68,7 +68,7 @@
machine.start() machine.start()
machine.wait_for_unit("nim-codex.service") machine.wait_for_unit("nim-codex.service")
machine.succeed("test -d /var/lib/nim-codex-test") machine.succeed("test -d /var/lib/nim-codex-test")
machine.wait_until_succeeds("journalctl -u nim-codex.service | grep 'Started codex node'", 10) machine.wait_until_succeeds("journalctl -u nim-codex.service | grep 'Started Storage node'", 10)
''; '';
}; };
}); });

View File

@ -1,6 +1,6 @@
# Codex Library # Logos Storage Library
Codex exposes a C binding that serves as a stable contract, making it straightforward to integrate Codex into other languages such as Go. Logos Storage exposes a C binding that serves as a stable contract, making it straightforward to integrate Logos Storage into other languages such as Go.
The implementation was inspired by [nim-library-template](https://github.com/logos-co/nim-library-template) The implementation was inspired by [nim-library-template](https://github.com/logos-co/nim-library-template)
and by the [nwaku](https://github.com/waku-org/nwaku/tree/master/library) library. and by the [nwaku](https://github.com/waku-org/nwaku/tree/master/library) library.
@ -13,13 +13,13 @@ sequenceDiagram
autonumber autonumber
actor App as App/User actor App as App/User
participant Go as Go Wrapper participant Go as Go Wrapper
participant C as C API (libcodex.h) participant C as C API (libstorage.h)
participant Ctx as CodexContext participant Ctx as StorageContext
participant Thr as Worker Thread participant Thr as Worker Thread
participant Eng as CodexServer participant Eng as CodexServer
App->>Go: Start App->>Go: Start
Go->>C: codex_start_node Go->>C: storage_start_node
C->>Ctx: enqueue request C->>Ctx: enqueue request
C->>Ctx: fire signal C->>Ctx: fire signal
Ctx->>Thr: wake worker Ctx->>Thr: wake worker

View File

@ -7,7 +7,7 @@
### Exported types ### Exported types
import results import results
type CodexCallback* = proc( type StorageCallback* = proc(
callerRet: cint, msg: ptr cchar, len: csize_t, userData: pointer callerRet: cint, msg: ptr cchar, len: csize_t, userData: pointer
) {.cdecl, gcsafe, raises: [].} ) {.cdecl, gcsafe, raises: [].}
@ -18,15 +18,15 @@ const RET_PROGRESS*: cint = 3
## Returns RET_OK as acknowledgment and call the callback ## Returns RET_OK as acknowledgment and call the callback
## with RET_OK code and the provided message. ## with RET_OK code and the provided message.
proc success*(callback: CodexCallback, msg: string, userData: pointer): cint = proc success*(callback: StorageCallback, msg: string, userData: pointer): cint =
callback(RET_OK, cast[ptr cchar](msg), cast[csize_t](len(msg)), userData) callback(RET_OK, cast[ptr cchar](msg), cast[csize_t](len(msg)), userData)
return RET_OK return RET_OK
## Returns RET_ERR as acknowledgment and call the callback ## Returns RET_ERR as acknowledgment and call the callback
## with RET_ERR code and the provided message. ## with RET_ERR code and the provided message.
proc error*(callback: CodexCallback, msg: string, userData: pointer): cint = proc error*(callback: StorageCallback, msg: string, userData: pointer): cint =
let msg = "libcodex error: " & msg let msg = "libstorage error: " & msg
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData) callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
return RET_ERR return RET_ERR
@ -34,7 +34,7 @@ proc error*(callback: CodexCallback, msg: string, userData: pointer): cint =
## Returns RET_OK as acknowledgment if the result is ok. ## Returns RET_OK as acknowledgment if the result is ok.
## If not, return RET_ERR and call the callback with the error message. ## If not, return RET_ERR and call the callback with the error message.
proc okOrError*[T]( proc okOrError*[T](
callback: CodexCallback, res: Result[T, string], userData: pointer callback: StorageCallback, res: Result[T, string], userData: pointer
): cint = ): cint =
if res.isOk: if res.isOk:
return RET_OK return RET_OK

View File

@ -1,15 +1,15 @@
/** /**
* libcodex.h - C Interface for Example Library * libstorage.h - C Interface for Example Library
* *
* This header provides the public API for libcodex * This header provides the public API for libstorage
* *
* To see the auto-generated header by Nim, run `make libcodex` from the * To see the auto-generated header by Nim, run `make libstorage` from the
* repository root. The generated file will be created at: * repository root. The generated file will be created at:
* nimcache/release/libcodex/libcodex.h * nimcache/release/libstorage/libstorage.h
*/ */
#ifndef __libcodex__ #ifndef __libstorage__
#define __libcodex__ #define __libstorage__
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -24,183 +24,183 @@
extern "C" { extern "C" {
#endif #endif
typedef void (*CodexCallback) (int callerRet, const char* msg, size_t len, void* userData); typedef void (*StorageCallback) (int callerRet, const char* msg, size_t len, void* userData);
void* codex_new( void* storage_new(
const char* configJson, const char* configJson,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_version( int storage_version(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_revision( int storage_revision(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_repo( int storage_repo(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_debug( int storage_debug(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_spr( int storage_spr(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_peer_id( int storage_peer_id(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_log_level( int storage_log_level(
void* ctx, void* ctx,
const char* logLevel, const char* logLevel,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_connect( int storage_connect(
void* ctx, void* ctx,
const char* peerId, const char* peerId,
const char** peerAddresses, const char** peerAddresses,
size_t peerAddressesSize, size_t peerAddressesSize,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_peer_debug( int storage_peer_debug(
void* ctx, void* ctx,
const char* peerId, const char* peerId,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_upload_init( int storage_upload_init(
void* ctx, void* ctx,
const char* filepath, const char* filepath,
size_t chunkSize, size_t chunkSize,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_upload_chunk( int storage_upload_chunk(
void* ctx, void* ctx,
const char* sessionId, const char* sessionId,
const uint8_t* chunk, const uint8_t* chunk,
size_t len, size_t len,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_upload_finalize( int storage_upload_finalize(
void* ctx, void* ctx,
const char* sessionId, const char* sessionId,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_upload_cancel( int storage_upload_cancel(
void* ctx, void* ctx,
const char* sessionId, const char* sessionId,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_upload_file( int storage_upload_file(
void* ctx, void* ctx,
const char* sessionId, const char* sessionId,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_download_stream( int storage_download_stream(
void* ctx, void* ctx,
const char* cid, const char* cid,
size_t chunkSize, size_t chunkSize,
bool local, bool local,
const char* filepath, const char* filepath,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_download_init( int storage_download_init(
void* ctx, void* ctx,
const char* cid, const char* cid,
size_t chunkSize, size_t chunkSize,
bool local, bool local,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_download_chunk( int storage_download_chunk(
void* ctx, void* ctx,
const char* cid, const char* cid,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_download_cancel( int storage_download_cancel(
void* ctx, void* ctx,
const char* cid, const char* cid,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_download_manifest( int storage_download_manifest(
void* ctx, void* ctx,
const char* cid, const char* cid,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_storage_list( int storage_list(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_storage_space( int storage_space(
void* ctx, void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_storage_delete( int storage_delete(
void* ctx, void* ctx,
const char* cid, const char* cid,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_storage_fetch( int storage_fetch(
void* ctx, void* ctx,
const char* cid, const char* cid,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_storage_exists( int storage_exists(
void* ctx, void* ctx,
const char* cid, const char* cid,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_start(void* ctx, int storage_start(void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_stop(void* ctx, int storage_stop(void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
int codex_close(void* ctx, int storage_close(void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
// Destroys an instance of a codex node created with codex_new // Destroys an instance of a Logos Storage node created with storage_new
int codex_destroy(void* ctx, int storage_destroy(void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
void codex_set_event_callback(void* ctx, void storage_set_event_callback(void* ctx,
CodexCallback callback, StorageCallback callback,
void* userData); void* userData);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __libcodex__ */ #endif /* __libstorage__ */

View File

@ -1,6 +1,6 @@
# libcodex.nim - C-exported interface for the Codex shared library # libstorage.nim - C-exported interface for the Storage shared library
# #
# This file implements the public C API for libcodex. # This file implements the public C API for libstorage.
# It acts as the bridge between C programs and the internal Nim implementation. # It acts as the bridge between C programs and the internal Nim implementation.
# #
# This file defines: # This file defines:
@ -22,30 +22,30 @@
when defined(linux): when defined(linux):
# Define the canonical name for this library # Define the canonical name for this library
{.passl: "-Wl,-soname,libcodex.so".} {.passl: "-Wl,-soname,libstorage.so".}
import std/[atomics] import std/[atomics]
import chronicles import chronicles
import chronos import chronos
import chronos/threadsync import chronos/threadsync
import ./codex_context import ./storage_context
import ./codex_thread_requests/codex_thread_request import ./storage_thread_requests/storage_thread_request
import ./codex_thread_requests/requests/node_lifecycle_request import ./storage_thread_requests/requests/node_lifecycle_request
import ./codex_thread_requests/requests/node_info_request import ./storage_thread_requests/requests/node_info_request
import ./codex_thread_requests/requests/node_debug_request import ./storage_thread_requests/requests/node_debug_request
import ./codex_thread_requests/requests/node_p2p_request import ./storage_thread_requests/requests/node_p2p_request
import ./codex_thread_requests/requests/node_upload_request import ./storage_thread_requests/requests/node_upload_request
import ./codex_thread_requests/requests/node_download_request import ./storage_thread_requests/requests/node_download_request
import ./codex_thread_requests/requests/node_storage_request import ./storage_thread_requests/requests/node_storage_request
import ./ffi_types import ./ffi_types
from ../codex/conf import codexVersion from ../codex/conf import codexVersion
logScope: logScope:
topics = "codexlib" topics = "libstorage"
template checkLibcodexParams*( template checkLibstorageParams*(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
) = ) =
if not isNil(ctx): if not isNil(ctx):
ctx[].userData = userData ctx[].userData = userData
@ -57,7 +57,7 @@ template checkLibcodexParams*(
# "the C targets require you to initialize Nim's internals, which is done calling a NimMain function." # "the C targets require you to initialize Nim's internals, which is done calling a NimMain function."
# "The name NimMain can be influenced via the --nimMainPrefix:prefix switch." # "The name NimMain can be influenced via the --nimMainPrefix:prefix switch."
# "Use --nimMainPrefix:MyLib and the function to call is named MyLibNimMain." # "Use --nimMainPrefix:MyLib and the function to call is named MyLibNimMain."
proc libcodexNimMain() {.importc.} proc libstorageNimMain() {.importc.}
# Atomic flag to prevent multiple initializations # Atomic flag to prevent multiple initializations
var initialized: Atomic[bool] var initialized: Atomic[bool]
@ -74,7 +74,7 @@ if defined(android):
proc initializeLibrary() {.exported.} = proc initializeLibrary() {.exported.} =
if not initialized.exchange(true): if not initialized.exchange(true):
## Every Nim library must call `<prefix>NimMain()` once ## Every Nim library must call `<prefix>NimMain()` once
libcodexNimMain() libstorageNimMain()
when declared(setupForeignThreadGc): when declared(setupForeignThreadGc):
setupForeignThreadGc() setupForeignThreadGc()
when declared(nimGC_setStackBottom): when declared(nimGC_setStackBottom):
@ -82,16 +82,16 @@ proc initializeLibrary() {.exported.} =
locals = addr(locals) locals = addr(locals)
nimGC_setStackBottom(locals) nimGC_setStackBottom(locals)
proc codex_new( proc storage_new(
configJson: cstring, callback: CodexCallback, userData: pointer configJson: cstring, callback: StorageCallback, userData: pointer
): pointer {.dynlib, exported.} = ): pointer {.dynlib, exported.} =
initializeLibrary() initializeLibrary()
if isNil(callback): if isNil(callback):
error "Failed to create codex instance: the callback is missing." error "Failed to create Storage instance: the callback is missing."
return nil return nil
var ctx = codex_context.createCodexContext().valueOr: var ctx = storage_context.createStorageContext().valueOr:
let msg = $error let msg = $error
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData) callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
return nil return nil
@ -101,7 +101,7 @@ proc codex_new(
let reqContent = let reqContent =
NodeLifecycleRequest.createShared(NodeLifecycleMsgType.CREATE_NODE, configJson) NodeLifecycleRequest.createShared(NodeLifecycleMsgType.CREATE_NODE, configJson)
codex_context.sendRequestToCodexThread( storage_context.sendRequestToStorageThread(
ctx, RequestType.LIFECYCLE, reqContent, callback, userData ctx, RequestType.LIFECYCLE, reqContent, callback, userData
).isOkOr: ).isOkOr:
let msg = $error let msg = $error
@ -110,11 +110,11 @@ proc codex_new(
return ctx return ctx
proc codex_version( proc storage_version(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
callback( callback(
RET_OK, RET_OK,
@ -125,11 +125,11 @@ proc codex_version(
return RET_OK return RET_OK
proc codex_revision( proc storage_revision(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
callback( callback(
RET_OK, RET_OK,
@ -140,53 +140,53 @@ proc codex_revision(
return RET_OK return RET_OK
proc codex_repo( proc storage_repo(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeInfoRequest.createShared(NodeInfoMsgType.REPO) let reqContent = NodeInfoRequest.createShared(NodeInfoMsgType.REPO)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.INFO, reqContent, callback, userData ctx, RequestType.INFO, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_debug( proc storage_debug(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeDebugRequest.createShared(NodeDebugMsgType.DEBUG) let reqContent = NodeDebugRequest.createShared(NodeDebugMsgType.DEBUG)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DEBUG, reqContent, callback, userData ctx, RequestType.DEBUG, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_spr( proc storage_spr(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeInfoRequest.createShared(NodeInfoMsgType.SPR) let reqContent = NodeInfoRequest.createShared(NodeInfoMsgType.SPR)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.INFO, reqContent, callback, userData ctx, RequestType.INFO, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_peer_id( proc storage_peer_id(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeInfoRequest.createShared(NodeInfoMsgType.PEERID) let reqContent = NodeInfoRequest.createShared(NodeInfoMsgType.PEERID)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.INFO, reqContent, callback, userData ctx, RequestType.INFO, reqContent, callback, userData
) )
@ -195,30 +195,33 @@ proc codex_peer_id(
## Set the log level of the library at runtime. ## Set the log level of the library at runtime.
## It uses updateLogLevel which is a synchronous proc and ## It uses updateLogLevel which is a synchronous proc and
## cannot be used inside an async context because of gcsafe issue. ## cannot be used inside an async context because of gcsafe issue.
proc codex_log_level( proc storage_log_level(
ctx: ptr CodexContext, logLevel: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext,
logLevel: cstring,
callback: StorageCallback,
userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = let reqContent =
NodeDebugRequest.createShared(NodeDebugMsgType.LOG_LEVEL, logLevel = logLevel) NodeDebugRequest.createShared(NodeDebugMsgType.LOG_LEVEL, logLevel = logLevel)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DEBUG, reqContent, callback, userData ctx, RequestType.DEBUG, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_connect( proc storage_connect(
ctx: ptr CodexContext, ctx: ptr StorageContext,
peerId: cstring, peerId: cstring,
peerAddressesPtr: ptr cstring, peerAddressesPtr: ptr cstring,
peerAddressesLength: csize_t, peerAddressesLength: csize_t,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
var peerAddresses = newSeq[cstring](peerAddressesLength) var peerAddresses = newSeq[cstring](peerAddressesLength)
let peers = cast[ptr UncheckedArray[cstring]](peerAddressesPtr) let peers = cast[ptr UncheckedArray[cstring]](peerAddressesPtr)
@ -228,33 +231,36 @@ proc codex_connect(
let reqContent = NodeP2PRequest.createShared( let reqContent = NodeP2PRequest.createShared(
NodeP2PMsgType.CONNECT, peerId = peerId, peerAddresses = peerAddresses NodeP2PMsgType.CONNECT, peerId = peerId, peerAddresses = peerAddresses
) )
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.P2P, reqContent, callback, userData ctx, RequestType.P2P, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_peer_debug( proc storage_peer_debug(
ctx: ptr CodexContext, peerId: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext,
peerId: cstring,
callback: StorageCallback,
userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeDebugRequest.createShared(NodeDebugMsgType.PEER, peerId = peerId) let reqContent = NodeDebugRequest.createShared(NodeDebugMsgType.PEER, peerId = peerId)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DEBUG, reqContent, callback, userData ctx, RequestType.DEBUG, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_close( proc storage_close(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeLifecycleRequest.createShared(NodeLifecycleMsgType.CLOSE_NODE) let reqContent = NodeLifecycleRequest.createShared(NodeLifecycleMsgType.CLOSE_NODE)
var res = codex_context.sendRequestToCodexThread( var res = storage_context.sendRequestToStorageThread(
ctx, RequestType.LIFECYCLE, reqContent, callback, userData ctx, RequestType.LIFECYCLE, reqContent, callback, userData
) )
if res.isErr: if res.isErr:
@ -262,48 +268,48 @@ proc codex_close(
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_destroy( proc storage_destroy(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let res = codex_context.destroyCodexContext(ctx) let res = storage_context.destroyStorageContext(ctx)
if res.isErr: if res.isErr:
return RET_ERR return RET_ERR
return RET_OK return RET_OK
proc codex_upload_init( proc storage_upload_init(
ctx: ptr CodexContext, ctx: ptr StorageContext,
filepath: cstring, filepath: cstring,
chunkSize: csize_t, chunkSize: csize_t,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = NodeUploadRequest.createShared( let reqContent = NodeUploadRequest.createShared(
NodeUploadMsgType.INIT, filepath = filepath, chunkSize = chunkSize NodeUploadMsgType.INIT, filepath = filepath, chunkSize = chunkSize
) )
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.UPLOAD, reqContent, callback, userData ctx, RequestType.UPLOAD, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_upload_chunk( proc storage_upload_chunk(
ctx: ptr CodexContext, ctx: ptr StorageContext,
sessionId: cstring, sessionId: cstring,
data: ptr byte, data: ptr byte,
len: csize_t, len: csize_t,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let chunk = newSeq[byte](len) let chunk = newSeq[byte](len)
copyMem(addr chunk[0], data, len) copyMem(addr chunk[0], data, len)
@ -311,111 +317,111 @@ proc codex_upload_chunk(
let reqContent = NodeUploadRequest.createShared( let reqContent = NodeUploadRequest.createShared(
NodeUploadMsgType.CHUNK, sessionId = sessionId, chunk = chunk NodeUploadMsgType.CHUNK, sessionId = sessionId, chunk = chunk
) )
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.UPLOAD, reqContent, callback, userData ctx, RequestType.UPLOAD, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_upload_finalize( proc storage_upload_finalize(
ctx: ptr CodexContext, ctx: ptr StorageContext,
sessionId: cstring, sessionId: cstring,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = let reqContent =
NodeUploadRequest.createShared(NodeUploadMsgType.FINALIZE, sessionId = sessionId) NodeUploadRequest.createShared(NodeUploadMsgType.FINALIZE, sessionId = sessionId)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.UPLOAD, reqContent, callback, userData ctx, RequestType.UPLOAD, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_upload_cancel( proc storage_upload_cancel(
ctx: ptr CodexContext, ctx: ptr StorageContext,
sessionId: cstring, sessionId: cstring,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = let reqContent =
NodeUploadRequest.createShared(NodeUploadMsgType.CANCEL, sessionId = sessionId) NodeUploadRequest.createShared(NodeUploadMsgType.CANCEL, sessionId = sessionId)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.UPLOAD, reqContent, callback, userData ctx, RequestType.UPLOAD, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_upload_file( proc storage_upload_file(
ctx: ptr CodexContext, ctx: ptr StorageContext,
sessionId: cstring, sessionId: cstring,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent = let reqContent =
NodeUploadRequest.createShared(NodeUploadMsgType.FILE, sessionId = sessionId) NodeUploadRequest.createShared(NodeUploadMsgType.FILE, sessionId = sessionId)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.UPLOAD, reqContent, callback, userData ctx, RequestType.UPLOAD, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_download_init( proc storage_download_init(
ctx: ptr CodexContext, ctx: ptr StorageContext,
cid: cstring, cid: cstring,
chunkSize: csize_t, chunkSize: csize_t,
local: bool, local: bool,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeDownloadRequest.createShared( let req = NodeDownloadRequest.createShared(
NodeDownloadMsgType.INIT, cid = cid, chunkSize = chunkSize, local = local NodeDownloadMsgType.INIT, cid = cid, chunkSize = chunkSize, local = local
) )
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DOWNLOAD, req, callback, userData ctx, RequestType.DOWNLOAD, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_download_chunk( proc storage_download_chunk(
ctx: ptr CodexContext, cid: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, cid: cstring, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeDownloadRequest.createShared(NodeDownloadMsgType.CHUNK, cid = cid) let req = NodeDownloadRequest.createShared(NodeDownloadMsgType.CHUNK, cid = cid)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DOWNLOAD, req, callback, userData ctx, RequestType.DOWNLOAD, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_download_stream( proc storage_download_stream(
ctx: ptr CodexContext, ctx: ptr StorageContext,
cid: cstring, cid: cstring,
chunkSize: csize_t, chunkSize: csize_t,
local: bool, local: bool,
filepath: cstring, filepath: cstring,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeDownloadRequest.createShared( let req = NodeDownloadRequest.createShared(
NodeDownloadMsgType.STREAM, NodeDownloadMsgType.STREAM,
@ -425,140 +431,140 @@ proc codex_download_stream(
filepath = filepath, filepath = filepath,
) )
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DOWNLOAD, req, callback, userData ctx, RequestType.DOWNLOAD, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_download_cancel( proc storage_download_cancel(
ctx: ptr CodexContext, cid: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, cid: cstring, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeDownloadRequest.createShared(NodeDownloadMsgType.CANCEL, cid = cid) let req = NodeDownloadRequest.createShared(NodeDownloadMsgType.CANCEL, cid = cid)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DOWNLOAD, req, callback, userData ctx, RequestType.DOWNLOAD, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_download_manifest( proc storage_download_manifest(
ctx: ptr CodexContext, cid: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, cid: cstring, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeDownloadRequest.createShared(NodeDownloadMsgType.MANIFEST, cid = cid) let req = NodeDownloadRequest.createShared(NodeDownloadMsgType.MANIFEST, cid = cid)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.DOWNLOAD, req, callback, userData ctx, RequestType.DOWNLOAD, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_storage_list( proc storage_list(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeStorageRequest.createShared(NodeStorageMsgType.LIST) let req = NodeStorageRequest.createShared(NodeStorageMsgType.LIST)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.STORAGE, req, callback, userData ctx, RequestType.STORAGE, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_storage_space( proc storage_space(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeStorageRequest.createShared(NodeStorageMsgType.SPACE) let req = NodeStorageRequest.createShared(NodeStorageMsgType.SPACE)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.STORAGE, req, callback, userData ctx, RequestType.STORAGE, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_storage_delete( proc storage_delete(
ctx: ptr CodexContext, cid: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, cid: cstring, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeStorageRequest.createShared(NodeStorageMsgType.DELETE, cid = cid) let req = NodeStorageRequest.createShared(NodeStorageMsgType.DELETE, cid = cid)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.STORAGE, req, callback, userData ctx, RequestType.STORAGE, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_storage_fetch( proc storage_fetch(
ctx: ptr CodexContext, cid: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, cid: cstring, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeStorageRequest.createShared(NodeStorageMsgType.FETCH, cid = cid) let req = NodeStorageRequest.createShared(NodeStorageMsgType.FETCH, cid = cid)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.STORAGE, req, callback, userData ctx, RequestType.STORAGE, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_storage_exists( proc storage_exists(
ctx: ptr CodexContext, cid: cstring, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, cid: cstring, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let req = NodeStorageRequest.createShared(NodeStorageMsgType.EXISTS, cid = cid) let req = NodeStorageRequest.createShared(NodeStorageMsgType.EXISTS, cid = cid)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.STORAGE, req, callback, userData ctx, RequestType.STORAGE, req, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_start( proc storage_start(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent: ptr NodeLifecycleRequest = let reqContent: ptr NodeLifecycleRequest =
NodeLifecycleRequest.createShared(NodeLifecycleMsgType.START_NODE) NodeLifecycleRequest.createShared(NodeLifecycleMsgType.START_NODE)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.LIFECYCLE, reqContent, callback, userData ctx, RequestType.LIFECYCLE, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_stop( proc storage_stop(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
): cint {.dynlib, exportc.} = ): cint {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
checkLibcodexParams(ctx, callback, userData) checkLibstorageParams(ctx, callback, userData)
let reqContent: ptr NodeLifecycleRequest = let reqContent: ptr NodeLifecycleRequest =
NodeLifecycleRequest.createShared(NodeLifecycleMsgType.STOP_NODE) NodeLifecycleRequest.createShared(NodeLifecycleMsgType.STOP_NODE)
let res = codex_context.sendRequestToCodexThread( let res = storage_context.sendRequestToStorageThread(
ctx, RequestType.LIFECYCLE, reqContent, callback, userData ctx, RequestType.LIFECYCLE, reqContent, callback, userData
) )
return callback.okOrError(res, userData) return callback.okOrError(res, userData)
proc codex_set_event_callback( proc storage_set_event_callback(
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ctx: ptr StorageContext, callback: StorageCallback, userData: pointer
) {.dynlib, exportc.} = ) {.dynlib, exportc.} =
initializeLibrary() initializeLibrary()
ctx[].eventCallback = cast[pointer](callback) ctx[].eventCallback = cast[pointer](callback)

View File

@ -1,8 +1,8 @@
## This file defines the Codex context and its thread flow: ## This file defines the Logos Storage context and its thread flow:
## 1. Client enqueues a request and signals the Codex thread. ## 1. Client enqueues a request and signals the Logos Storage thread.
## 2. The Codex thread dequeues the request and sends an ack (reqReceivedSignal). ## 2. The Logos Storage thread dequeues the request and sends an ack (reqReceivedSignal).
## 3. The Codex thread executes the request asynchronously. ## 3. The Logos Storage thread executes the request asynchronously.
## 4. On completion, the Codex thread invokes the client callback with the result and userData. ## 4. On completion, the Logos Storage thread invokes the client callback with the result and userData.
{.pragma: exported, exportc, cdecl, raises: [].} {.pragma: exported, exportc, cdecl, raises: [].}
{.pragma: callback, cdecl, raises: [], gcsafe.} {.pragma: callback, cdecl, raises: [], gcsafe.}
@ -14,15 +14,15 @@ import chronos
import chronos/threadsync import chronos/threadsync
import taskpools/channels_spsc_single import taskpools/channels_spsc_single
import ./ffi_types import ./ffi_types
import ./codex_thread_requests/[codex_thread_request] import ./storage_thread_requests/[storage_thread_request]
from ../codex/codex import CodexServer from ../codex/codex import CodexServer
logScope: logScope:
topics = "codexlib" topics = "libstorage"
type CodexContext* = object type StorageContext* = object
thread: Thread[(ptr CodexContext)] thread: Thread[(ptr StorageContext)]
# This lock is only necessary while we use a SP Channel and while the signalling # This lock is only necessary while we use a SP Channel and while the signalling
# between threads assumes that there aren't concurrent requests. # between threads assumes that there aren't concurrent requests.
@ -30,11 +30,11 @@ type CodexContext* = object
# requests concurrently and spare us the need of locks # requests concurrently and spare us the need of locks
lock: Lock lock: Lock
# Channel to send requests to the Codex thread. # Channel to send requests to the Logos Storage thread.
# Requests will be popped from this channel. # Requests will be popped from this channel.
reqChannel: ChannelSPSCSingle[ptr CodexThreadRequest] reqChannel: ChannelSPSCSingle[ptr StorageThreadRequest]
# To notify the Codex thread that a request is ready # To notify the Logos Storage thread that a request is ready
reqSignal: ThreadSignalPtr reqSignal: ThreadSignalPtr
# To notify the client thread that the request was received. # To notify the client thread that the request was received.
@ -52,10 +52,10 @@ type CodexContext* = object
# returned with every event callback # returned with every event callback
eventUserData*: pointer eventUserData*: pointer
# Set to false to stop the Codex thread (during codex_destroy) # Set to false to stop the Logos Storage thread (during storage_destroy)
running: Atomic[bool] running: Atomic[bool]
template callEventCallback(ctx: ptr CodexContext, eventName: string, body: untyped) = template callEventCallback(ctx: ptr StorageContext, eventName: string, body: untyped) =
## Template used to notify the client of global events ## Template used to notify the client of global events
## Example: onConnectionChanged, onProofMissing, etc. ## Example: onConnectionChanged, onProofMissing, etc.
if isNil(ctx[].eventCallback): if isNil(ctx[].eventCallback):
@ -65,22 +65,22 @@ template callEventCallback(ctx: ptr CodexContext, eventName: string, body: untyp
foreignThreadGc: foreignThreadGc:
try: try:
let event = body let event = body
cast[CodexCallback](ctx[].eventCallback)( cast[StorageCallback](ctx[].eventCallback)(
RET_OK, unsafeAddr event[0], cast[csize_t](len(event)), ctx[].eventUserData RET_OK, unsafeAddr event[0], cast[csize_t](len(event)), ctx[].eventUserData
) )
except CatchableError: except CatchableError:
let msg = let msg =
"Exception " & eventName & " when calling 'eventCallBack': " & "Exception " & eventName & " when calling 'eventCallBack': " &
getCurrentExceptionMsg() getCurrentExceptionMsg()
cast[CodexCallback](ctx[].eventCallback)( cast[StorageCallback](ctx[].eventCallback)(
RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), ctx[].eventUserData RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), ctx[].eventUserData
) )
proc sendRequestToCodexThread*( proc sendRequestToStorageThread*(
ctx: ptr CodexContext, ctx: ptr StorageContext,
reqType: RequestType, reqType: RequestType,
reqContent: pointer, reqContent: pointer,
callback: CodexCallback, callback: StorageCallback,
userData: pointer, userData: pointer,
timeout = InfiniteDuration, timeout = InfiniteDuration,
): Result[void, string] = ): Result[void, string] =
@ -89,60 +89,62 @@ proc sendRequestToCodexThread*(
defer: defer:
ctx.lock.release() ctx.lock.release()
let req = CodexThreadRequest.createShared(reqType, reqContent, callback, userData) let req = StorageThreadRequest.createShared(reqType, reqContent, callback, userData)
# Send the request to the Codex thread # Send the request to the Logos Storage thread
let sentOk = ctx.reqChannel.trySend(req) let sentOk = ctx.reqChannel.trySend(req)
if not sentOk: if not sentOk:
deallocShared(req) deallocShared(req)
return err("Failed to send request to the codex thread: " & $req[]) return err("Failed to send request to the Logos Storage thread: " & $req[])
# Notify the Codex thread that a request is available # Notify the Logos Storage thread that a request is available
let fireSyncRes = ctx.reqSignal.fireSync() let fireSyncRes = ctx.reqSignal.fireSync()
if fireSyncRes.isErr(): if fireSyncRes.isErr():
deallocShared(req) deallocShared(req)
return err( return err(
"Failed to send request to the codex thread: unable to fireSync: " & "Failed to send request to the Logos Storage thread: unable to fireSync: " &
$fireSyncRes.error $fireSyncRes.error
) )
if fireSyncRes.get() == false: if fireSyncRes.get() == false:
deallocShared(req) deallocShared(req)
return err("Failed to send request to the codex thread: fireSync timed out.") return
err("Failed to send request to the Logos Storage thread: fireSync timed out.")
# Wait until the Codex Thread properly received the request # Wait until the Logos Storage thread properly received the request
let res = ctx.reqReceivedSignal.waitSync(timeout) let res = ctx.reqReceivedSignal.waitSync(timeout)
if res.isErr(): if res.isErr():
deallocShared(req) deallocShared(req)
return err( return err(
"Failed to send request to the codex thread: unable to receive reqReceivedSignal signal." "Failed to send request to the Logos Storage thread: unable to receive reqReceivedSignal signal."
) )
## Notice that in case of "ok", the deallocShared(req) is performed by the Codex Thread in the ## Notice that in case of "ok", the deallocShared(req) is performed by the Logos Storage thread in the
## process proc. See the 'codex_thread_request.nim' module for more details. ## process proc. See the 'storage_thread_request.nim' module for more details.
ok() ok()
proc runCodex(ctx: ptr CodexContext) {.async: (raises: []).} = proc runStorage(ctx: ptr StorageContext) {.async: (raises: []).} =
var codex: CodexServer var storage: CodexServer
while true: while true:
try: try:
# Wait until a request is available # Wait until a request is available
await ctx.reqSignal.wait() await ctx.reqSignal.wait()
except Exception as e: except Exception as e:
error "Failure in run codex thread while waiting for reqSignal.", error = e.msg error "Failure in run Logos Storage thread while waiting for reqSignal.",
error = e.msg
continue continue
# If codex_destroy was called, exit the loop # If storage_destroy was called, exit the loop
if ctx.running.load == false: if ctx.running.load == false:
break break
var request: ptr CodexThreadRequest var request: ptr StorageThreadRequest
# Pop a request from the channel # Pop a request from the channel
let recvOk = ctx.reqChannel.tryRecv(request) let recvOk = ctx.reqChannel.tryRecv(request)
if not recvOk: if not recvOk:
error "Failure in run codex: unable to receive request in codex thread." error "Failure in run Storage: unable to receive request in Logos Storage thread."
continue continue
# yield immediately to the event loop # yield immediately to the event loop
@ -151,42 +153,42 @@ proc runCodex(ctx: ptr CodexContext) {.async: (raises: []).} =
asyncSpawn ( asyncSpawn (
proc() {.async.} = proc() {.async.} =
await sleepAsync(0) await sleepAsync(0)
await CodexThreadRequest.process(request, addr codex) await StorageThreadRequest.process(request, addr storage)
)() )()
# Notify the main thread that we picked up the request # Notify the main thread that we picked up the request
let fireRes = ctx.reqReceivedSignal.fireSync() let fireRes = ctx.reqReceivedSignal.fireSync()
if fireRes.isErr(): if fireRes.isErr():
error "Failure in run codex: unable to fire back to requester thread.", error "Failure in run Storage: unable to fire back to requester thread.",
error = fireRes.error error = fireRes.error
proc run(ctx: ptr CodexContext) {.thread.} = proc run(ctx: ptr StorageContext) {.thread.} =
waitFor runCodex(ctx) waitFor runStorage(ctx)
proc createCodexContext*(): Result[ptr CodexContext, string] = proc createStorageContext*(): Result[ptr StorageContext, string] =
## This proc is called from the main thread and it creates ## This proc is called from the main thread and it creates
## the Codex working thread. ## the Logos Storage working thread.
# Allocates a CodexContext in shared memory (for the main thread) # Allocates a StorageContext in shared memory (for the main thread)
var ctx = createShared(CodexContext, 1) var ctx = createShared(StorageContext, 1)
# This signal is used by the main side to wake the Codex thread # This signal is used by the main side to wake the Logos Storage thread
# when a new request is enqueued. # when a new request is enqueued.
ctx.reqSignal = ThreadSignalPtr.new().valueOr: ctx.reqSignal = ThreadSignalPtr.new().valueOr:
return return
err("Failed to create a context: unable to create reqSignal ThreadSignalPtr.") err("Failed to create a context: unable to create reqSignal ThreadSignalPtr.")
# Used to let the caller know that the Codex thread has # Used to let the caller know that the Logos Storage thread has
# acknowledged / picked up a request (like a handshake). # acknowledged / picked up a request (like a handshake).
ctx.reqReceivedSignal = ThreadSignalPtr.new().valueOr: ctx.reqReceivedSignal = ThreadSignalPtr.new().valueOr:
return err( return err(
"Failed to create codex context: unable to create reqReceivedSignal ThreadSignalPtr." "Failed to create Logos Storage context: unable to create reqReceivedSignal ThreadSignalPtr."
) )
# Protects shared state inside CodexContext # Protects shared state inside StorageContext
ctx.lock.initLock() ctx.lock.initLock()
# Codex thread will loop until codex_destroy is called # Logos Storage thread will loop until storage_destroy is called
ctx.running.store(true) ctx.running.store(true)
try: try:
@ -194,23 +196,23 @@ proc createCodexContext*(): Result[ptr CodexContext, string] =
except ValueError, ResourceExhaustedError: except ValueError, ResourceExhaustedError:
freeShared(ctx) freeShared(ctx)
return err( return err(
"Failed to create codex context: unable to create thread: " & "Failed to create Logos Storage context: unable to create thread: " &
getCurrentExceptionMsg() getCurrentExceptionMsg()
) )
return ok(ctx) return ok(ctx)
proc destroyCodexContext*(ctx: ptr CodexContext): Result[void, string] = proc destroyStorageContext*(ctx: ptr StorageContext): Result[void, string] =
# Signal the Codex thread to stop # Signal the Logos Storage thread to stop
ctx.running.store(false) ctx.running.store(false)
# Wake the worker up if it's waiting # Wake the worker up if it's waiting
let signaledOnTime = ctx.reqSignal.fireSync().valueOr: let signaledOnTime = ctx.reqSignal.fireSync().valueOr:
return err("Failed to destroy codex context: " & $error) return err("Failed to destroy Logos Storage context: " & $error)
if not signaledOnTime: if not signaledOnTime:
return err( return err(
"Failed to destroy codex context: unable to get signal reqSignal on time in destroyCodexContext." "Failed to destroy Logos Storage context: unable to get signal reqSignal on time in destroyStorageContext."
) )
# Wait for the thread to finish # Wait for the thread to finish

View File

@ -1,8 +1,8 @@
{.push raises: [].} {.push raises: [].}
## This file contains the debug info available with Codex. ## This file contains the debug info available with Logos Storage.
## The DEBUG type will return info about the P2P node. ## The DEBUG type will return info about the P2P node.
## The PEER type is available only with codex_enable_api_debug_peers flag. ## The PEER type is available only with storage_enable_api_debug_peers flag.
## It will return info about a specific peer if available. ## It will return info about a specific peer if available.
import std/[options] import std/[options]
@ -17,7 +17,7 @@ import ../../../codex/node
from ../../../codex/codex import CodexServer, node from ../../../codex/codex import CodexServer, node
logScope: logScope:
topics = "codexlib codexlibdebug" topics = "libstorage libstoragedebug"
type NodeDebugMsgType* = enum type NodeDebugMsgType* = enum
DEBUG DEBUG
@ -47,9 +47,9 @@ proc destroyShared(self: ptr NodeDebugRequest) =
deallocShared(self) deallocShared(self)
proc getDebug( proc getDebug(
codex: ptr CodexServer storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
let node = codex[].node let node = storage[].node
let table = RestRoutingTable.init(node.discovery.protocol.routingTable) let table = RestRoutingTable.init(node.discovery.protocol.routingTable)
let json = let json =
@ -65,10 +65,10 @@ proc getDebug(
return ok($json) return ok($json)
proc getPeer( proc getPeer(
codex: ptr CodexServer, peerId: cstring storage: ptr CodexServer, peerId: cstring
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
when codex_enable_api_debug_peers: when storage_enable_api_debug_peers:
let node = codex[].node let node = storage[].node
let res = PeerId.init($peerId) let res = PeerId.init($peerId)
if res.isErr: if res.isErr:
return err("Failed to get peer: invalid peer ID " & $peerId & ": " & $res.error()) return err("Failed to get peer: invalid peer ID " & $peerId & ": " & $res.error())
@ -89,7 +89,7 @@ proc getPeer(
return err("Failed to get peer: peer debug API is disabled") return err("Failed to get peer: peer debug API is disabled")
proc updateLogLevel( proc updateLogLevel(
codex: ptr CodexServer, logLevel: cstring storage: ptr CodexServer, logLevel: cstring
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
try: try:
{.gcsafe.}: {.gcsafe.}:
@ -100,26 +100,26 @@ proc updateLogLevel(
return ok("") return ok("")
proc process*( proc process*(
self: ptr NodeDebugRequest, codex: ptr CodexServer self: ptr NodeDebugRequest, storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
defer: defer:
destroyShared(self) destroyShared(self)
case self.operation case self.operation
of NodeDebugMsgType.DEBUG: of NodeDebugMsgType.DEBUG:
let res = (await getDebug(codex)) let res = (await getDebug(storage))
if res.isErr: if res.isErr:
error "Failed to get DEBUG.", error = res.error error "Failed to get DEBUG.", error = res.error
return err($res.error) return err($res.error)
return res return res
of NodeDebugMsgType.PEER: of NodeDebugMsgType.PEER:
let res = (await getPeer(codex, self.peerId)) let res = (await getPeer(storage, self.peerId))
if res.isErr: if res.isErr:
error "Failed to get PEER.", error = res.error error "Failed to get PEER.", error = res.error
return err($res.error) return err($res.error)
return res return res
of NodeDebugMsgType.LOG_LEVEL: of NodeDebugMsgType.LOG_LEVEL:
let res = (await updateLogLevel(codex, self.logLevel)) let res = (await updateLogLevel(storage, self.logLevel))
if res.isErr: if res.isErr:
error "Failed to update LOG_LEVEL.", error = res.error error "Failed to update LOG_LEVEL.", error = res.error
return err($res.error) return err($res.error)

View File

@ -30,7 +30,7 @@ from ../../../codex/rest/json import `%`, RestContent
from libp2p import Cid, init, `$` from libp2p import Cid, init, `$`
logScope: logScope:
topics = "codexlib codexlibdownload" topics = "libstorage libstoragedownload"
type NodeDownloadMsgType* = enum type NodeDownloadMsgType* = enum
INIT INIT
@ -80,7 +80,7 @@ proc destroyShared(self: ptr NodeDownloadRequest) =
deallocShared(self) deallocShared(self)
proc init( proc init(
codex: ptr CodexServer, cCid: cstring = "", chunkSize: csize_t = 0, local: bool storage: ptr CodexServer, cCid: cstring = "", chunkSize: csize_t = 0, local: bool
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
## Init a new session to download the file identified by cid. ## Init a new session to download the file identified by cid.
## ##
@ -96,7 +96,7 @@ proc init(
if downloadSessions.contains($cid): if downloadSessions.contains($cid):
return ok("Download session already exists.") return ok("Download session already exists.")
let node = codex[].node let node = storage[].node
var stream: LPStream var stream: LPStream
try: try:
@ -114,7 +114,7 @@ proc init(
return ok("") return ok("")
proc chunk( proc chunk(
codex: ptr CodexServer, cCid: cstring = "", onChunk: OnChunkHandler storage: ptr CodexServer, cCid: cstring = "", onChunk: OnChunkHandler
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
## Download the next chunk of the file identified by cid. ## Download the next chunk of the file identified by cid.
## The chunk is passed to the onChunk handler. ## The chunk is passed to the onChunk handler.
@ -164,7 +164,7 @@ proc chunk(
return ok("") return ok("")
proc streamData( proc streamData(
codex: ptr CodexServer, storage: ptr CodexServer,
stream: LPStream, stream: LPStream,
onChunk: OnChunkHandler, onChunk: OnChunkHandler,
chunkSize: csize_t, chunkSize: csize_t,
@ -207,7 +207,7 @@ proc streamData(
return ok("") return ok("")
proc stream( proc stream(
codex: ptr CodexServer, storage: ptr CodexServer,
cCid: cstring, cCid: cstring,
chunkSize: csize_t, chunkSize: csize_t,
local: bool, local: bool,
@ -232,11 +232,11 @@ proc stream(
except KeyError: except KeyError:
return err("Failed to stream: no session for cid " & $cid) return err("Failed to stream: no session for cid " & $cid)
let node = codex[].node let node = storage[].node
try: try:
let res = let res =
await noCancel codex.streamData(session.stream, onChunk, chunkSize, filepath) await noCancel storage.streamData(session.stream, onChunk, chunkSize, filepath)
if res.isErr: if res.isErr:
return err($res.error) return err($res.error)
except LPStreamError as e: except LPStreamError as e:
@ -251,7 +251,7 @@ proc stream(
return ok("") return ok("")
proc cancel( proc cancel(
codex: ptr CodexServer, cCid: cstring storage: ptr CodexServer, cCid: cstring
): Future[Result[string, string]] {.raises: [], async: (raises: []).} = ): Future[Result[string, string]] {.raises: [], async: (raises: []).} =
## Cancel the download session identified by cid. ## Cancel the download session identified by cid.
## This operation is not supported when using the stream mode, ## This operation is not supported when using the stream mode,
@ -279,14 +279,14 @@ proc cancel(
return ok("") return ok("")
proc manifest( proc manifest(
codex: ptr CodexServer, cCid: cstring storage: ptr CodexServer, cCid: cstring
): Future[Result[string, string]] {.raises: [], async: (raises: []).} = ): Future[Result[string, string]] {.raises: [], async: (raises: []).} =
let cid = Cid.init($cCid) let cid = Cid.init($cCid)
if cid.isErr: if cid.isErr:
return err("Failed to fetch manifest: cannot parse cid: " & $cCid) return err("Failed to fetch manifest: cannot parse cid: " & $cCid)
try: try:
let node = codex[].node let node = storage[].node
let manifest = await node.fetchManifest(cid.get()) let manifest = await node.fetchManifest(cid.get())
if manifest.isErr: if manifest.isErr:
return err("Failed to fetch manifest: " & manifest.error.msg) return err("Failed to fetch manifest: " & manifest.error.msg)
@ -296,40 +296,42 @@ proc manifest(
return err("Failed to fetch manifest: download cancelled.") return err("Failed to fetch manifest: download cancelled.")
proc process*( proc process*(
self: ptr NodeDownloadRequest, codex: ptr CodexServer, onChunk: OnChunkHandler self: ptr NodeDownloadRequest, storage: ptr CodexServer, onChunk: OnChunkHandler
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
defer: defer:
destroyShared(self) destroyShared(self)
case self.operation case self.operation
of NodeDownloadMsgType.INIT: of NodeDownloadMsgType.INIT:
let res = (await init(codex, self.cid, self.chunkSize, self.local)) let res = (await init(storage, self.cid, self.chunkSize, self.local))
if res.isErr: if res.isErr:
error "Failed to INIT.", error = res.error error "Failed to INIT.", error = res.error
return err($res.error) return err($res.error)
return res return res
of NodeDownloadMsgType.CHUNK: of NodeDownloadMsgType.CHUNK:
let res = (await chunk(codex, self.cid, onChunk)) let res = (await chunk(storage, self.cid, onChunk))
if res.isErr: if res.isErr:
error "Failed to CHUNK.", error = res.error error "Failed to CHUNK.", error = res.error
return err($res.error) return err($res.error)
return res return res
of NodeDownloadMsgType.STREAM: of NodeDownloadMsgType.STREAM:
let res = ( let res = (
await stream(codex, self.cid, self.chunkSize, self.local, self.filepath, onChunk) await stream(
storage, self.cid, self.chunkSize, self.local, self.filepath, onChunk
)
) )
if res.isErr: if res.isErr:
error "Failed to STREAM.", error = res.error error "Failed to STREAM.", error = res.error
return err($res.error) return err($res.error)
return res return res
of NodeDownloadMsgType.CANCEL: of NodeDownloadMsgType.CANCEL:
let res = (await cancel(codex, self.cid)) let res = (await cancel(storage, self.cid))
if res.isErr: if res.isErr:
error "Failed to CANCEL.", error = res.error error "Failed to CANCEL.", error = res.error
return err($res.error) return err($res.error)
return res return res
of NodeDownloadMsgType.MANIFEST: of NodeDownloadMsgType.MANIFEST:
let res = (await manifest(codex, self.cid)) let res = (await manifest(storage, self.cid))
if res.isErr: if res.isErr:
error "Failed to MANIFEST.", error = res.error error "Failed to MANIFEST.", error = res.error
return err($res.error) return err($res.error)

View File

@ -12,7 +12,7 @@ import ../../../codex/node
from ../../../codex/codex import CodexServer, config, node from ../../../codex/codex import CodexServer, config, node
logScope: logScope:
topics = "codexlib codexlibinfo" topics = "libstorage libstorageinfo"
type NodeInfoMsgType* = enum type NodeInfoMsgType* = enum
REPO REPO
@ -31,45 +31,45 @@ proc destroyShared(self: ptr NodeInfoRequest) =
deallocShared(self) deallocShared(self)
proc getRepo( proc getRepo(
codex: ptr CodexServer storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
return ok($(codex[].config.dataDir)) return ok($(storage[].config.dataDir))
proc getSpr( proc getSpr(
codex: ptr CodexServer storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
let spr = codex[].node.discovery.dhtRecord let spr = storage[].node.discovery.dhtRecord
if spr.isNone: if spr.isNone:
return err("Failed to get SPR: no SPR record found.") return err("Failed to get SPR: no SPR record found.")
return ok(spr.get.toURI) return ok(spr.get.toURI)
proc getPeerId( proc getPeerId(
codex: ptr CodexServer storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
return ok($codex[].node.switch.peerInfo.peerId) return ok($storage[].node.switch.peerInfo.peerId)
proc process*( proc process*(
self: ptr NodeInfoRequest, codex: ptr CodexServer self: ptr NodeInfoRequest, storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
defer: defer:
destroyShared(self) destroyShared(self)
case self.operation case self.operation
of REPO: of REPO:
let res = (await getRepo(codex)) let res = (await getRepo(storage))
if res.isErr: if res.isErr:
error "Failed to get REPO.", error = res.error error "Failed to get REPO.", error = res.error
return err($res.error) return err($res.error)
return res return res
of SPR: of SPR:
let res = (await getSpr(codex)) let res = (await getSpr(storage))
if res.isErr: if res.isErr:
error "Failed to get SPR.", error = res.error error "Failed to get SPR.", error = res.error
return err($res.error) return err($res.error)
return res return res
of PEERID: of PEERID:
let res = (await getPeerId(codex)) let res = (await getPeerId(storage))
if res.isErr: if res.isErr:
error "Failed to get PEERID.", error = res.error error "Failed to get PEERID.", error = res.error
return err($res.error) return err($res.error)

View File

@ -1,7 +1,7 @@
## This file contains the lifecycle request type that will be handled. ## This file contains the lifecycle request type that will be handled.
## CREATE_NODE: create a new Codex node with the provided config.json. ## CREATE_NODE: create a new Logos Storage node with the provided config.json.
## START_NODE: start the provided Codex node. ## START_NODE: start the provided Logos Storage node.
## STOP_NODE: stop the provided Codex node. ## STOP_NODE: stop the provided Logos Storage node.
import std/[options, json, strutils, net, os] import std/[options, json, strutils, net, os]
import codexdht/discv5/spr import codexdht/discv5/spr
@ -25,7 +25,7 @@ import ../../../codex/units
from ../../../codex/codex import CodexServer, new, start, stop, close from ../../../codex/codex import CodexServer, new, start, stop, close
logScope: logScope:
topics = "codexlib codexliblifecycle" topics = "libstorage libstoragelifecycle"
type NodeLifecycleMsgType* = enum type NodeLifecycleMsgType* = enum
CREATE_NODE CREATE_NODE
@ -88,7 +88,7 @@ proc destroyShared(self: ptr NodeLifecycleRequest) =
deallocShared(self[].configJson) deallocShared(self[].configJson)
deallocShared(self) deallocShared(self)
proc createCodex( proc createStorage(
configJson: cstring configJson: cstring
): Future[Result[CodexServer, string]] {.async: (raises: []).} = ): Future[Result[CodexServer, string]] {.async: (raises: []).} =
var conf: CodexConf var conf: CodexConf
@ -96,7 +96,7 @@ proc createCodex(
try: try:
conf = CodexConf.load( conf = CodexConf.load(
version = codexFullVersion, version = codexFullVersion,
envVarsPrefix = "codex", envVarsPrefix = "storage",
cmdLine = @[], cmdLine = @[],
secondarySources = proc( secondarySources = proc(
config: CodexConf, sources: auto config: CodexConf, sources: auto
@ -106,7 +106,7 @@ proc createCodex(
, ,
) )
except ConfigurationError as e: except ConfigurationError as e:
return err("Failed to create codex: unable to load configuration: " & e.msg) return err("Failed to create Storage: unable to load configuration: " & e.msg)
conf.setupLogging() conf.setupLogging()
@ -114,7 +114,7 @@ proc createCodex(
{.gcsafe.}: {.gcsafe.}:
updateLogLevel(conf.logLevel) updateLogLevel(conf.logLevel)
except ValueError as err: except ValueError as err:
return err("Failed to create codex: invalid value for log level: " & err.msg) return err("Failed to create Storage: invalid value for log level: " & err.msg)
conf.setupMetrics() conf.setupMetrics()
@ -122,14 +122,14 @@ proc createCodex(
# We are unable to access/create data folder or data folder's # We are unable to access/create data folder or data folder's
# permissions are insecure. # permissions are insecure.
return err( return err(
"Failed to create codex: unable to access/create data folder or data folder's permissions are insecure." "Failed to create Storage: unable to access/create data folder or data folder's permissions are insecure."
) )
if not (checkAndCreateDataDir((conf.dataDir / "repo"))): if not (checkAndCreateDataDir((conf.dataDir / "repo"))):
# We are unable to access/create data folder or data folder's # We are unable to access/create data folder or data folder's
# permissions are insecure. # permissions are insecure.
return err( return err(
"Failed to create codex: unable to access/create data folder or data folder's permissions are insecure." "Failed to create Storage: unable to access/create data folder or data folder's permissions are insecure."
) )
let keyPath = let keyPath =
@ -139,7 +139,7 @@ proc createCodex(
conf.dataDir / conf.netPrivKeyFile conf.dataDir / conf.netPrivKeyFile
let privateKey = setupKey(keyPath) let privateKey = setupKey(keyPath)
if privateKey.isErr: if privateKey.isErr:
return err("Failed to create codex: unable to get the private key.") return err("Failed to create Storage: unable to get the private key.")
let pk = privateKey.get() let pk = privateKey.get()
conf.apiBindAddress = string.none conf.apiBindAddress = string.none
@ -148,20 +148,20 @@ proc createCodex(
try: try:
CodexServer.new(conf, pk) CodexServer.new(conf, pk)
except Exception as exc: except Exception as exc:
return err("Failed to create codex: " & exc.msg) return err("Failed to create Storage: " & exc.msg)
return ok(server) return ok(server)
proc process*( proc process*(
self: ptr NodeLifecycleRequest, codex: ptr CodexServer self: ptr NodeLifecycleRequest, storage: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} = ): Future[Result[string, string]] {.async: (raises: []).} =
defer: defer:
destroyShared(self) destroyShared(self)
case self.operation case self.operation
of CREATE_NODE: of CREATE_NODE:
codex[] = ( storage[] = (
await createCodex( await createStorage(
self.configJson # , self.appCallbacks self.configJson # , self.appCallbacks
) )
).valueOr: ).valueOr:
@ -169,19 +169,19 @@ proc process*(
return err($error) return err($error)
of START_NODE: of START_NODE:
try: try:
await codex[].start() await storage[].start()
except Exception as e: except Exception as e:
error "Failed to START_NODE.", error = e.msg error "Failed to START_NODE.", error = e.msg
return err(e.msg) return err(e.msg)
of STOP_NODE: of STOP_NODE:
try: try:
await codex[].stop() await storage[].stop()
except Exception as e: except Exception as e:
error "Failed to STOP_NODE.", error = e.msg error "Failed to STOP_NODE.", error = e.msg
return err(e.msg) return err(e.msg)
of CLOSE_NODE: of CLOSE_NODE:
try: try:
await codex[].close() await storage[].close()
except Exception as e: except Exception as e:
error "Failed to STOP_NODE.", error = e.msg error "Failed to STOP_NODE.", error = e.msg
return err(e.msg) return err(e.msg)

Some files were not shown because too many files have changed in this diff Show More