Add node space

This commit is contained in:
Arnaud 2025-10-01 09:45:16 +02:00
parent e904355d72
commit 84b9e676f0
No known key found for this signature in database
GPG Key ID: B8FBC178F10CA7AE
3 changed files with 58 additions and 2 deletions

View File

@ -67,6 +67,9 @@ func config*(self: CodexServer): CodexConf =
func node*(self: CodexServer): CodexNodeRef =
return self.codexNode
func repoStore*(self: CodexServer): RepoStore =
return self.repoStore
proc waitForSync(provider: Provider): Future[void] {.async.} =
var sleepTime = 1
trace "Checking sync state of Ethereum provider..."

View File

@ -152,6 +152,10 @@ package main
return codex_storage_fetch(codexCtx, cid, (CodexCallback) callback, resp);
}
static int cGoCodexStorageSpace(void* codexCtx, void* resp) {
return codex_storage_space(codexCtx, (CodexCallback) callback, resp);
}
static int cGoCodexStart(void* codexCtx, void* resp) {
return codex_start(codexCtx, (CodexCallback) callback, resp);
}
@ -353,6 +357,13 @@ type CodexManifestWithCid struct {
Manifest CodexManifest `json:"manifest"`
}
type CodexSpace struct {
TotalBlocks int `json:"totalBlocks"`
QuotaMaxBytes int64 `json:"quotaMaxBytes"`
QuotaUsedBytes int64 `json:"quotaUsedBytes"`
QuotaReservedBytes int64 `json:"quotaReservedBytes"`
}
func newBridgeCtx() *bridgeCtx {
bridge := &bridgeCtx{}
bridge.wg = &sync.WaitGroup{}
@ -996,6 +1007,26 @@ func (self CodexNode) CodexStorageFetch(cid string) (CodexManifest, error) {
return manifest, nil
}
func (self CodexNode) CodexStorageSpace() (CodexSpace, error) {
var space CodexSpace
bridge := newBridgeCtx()
defer bridge.free()
if C.cGoCodexStorageSpace(self.ctx, bridge.resp) != C.RET_OK {
return space, bridge.CallError("cGoCodexStorageSpace")
}
value, err := bridge.wait()
if err != nil {
return space, err
}
err = json.Unmarshal([]byte(value), &space)
return space, err
}
func (self CodexNode) CodexStart() error {
bridge := newBridgeCtx()
defer bridge.free()
@ -1248,6 +1279,13 @@ func main() {
}
log.Println("Storage Fetch content:", manifest)
space, err := node.CodexStorageSpace()
if err != nil {
log.Fatal("Error happened:", err.Error())
}
log.Println("Storage Space content:", space)
// }
// err = node.CodexConnect(peerId, []string{})

View File

@ -13,9 +13,11 @@ import chronicles
import libp2p/stream/[lpstream]
import serde/json as serde
import ../../alloc
import ../../../codex/units
import ../../../codex/manifest
import ../../../codex/stores/repostore
from ../../../codex/codex import CodexServer, node
from ../../../codex/codex import CodexServer, node, repoStore
from ../../../codex/node import iterateManifests, fetchManifest, fetchDatasetAsyncTask
from libp2p import Cid, init, `$`
@ -32,6 +34,12 @@ type NodeStorageRequest* = object
operation: NodeStorageMsgType
cid: cstring
type StorageSpace = object
totalBlocks* {.serialize.}: Natural
quotaMaxBytes* {.serialize.}: NBytes
quotaUsedBytes* {.serialize.}: NBytes
quotaReservedBytes* {.serialize.}: NBytes
proc createShared*(
T: type NodeStorageRequest, op: NodeStorageMsgType, cid: cstring = ""
): ptr type T =
@ -93,7 +101,14 @@ proc fetch(
proc space(
codex: ptr CodexServer
): Future[Result[string, string]] {.async: (raises: []).} =
return err("SPACE operation not implemented yet.")
let repoStore = codex[].repoStore
let space = StorageSpace(
totalBlocks: repoStore.totalBlocks,
quotaMaxBytes: repoStore.quotaMaxBytes,
quotaUsedBytes: repoStore.quotaUsedBytes,
quotaReservedBytes: repoStore.quotaReservedBytes,
)
return ok(serde.toJson(space))
proc process*(
self: ptr NodeStorageRequest, codex: ptr CodexServer