mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-04 06:53:12 +00:00
chore: Improve binding for waku_sync (#3102)
This commit is contained in:
parent
5e3f79896a
commit
8faca4c024
2
vendor/negentropy
vendored
2
vendor/negentropy
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 13243f668edb85ef4b660e40833d81435501325f
|
Subproject commit 449b304d67e9401bd96451cb349eb6b17b713f67
|
||||||
@ -67,6 +67,8 @@ proc toBufferSeq(buffLen: uint, buffPtr: ptr Buffer): seq[Buffer] =
|
|||||||
|
|
||||||
type NegentropyStorage* = distinct pointer
|
type NegentropyStorage* = distinct pointer
|
||||||
|
|
||||||
|
proc get_last_error(): cstring {.header: NEGENTROPY_HEADER, importc: "get_last_error".}
|
||||||
|
|
||||||
# https://github.com/waku-org/negentropy/blob/d4845b95b5a2d9bee28555833e7502db71bf319f/cpp/negentropy_wrapper.h#L27
|
# https://github.com/waku-org/negentropy/blob/d4845b95b5a2d9bee28555833e7502db71bf319f/cpp/negentropy_wrapper.h#L27
|
||||||
proc storage_init(
|
proc storage_init(
|
||||||
db_path: cstring, name: cstring
|
db_path: cstring, name: cstring
|
||||||
@ -194,6 +196,10 @@ proc new*(T: type NegentropyStorage): Result[T, string] =
|
|||||||
#[ TODO: Uncomment once we move to lmdb
|
#[ TODO: Uncomment once we move to lmdb
|
||||||
if storage == nil:
|
if storage == nil:
|
||||||
return err("storage initialization failed") ]#
|
return err("storage initialization failed") ]#
|
||||||
|
|
||||||
|
if storage == nil:
|
||||||
|
return err($get_last_error())
|
||||||
|
|
||||||
return ok(storage)
|
return ok(storage)
|
||||||
|
|
||||||
proc delete*(storage: NegentropyStorage) =
|
proc delete*(storage: NegentropyStorage) =
|
||||||
@ -211,7 +217,7 @@ proc erase*(
|
|||||||
if res:
|
if res:
|
||||||
return ok()
|
return ok()
|
||||||
else:
|
else:
|
||||||
return err("erase error")
|
return err($get_last_error())
|
||||||
|
|
||||||
proc insert*(
|
proc insert*(
|
||||||
storage: NegentropyStorage, id: int64, hash: WakuMessageHash
|
storage: NegentropyStorage, id: int64, hash: WakuMessageHash
|
||||||
@ -225,7 +231,7 @@ proc insert*(
|
|||||||
if res:
|
if res:
|
||||||
return ok()
|
return ok()
|
||||||
else:
|
else:
|
||||||
return err("insert error")
|
return err($get_last_error())
|
||||||
|
|
||||||
proc len*(storage: NegentropyStorage): int =
|
proc len*(storage: NegentropyStorage): int =
|
||||||
int(storage.size)
|
int(storage.size)
|
||||||
@ -245,6 +251,10 @@ proc new*(
|
|||||||
#[ TODO: Uncomment once we move to lmdb
|
#[ TODO: Uncomment once we move to lmdb
|
||||||
if storage == nil:
|
if storage == nil:
|
||||||
return err("storage initialization failed") ]#
|
return err("storage initialization failed") ]#
|
||||||
|
|
||||||
|
if subrange == nil:
|
||||||
|
return err($get_last_error())
|
||||||
|
|
||||||
return ok(subrange)
|
return ok(subrange)
|
||||||
|
|
||||||
proc delete*(subrange: NegentropySubRangeStorage) =
|
proc delete*(subrange: NegentropySubRangeStorage) =
|
||||||
@ -296,16 +306,20 @@ proc new*(
|
|||||||
let raw_negentropy =
|
let raw_negentropy =
|
||||||
constructNegentropy(NegentropyStorage(storage), uint64(frameSizeLimit))
|
constructNegentropy(NegentropyStorage(storage), uint64(frameSizeLimit))
|
||||||
|
|
||||||
let negentropy = NegentropyWithStorage(inner: raw_negentropy)
|
if cast[pointer](raw_negentropy) == nil:
|
||||||
|
return err($get_last_error())
|
||||||
|
|
||||||
|
let negentropy = NegentropyWithStorage(inner: raw_negentropy)
|
||||||
return ok(negentropy)
|
return ok(negentropy)
|
||||||
elif storage is NegentropySubRangeStorage:
|
elif storage is NegentropySubRangeStorage:
|
||||||
let raw_negentropy = constructNegentropyWithSubRange(
|
let raw_negentropy = constructNegentropyWithSubRange(
|
||||||
NegentropySubRangeStorage(storage), uint64(frameSizeLimit)
|
NegentropySubRangeStorage(storage), uint64(frameSizeLimit)
|
||||||
)
|
)
|
||||||
|
|
||||||
let negentropy = NegentropyWithSubRange(inner: raw_negentropy)
|
if cast[pointer](raw_negentropy) == nil:
|
||||||
|
return err($get_last_error())
|
||||||
|
|
||||||
|
let negentropy = NegentropyWithSubRange(inner: raw_negentropy)
|
||||||
return ok(negentropy)
|
return ok(negentropy)
|
||||||
|
|
||||||
method delete*(self: NegentropyWithSubRange) =
|
method delete*(self: NegentropyWithSubRange) =
|
||||||
@ -319,7 +333,7 @@ method initiate*(self: NegentropyWithSubRange): Result[NegentropyPayload, string
|
|||||||
let ret = self.inner.raw_initiate_subrange(myResultPtr)
|
let ret = self.inner.raw_initiate_subrange(myResultPtr)
|
||||||
if ret < 0 or myResultPtr == nil:
|
if ret < 0 or myResultPtr == nil:
|
||||||
error "negentropy initiate failed with code ", code = ret
|
error "negentropy initiate failed with code ", code = ret
|
||||||
return err("negentropy already initiated!")
|
return err($get_last_error())
|
||||||
let bytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
let bytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
||||||
free_result(myResultPtr)
|
free_result(myResultPtr)
|
||||||
trace "received return from initiate", len = myResultPtr.output.len
|
trace "received return from initiate", len = myResultPtr.output.len
|
||||||
@ -340,7 +354,7 @@ method serverReconcile*(
|
|||||||
let ret = self.inner.raw_reconcile_subrange(queryBufPtr, myResultPtr)
|
let ret = self.inner.raw_reconcile_subrange(queryBufPtr, myResultPtr)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
error "raw_reconcile failed with code ", code = ret
|
error "raw_reconcile failed with code ", code = ret
|
||||||
return err($myResultPtr.error)
|
return err($get_last_error())
|
||||||
trace "received return from raw_reconcile", len = myResultPtr.output.len
|
trace "received return from raw_reconcile", len = myResultPtr.output.len
|
||||||
|
|
||||||
let outputBytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
let outputBytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
||||||
@ -368,7 +382,7 @@ method clientReconcile*(
|
|||||||
let ret = self.inner.raw_reconcile_with_ids_subrange(cQuery.unsafeAddr, myResultPtr)
|
let ret = self.inner.raw_reconcile_with_ids_subrange(cQuery.unsafeAddr, myResultPtr)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
error "raw_reconcile failed with code ", code = ret
|
error "raw_reconcile failed with code ", code = ret
|
||||||
return err($myResultPtr.error)
|
return err($get_last_error())
|
||||||
|
|
||||||
let output = bufferToBytes(addr myResult.output)
|
let output = bufferToBytes(addr myResult.output)
|
||||||
|
|
||||||
@ -414,7 +428,7 @@ method initiate*(self: NegentropyWithStorage): Result[NegentropyPayload, string]
|
|||||||
let ret = self.inner.raw_initiate(myResultPtr)
|
let ret = self.inner.raw_initiate(myResultPtr)
|
||||||
if ret < 0 or myResultPtr == nil:
|
if ret < 0 or myResultPtr == nil:
|
||||||
error "negentropy initiate failed with code ", code = ret
|
error "negentropy initiate failed with code ", code = ret
|
||||||
return err("negentropy already initiated!")
|
return err($get_last_error())
|
||||||
let bytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
let bytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
||||||
free_result(myResultPtr)
|
free_result(myResultPtr)
|
||||||
trace "received return from initiate", len = myResultPtr.output.len
|
trace "received return from initiate", len = myResultPtr.output.len
|
||||||
@ -435,7 +449,7 @@ method serverReconcile*(
|
|||||||
let ret = self.inner.raw_reconcile(queryBufPtr, myResultPtr)
|
let ret = self.inner.raw_reconcile(queryBufPtr, myResultPtr)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
error "raw_reconcile failed with code ", code = ret
|
error "raw_reconcile failed with code ", code = ret
|
||||||
return err($myResultPtr.error)
|
return err($get_last_error())
|
||||||
trace "received return from raw_reconcile", len = myResultPtr.output.len
|
trace "received return from raw_reconcile", len = myResultPtr.output.len
|
||||||
|
|
||||||
let outputBytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
let outputBytes: seq[byte] = bufferToBytes(addr(myResultPtr.output))
|
||||||
@ -463,7 +477,7 @@ method clientReconcile*(
|
|||||||
let ret = self.inner.raw_reconcile_with_ids(cQuery.unsafeAddr, myResultPtr)
|
let ret = self.inner.raw_reconcile_with_ids(cQuery.unsafeAddr, myResultPtr)
|
||||||
if ret < 0:
|
if ret < 0:
|
||||||
error "raw_reconcile failed with code ", code = ret
|
error "raw_reconcile failed with code ", code = ret
|
||||||
return err($myResultPtr.error)
|
return err($get_last_error())
|
||||||
|
|
||||||
let output = bufferToBytes(addr myResult.output)
|
let output = bufferToBytes(addr myResult.output)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user