From 456b3d273d2adad910fd8d77ef35822bda89d7aa Mon Sep 17 00:00:00 2001 From: Aya Hassan Date: Thu, 19 Feb 2026 02:13:55 +0100 Subject: [PATCH 1/3] Add wrapper for first function --- waku/wrapper.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 waku/wrapper.py diff --git a/waku/wrapper.py b/waku/wrapper.py new file mode 100644 index 0000000..e69de29 From 0f401533274f3248c07ccb29bac6346c7826eadd Mon Sep 17 00:00:00 2001 From: Aya Hassan Date: Thu, 19 Feb 2026 13:22:44 +0100 Subject: [PATCH 2/3] Add first function wrapper --- waku/wrapper.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/waku/wrapper.py b/waku/wrapper.py index e69de29..f2cba26 100644 --- a/waku/wrapper.py +++ b/waku/wrapper.py @@ -0,0 +1,52 @@ +from cffi import FFI +from pathlib import Path +import json + + +config = { + "relay": True, + "discv5Discovery": True, + "peerExchange": True, + "clusterId": 3, + "shard": 0, + "rlnRelay": False +} +config_json1 = json.dumps(config) +ffi = FFI() + +_repo_root = Path(__file__).resolve().parents[1] +lib = ffi.dlopen(str(_repo_root / "lib" / "liblogosdelivery.so")) + +ffi.cdef(""" + typedef void (*FFICallBack)(int callerRet, const char *msg, size_t len, void *userData); + + void *logosdelivery_create_node( + const char *configJson, + FFICallBack callback, + void *userData + ); +""") + +def process_callback(ret, char_p, length, callback): + byte_string = ffi.buffer(char_p, length)[:] if char_p != ffi.NULL and length else b"" + callback(ret, byte_string) + +CallbackType = ffi.callback("void(int, const char*, size_t, void*)") + +def logosdelivery_create_node(config_json, callback): + def cb(ret, char_p, length, userData): + process_callback(ret, char_p, length, callback) + + return lib.logosdelivery_create_node( + config_json.encode("utf-8"), + CallbackType(cb), + ffi.cast("void*", 0), + ) + +if __name__ == "__main__": + def cb(ret, msg): + print("ret:", ret) + print("msg:", msg) + + ctx = logosdelivery_create_node(config_json1, cb) + print("ctx:", ctx) \ No newline at end of file From cab26c889fc3abb82487a520ec9a143be52a5c93 Mon Sep 17 00:00:00 2001 From: Aya Hassan Date: Thu, 19 Feb 2026 14:47:08 +0100 Subject: [PATCH 3/3] test create node API and add start node API --- waku/wrapper.py | 91 +++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/waku/wrapper.py b/waku/wrapper.py index f2cba26..3403270 100644 --- a/waku/wrapper.py +++ b/waku/wrapper.py @@ -1,52 +1,75 @@ +import json from cffi import FFI from pathlib import Path -import json - -config = { - "relay": True, - "discv5Discovery": True, - "peerExchange": True, - "clusterId": 3, - "shard": 0, - "rlnRelay": False -} -config_json1 = json.dumps(config) ffi = FFI() +ffi.cdef(""" +typedef void (*FFICallBack)(int callerRet, const char *msg, size_t len, void *userData); + +void *logosdelivery_create_node( + const char *configJson, + FFICallBack callback, + void *userData +); + +int logosdelivery_start_node( + void *ctx, + FFICallBack callback, + void *userData +); +""") + _repo_root = Path(__file__).resolve().parents[1] lib = ffi.dlopen(str(_repo_root / "lib" / "liblogosdelivery.so")) -ffi.cdef(""" - typedef void (*FFICallBack)(int callerRet, const char *msg, size_t len, void *userData); - - void *logosdelivery_create_node( - const char *configJson, - FFICallBack callback, - void *userData - ); -""") - -def process_callback(ret, char_p, length, callback): - byte_string = ffi.buffer(char_p, length)[:] if char_p != ffi.NULL and length else b"" - callback(ret, byte_string) - CallbackType = ffi.callback("void(int, const char*, size_t, void*)") -def logosdelivery_create_node(config_json, callback): - def cb(ret, char_p, length, userData): - process_callback(ret, char_p, length, callback) +class NodeHandle: + def __init__(self, ctx, cb_handle): + self.ctx = ctx + self._cb_handle = cb_handle # keep callback alive - return lib.logosdelivery_create_node( - config_json.encode("utf-8"), - CallbackType(cb), - ffi.cast("void*", 0), +def logosdelivery_create_node(config: dict, py_callback): + config_json = json.dumps(config, separators=(",", ":"), ensure_ascii=False) + cnfig_bytes = config_json.encode("utf-8") + + def c_cb(ret, char_p, length, userData): + if char_p != ffi.NULL and length : + msg = ffi.buffer(char_p, length)[:] + else : + msg = b"" + py_callback(ret, msg) + + cb_handle = CallbackType(c_cb) + ctx = lib.logosdelivery_create_node( + cnfig_bytes, + cb_handle, + ffi.NULL, ) + return NodeHandle(ctx, cb_handle) if __name__ == "__main__": + config = { + "logLevel": "DEBUG", + "mode": "Core", + "protocolsConfig": { + "entryNodes": [ + "/dns4/node-01.do-ams3.misc.logos-chat.status.im/tcp/30303/p2p/16Uiu2HAkxoqUTud5LUPQBRmkeL2xP4iKx2kaABYXomQRgmLUgf78" + ], + "clusterId": 3, + "autoShardingConfig": {"numShardsInCluster": 8}, + }, + "networkingConfig": { + "listenIpv4": "0.0.0.0", + "p2pTcpPort": 60000, + "discv5UdpPort": 9000, + }, + } + def cb(ret, msg): print("ret:", ret) print("msg:", msg) - ctx = logosdelivery_create_node(config_json1, cb) - print("ctx:", ctx) \ No newline at end of file + h = logosdelivery_create_node(config, cb) + print("ctx:", h.ctx)