2026-07-23 11:06:01 +01:00
|
|
|
import json
|
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
from cffi import FFI
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from result import Result, Ok, Err
|
|
|
|
|
|
|
|
|
|
ffi = FFI()
|
|
|
|
|
|
|
|
|
|
ffi.cdef(
|
|
|
|
|
"""
|
2026-08-06 23:53:38 -03:00
|
|
|
// Raw FFICallBack, used by the event listener registry and by the
|
|
|
|
|
// scalar-fast-path exports (no string arguments).
|
2026-07-23 11:06:01 +01:00
|
|
|
typedef void (*FFICallBack)(int callerRet, const char *msg, size_t len, void *userData);
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
// Reply callback of the `abi = c` exports that take arguments. `reply` and
|
|
|
|
|
// `errMsg` are NUL-terminated and valid only for the duration of the call.
|
|
|
|
|
typedef void (*ReplyFn)(int errCode, const char *reply, const char *errMsg, void *userData);
|
|
|
|
|
|
|
|
|
|
// The constructor reports the context address as decimal text.
|
|
|
|
|
typedef void (*CreateRawFn)(int errCode, const char *ctxAddr, const char *errMsg, void *userData);
|
|
|
|
|
|
|
|
|
|
typedef struct { const char *configJson; } CreateNodeCtorReq;
|
|
|
|
|
typedef struct { const char *contentTopicStr; } SubscribeReq;
|
|
|
|
|
typedef struct { const char *contentTopicStr; } UnsubscribeReq;
|
|
|
|
|
typedef struct { const char *messageJson; } SendReq;
|
|
|
|
|
typedef struct { const char *nodeInfoId; } GetNodeInfoReq;
|
|
|
|
|
|
2026-07-23 11:06:01 +01:00
|
|
|
void *logosdelivery_create_node(
|
2026-08-06 23:53:38 -03:00
|
|
|
const CreateNodeCtorReq *req,
|
|
|
|
|
CreateRawFn onCreated,
|
2026-07-23 11:06:01 +01:00
|
|
|
void *userData
|
|
|
|
|
);
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
int logosdelivery_destroy(void *ctx);
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
int logosdelivery_start_node(void *ctx, FFICallBack callback, void *userData);
|
|
|
|
|
int logosdelivery_stop_node(void *ctx, FFICallBack callback, void *userData);
|
|
|
|
|
int logosdelivery_get_available_node_info_ids(void *ctx, FFICallBack callback, void *userData);
|
|
|
|
|
int logosdelivery_get_available_configs(void *ctx, FFICallBack callback, void *userData);
|
|
|
|
|
|
|
|
|
|
int logosdelivery_subscribe(void *ctx, ReplyFn onReply, void *userData, const SubscribeReq *req);
|
|
|
|
|
int logosdelivery_unsubscribe(void *ctx, ReplyFn onReply, void *userData, const UnsubscribeReq *req);
|
|
|
|
|
int logosdelivery_send(void *ctx, ReplyFn onReply, void *userData, const SendReq *req);
|
|
|
|
|
int logosdelivery_get_node_info(void *ctx, ReplyFn onReply, void *userData, const GetNodeInfoReq *req);
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-07-31 13:50:59 -03:00
|
|
|
uint64_t logosdelivery_add_event_listener(
|
2026-07-23 11:06:01 +01:00
|
|
|
void *ctx,
|
2026-07-31 13:50:59 -03:00
|
|
|
const char *eventName,
|
2026-07-23 11:06:01 +01:00
|
|
|
FFICallBack callback,
|
|
|
|
|
void *userData
|
|
|
|
|
);
|
|
|
|
|
|
2026-07-31 13:50:59 -03:00
|
|
|
int logosdelivery_remove_event_listener(
|
|
|
|
|
void *ctx,
|
|
|
|
|
uint64_t listenerId
|
|
|
|
|
);
|
test(e2e): port remaining wrapper tests from the interop repo (#4077)
* test(e2e): port remaining wrapper tests from the interop repo
The wrapper suite that moved into tests-e2e (#4027) was a reworked subset of
the one still living in logos-delivery-interop-tests. Comparing both sides
showed 21 tests here against 46 there, with no overlap in the delta: the 25
missing tests cover scenarios the reworked set never included.
Ports those 25 tests, bringing the in-repo suite to the full 46:
- 12 send scenarios: s01 (nil/destroyed handle), s03, s04, s05, s11, s13,
s16, s18 (both orderings), s25, s29
- 7 channel lifecycle tests (rc01-rc04)
- 6 wrapper corner cases: auto port allocation, MyBoundPorts, ENR
Supporting changes the ported tests need:
- wrapper_helpers: get_node_tcp_port, get_node_bound_ports, enr_udp_port
- WrapperManager: channel_create/send/close, destroy_keep_ctx
- vendored binding refreshed to the revision exposing the channel API
(additive only; cffi resolves symbols lazily, so nothing existing moves)
Two Edge senders were fixed while porting. build_node_config defaults relay
and store to True, and the flat-JSON config path applies mode=Edge before
explicit fields, so those defaults win: the Edge nodes in s11/s16/s25 came up
as relay and store servers and exercised the relay path instead of lightpush.
They now set relay=False and store=False, matching test_send_e2e_part2. s16
also dropped lightpush=True, which mounts the lightpush server and fails node
start once relay is off; the lightpush client mounts unconditionally.
Suite goes from 21 to 46 functions (53 collected). The docker subset grows
from 3 to 5 as s11 and s25 need a store peer. Local run against a freshly
built library: 45 passed, 2 skipped, 1 xfailed.
* test(e2e): enable autosharding in the channel lifecycle tests
channel_create subscribes to the channel's content topic since #4081, and
resolving that topic to a shard needs autosharding. build_node_config leaves
numShardsInNetwork at 0 and cluster 198 has no preset, so these nodes came up
with static sharding and every channel_create failed with "autosharding is not
configured; pass an explicit shard".
Adds numShardsInNetwork=1 to the six tests that create a channel, matching what
every other wrapper test that touches the send or channel API already does.
rc02 is left alone: channel_send rejects on the id lookup before any shard is
resolved.
Verified locally against a fresh build: the five tests that complete now pass
and the error string is gone from the run.
2026-08-10 08:36:28 +01:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
const char *channelIdStr;
|
|
|
|
|
const char *contentTopicStr;
|
|
|
|
|
const char *senderIdStr;
|
|
|
|
|
} ChannelCreateReq;
|
|
|
|
|
typedef struct { const char *channelIdStr; const char *messageJson; } ChannelSendReq;
|
|
|
|
|
typedef struct { const char *channelIdStr; } ChannelCloseReq;
|
|
|
|
|
|
|
|
|
|
int logosdelivery_channel_create(void *ctx, ReplyFn onReply, void *userData, const ChannelCreateReq *req);
|
|
|
|
|
int logosdelivery_channel_send(void *ctx, ReplyFn onReply, void *userData, const ChannelSendReq *req);
|
|
|
|
|
int logosdelivery_channel_close(void *ctx, ReplyFn onReply, void *userData, const ChannelCloseReq *req);
|
2026-07-23 11:06:01 +01:00
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
_repo_root = Path(__file__).resolve().parents[1]
|
|
|
|
|
lib = ffi.dlopen(str(_repo_root / "lib" / "liblogosdelivery.so"))
|
|
|
|
|
|
|
|
|
|
CallbackType = ffi.callback("void(int, const char*, size_t, void*)")
|
2026-08-06 23:53:38 -03:00
|
|
|
ReplyCallbackType = ffi.callback("void(int, const char*, const char*, void*)")
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
# Non-terminal progress tick (~every 5s while a request is in flight), always
|
|
|
|
|
# followed by a terminal RET_OK/RET_ERR. The waiting callbacks drop it so a slow
|
|
|
|
|
# call (start_node most of all) is not latched as a result.
|
2026-07-31 13:50:59 -03:00
|
|
|
RET_STALE_WARN = 3
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
# Every event the library emits. Since 0.3.0 a listener is registered per event
|
|
|
|
|
# name, so an `event_cb` that wants them all registers once per name.
|
2026-07-31 13:50:59 -03:00
|
|
|
EVENT_NAMES = (
|
|
|
|
|
"onMessageSent",
|
|
|
|
|
"onMessageError",
|
|
|
|
|
"onMessagePropagated",
|
|
|
|
|
"onMessageReceived",
|
|
|
|
|
"onConnectionStatusChange",
|
|
|
|
|
"onTopicHealthChange",
|
|
|
|
|
"onConnectionChange",
|
|
|
|
|
"onReceivedMessage",
|
|
|
|
|
"onChannelMessageReceived",
|
|
|
|
|
"onChannelMessageSent",
|
|
|
|
|
"onChannelMessageError",
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
def _new_cb_state():
|
|
|
|
|
return {
|
|
|
|
|
"done": threading.Event(),
|
|
|
|
|
"ret": None,
|
|
|
|
|
"msg": b"",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _wait_cb_raw(
|
|
|
|
|
state,
|
|
|
|
|
op_name: str,
|
|
|
|
|
timeout_s: float = 20.0,
|
|
|
|
|
) -> Result[tuple[int, bytes], str]:
|
|
|
|
|
ok = state["done"].wait(timeout_s)
|
|
|
|
|
if not ok:
|
|
|
|
|
return Err(f"{op_name}: timeout after {timeout_s}s")
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
if state["ret"] is None:
|
2026-07-23 11:06:01 +01:00
|
|
|
return Err(f"{op_name}: callback ret is None")
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
return Ok((state["ret"], state["msg"]))
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def _wait_cb_ok(state, op_name: str, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
wait_result = _wait_cb_raw(state, op_name, timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(f"callback failed in _wait_cb_ok: {op_name} (ret={cb_ret}) msg={cb_msg!r}")
|
|
|
|
|
|
|
|
|
|
return Ok(cb_ret)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NodeWrapper:
|
2026-07-31 13:50:59 -03:00
|
|
|
def __init__(self, ctx, config_buffer, event_cb_handler, listener_ids=()):
|
2026-07-23 11:06:01 +01:00
|
|
|
self.ctx = ctx
|
|
|
|
|
self._config_buffer = config_buffer
|
|
|
|
|
self._event_cb_handler = event_cb_handler
|
2026-07-31 13:50:59 -03:00
|
|
|
self._listener_ids = tuple(listener_ids)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def _make_waiting_cb(state):
|
|
|
|
|
def c_cb(ret, char_p, length, userData):
|
2026-07-31 13:50:59 -03:00
|
|
|
if int(ret) == RET_STALE_WARN:
|
|
|
|
|
return
|
|
|
|
|
|
2026-07-23 11:06:01 +01:00
|
|
|
msg = ffi.buffer(char_p, length)[:] if char_p != ffi.NULL else b""
|
|
|
|
|
|
|
|
|
|
if not state["done"].is_set():
|
|
|
|
|
state["ret"] = int(ret)
|
|
|
|
|
state["msg"] = msg
|
|
|
|
|
state["done"].set()
|
|
|
|
|
|
|
|
|
|
return CallbackType(c_cb)
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
@staticmethod
|
|
|
|
|
def _make_waiting_reply_cb(state):
|
|
|
|
|
def c_cb(err_code, reply_p, err_p, userData):
|
|
|
|
|
if int(err_code) == RET_STALE_WARN:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
text_p = reply_p if int(err_code) == 0 else err_p
|
|
|
|
|
msg = ffi.string(text_p) if text_p != ffi.NULL else b""
|
|
|
|
|
|
|
|
|
|
if not state["done"].is_set():
|
|
|
|
|
state["ret"] = int(err_code)
|
|
|
|
|
state["msg"] = msg
|
|
|
|
|
state["done"].set()
|
|
|
|
|
|
|
|
|
|
return ReplyCallbackType(c_cb)
|
|
|
|
|
|
2026-07-23 11:06:01 +01:00
|
|
|
@staticmethod
|
|
|
|
|
def _make_event_cb(py_callback):
|
|
|
|
|
def c_cb(ret, char_p, length, userData):
|
|
|
|
|
msg = ffi.buffer(char_p, length)[:] if char_p != ffi.NULL else b""
|
|
|
|
|
py_callback(int(ret), msg)
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
return CallbackType(c_cb)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def create_node(
|
|
|
|
|
cls,
|
|
|
|
|
config: dict,
|
|
|
|
|
event_cb=None,
|
|
|
|
|
*,
|
|
|
|
|
timeout_s: float = 20.0,
|
|
|
|
|
) -> Result["NodeWrapper", str]:
|
|
|
|
|
config_json = json.dumps(config, separators=(",", ":"), ensure_ascii=False)
|
|
|
|
|
config_buffer = ffi.new("char[]", config_json.encode("utf-8"))
|
|
|
|
|
|
|
|
|
|
state = _new_cb_state()
|
2026-08-06 23:53:38 -03:00
|
|
|
cb = cls._make_waiting_reply_cb(state)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
req = ffi.new("CreateNodeCtorReq *", {"configJson": config_buffer})
|
|
|
|
|
lib.logosdelivery_create_node(req, cb, ffi.NULL)
|
2026-07-31 13:50:59 -03:00
|
|
|
|
2026-07-23 11:06:01 +01:00
|
|
|
wait_result = _wait_cb_ok(state, "create_node", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
# The constructor reports the context address as decimal text.
|
|
|
|
|
try:
|
|
|
|
|
ctx = ffi.cast("void *", int(state["msg"].decode("utf-8")))
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return Err(f"create_node: invalid context address: {e}")
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
if ctx == ffi.NULL:
|
|
|
|
|
return Err("create_node: ctx is NULL")
|
|
|
|
|
|
|
|
|
|
event_cb_handler = None
|
|
|
|
|
listener_ids = []
|
|
|
|
|
if event_cb is not None:
|
|
|
|
|
event_cb_handler = cls._make_event_cb(event_cb)
|
|
|
|
|
for event_name in EVENT_NAMES:
|
|
|
|
|
listener_id = lib.logosdelivery_add_event_listener(
|
|
|
|
|
ctx,
|
|
|
|
|
event_name.encode("utf-8"),
|
|
|
|
|
event_cb_handler,
|
|
|
|
|
ffi.NULL,
|
|
|
|
|
)
|
|
|
|
|
if listener_id == 0:
|
|
|
|
|
return Err(f"create_node: add_event_listener({event_name}) failed")
|
|
|
|
|
listener_ids.append(listener_id)
|
|
|
|
|
|
|
|
|
|
return Ok(cls(ctx, config_buffer, event_cb_handler, listener_ids))
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def create_and_start(
|
|
|
|
|
cls,
|
|
|
|
|
config: dict,
|
|
|
|
|
event_cb=None,
|
|
|
|
|
*,
|
|
|
|
|
timeout_s: float = 20.0,
|
|
|
|
|
) -> Result["NodeWrapper", str]:
|
|
|
|
|
node_result = cls.create_node(
|
|
|
|
|
config=config,
|
|
|
|
|
event_cb=event_cb,
|
|
|
|
|
timeout_s=timeout_s,
|
|
|
|
|
)
|
|
|
|
|
if node_result.is_err():
|
|
|
|
|
return Err(node_result.err())
|
|
|
|
|
|
|
|
|
|
node = node_result.ok_value
|
|
|
|
|
|
|
|
|
|
start_result = node.start_node(timeout_s=timeout_s)
|
|
|
|
|
if start_result.is_err():
|
2026-07-31 13:50:59 -03:00
|
|
|
# The caller drops the node here, so tear it down before its
|
|
|
|
|
# callbacks outlive the wrapper that owns them.
|
|
|
|
|
node.destroy(timeout_s=timeout_s)
|
2026-07-23 11:06:01 +01:00
|
|
|
return Err(start_result.err())
|
|
|
|
|
|
|
|
|
|
return Ok(node)
|
|
|
|
|
|
|
|
|
|
def start_node(self, *, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_cb(state)
|
|
|
|
|
|
|
|
|
|
rc = lib.logosdelivery_start_node(self.ctx, cb, ffi.NULL)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"start_node: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
return _wait_cb_ok(state, "start_node", timeout_s)
|
|
|
|
|
|
|
|
|
|
def stop_node(self, *, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_cb(state)
|
|
|
|
|
|
|
|
|
|
rc = lib.logosdelivery_stop_node(self.ctx, cb, ffi.NULL)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"stop_node: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
return _wait_cb_ok(state, "stop_node", timeout_s)
|
|
|
|
|
|
|
|
|
|
def destroy(self, *, timeout_s: float = 20.0) -> Result[int, str]:
|
2026-07-31 13:50:59 -03:00
|
|
|
if self.ctx == ffi.NULL:
|
2026-08-06 23:53:38 -03:00
|
|
|
return Ok(0)
|
2026-07-31 13:50:59 -03:00
|
|
|
|
|
|
|
|
# Drop the listeners first so the event thread cannot reach the Python
|
|
|
|
|
# callback once the context is gone.
|
|
|
|
|
for listener_id in self._listener_ids:
|
|
|
|
|
lib.logosdelivery_remove_event_listener(self.ctx, listener_id)
|
|
|
|
|
self._listener_ids = ()
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
rc = lib.logosdelivery_destroy(self.ctx)
|
2026-07-23 11:06:01 +01:00
|
|
|
if rc != 0:
|
2026-08-06 23:53:38 -03:00
|
|
|
return Err(f"destroy: call failed (ret={rc})")
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
self.ctx = ffi.NULL
|
2026-08-06 23:53:38 -03:00
|
|
|
return Ok(rc)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
def stop_and_destroy(self, *, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
stop_result = self.stop_node(timeout_s=timeout_s)
|
2026-07-31 13:50:59 -03:00
|
|
|
|
|
|
|
|
# Destroy even when the stop fails: a node that keeps its context alive
|
|
|
|
|
# also keeps calling back into a wrapper the caller is about to drop.
|
|
|
|
|
destroy_result = self.destroy(timeout_s=timeout_s)
|
|
|
|
|
|
2026-07-23 11:06:01 +01:00
|
|
|
if stop_result.is_err():
|
|
|
|
|
return Err(stop_result.err())
|
|
|
|
|
|
2026-07-31 13:50:59 -03:00
|
|
|
return destroy_result
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
def subscribe_content_topic(self, content_topic: str, *, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
state = _new_cb_state()
|
2026-08-06 23:53:38 -03:00
|
|
|
cb = self._make_waiting_reply_cb(state)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
topic_buffer = ffi.new("char[]", content_topic.encode("utf-8"))
|
|
|
|
|
req = ffi.new("SubscribeReq *", {"contentTopicStr": topic_buffer})
|
|
|
|
|
rc = lib.logosdelivery_subscribe(self.ctx, cb, ffi.NULL, req)
|
2026-07-23 11:06:01 +01:00
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"subscribe_content_topic: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
return _wait_cb_ok(state, f"subscribe({content_topic})", timeout_s)
|
|
|
|
|
|
|
|
|
|
def unsubscribe_content_topic(self, content_topic: str, *, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
state = _new_cb_state()
|
2026-08-06 23:53:38 -03:00
|
|
|
cb = self._make_waiting_reply_cb(state)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
topic_buffer = ffi.new("char[]", content_topic.encode("utf-8"))
|
|
|
|
|
req = ffi.new("UnsubscribeReq *", {"contentTopicStr": topic_buffer})
|
|
|
|
|
rc = lib.logosdelivery_unsubscribe(self.ctx, cb, ffi.NULL, req)
|
2026-07-23 11:06:01 +01:00
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"unsubscribe_content_topic: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
return _wait_cb_ok(state, f"unsubscribe({content_topic})", timeout_s)
|
|
|
|
|
|
|
|
|
|
def send_message(self, message: dict, *, timeout_s: float = 20.0) -> Result[str, str]:
|
|
|
|
|
state = _new_cb_state()
|
2026-08-06 23:53:38 -03:00
|
|
|
cb = self._make_waiting_reply_cb(state)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
message_json = json.dumps(message, separators=(",", ":"), ensure_ascii=False)
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
message_buffer = ffi.new("char[]", message_json.encode("utf-8"))
|
|
|
|
|
req = ffi.new("SendReq *", {"messageJson": message_buffer})
|
|
|
|
|
rc = lib.logosdelivery_send(self.ctx, cb, ffi.NULL, req)
|
2026-07-23 11:06:01 +01:00
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"send_message: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, "send_message", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(f"send_message: callback failed (ret={cb_ret}) msg={cb_msg!r}")
|
|
|
|
|
|
|
|
|
|
request_id = cb_msg.decode("utf-8") if cb_msg else ""
|
|
|
|
|
return Ok(request_id)
|
|
|
|
|
|
|
|
|
|
def get_available_node_info_ids(self, *, timeout_s: float = 20.0) -> Result[list[str], str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_cb(state)
|
|
|
|
|
|
|
|
|
|
rc = lib.logosdelivery_get_available_node_info_ids(self.ctx, cb, ffi.NULL)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"get_available_node_info_ids: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, "get_available_node_info_ids", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(f"get_available_node_info_ids: callback failed (ret={cb_ret})")
|
|
|
|
|
if not cb_msg:
|
|
|
|
|
return Err("get_available_node_info_ids: empty response")
|
|
|
|
|
|
|
|
|
|
try:
|
2026-08-06 23:53:38 -03:00
|
|
|
return Ok(json.loads(cb_msg.decode("utf-8")))
|
2026-07-23 11:06:01 +01:00
|
|
|
except Exception as e:
|
|
|
|
|
return Err(f"get_available_node_info_ids: invalid response: {e}")
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
def get_node_info(self, node_info_id: str, *, timeout_s: float = 20.0) -> Result[str, str]:
|
2026-07-23 11:06:01 +01:00
|
|
|
state = _new_cb_state()
|
2026-08-06 23:53:38 -03:00
|
|
|
cb = self._make_waiting_reply_cb(state)
|
2026-07-23 11:06:01 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
info_id_buffer = ffi.new("char[]", node_info_id.encode("utf-8"))
|
|
|
|
|
req = ffi.new("GetNodeInfoReq *", {"nodeInfoId": info_id_buffer})
|
|
|
|
|
rc = lib.logosdelivery_get_node_info(self.ctx, cb, ffi.NULL, req)
|
2026-07-23 11:06:01 +01:00
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"get_node_info: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, "get_node_info", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(f"get_node_info: callback failed (ret={cb_ret}) msg={cb_msg!r}")
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
# The item is a plain string, not JSON: a peer id, an ENR URI, a
|
|
|
|
|
# comma-separated multiaddress list or the Prometheus metrics text.
|
|
|
|
|
# MyMixPubKey is legitimately empty when mix is not mounted.
|
|
|
|
|
return Ok(cb_msg.decode("utf-8"))
|
2026-07-23 11:06:01 +01:00
|
|
|
|
|
|
|
|
def get_available_configs(self, *, timeout_s: float = 20.0) -> Result[dict, str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_cb(state)
|
|
|
|
|
|
|
|
|
|
rc = lib.logosdelivery_get_available_configs(self.ctx, cb, ffi.NULL)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"get_available_configs: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, "get_available_configs", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(f"get_available_configs: callback failed (ret={cb_ret}) msg={cb_msg!r}")
|
|
|
|
|
|
|
|
|
|
if not cb_msg:
|
|
|
|
|
return Err("get_available_configs: empty response")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
result = json.loads(cb_msg.decode("utf-8"))
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return Err(f"get_available_configs: invalid json: {e}")
|
|
|
|
|
|
|
|
|
|
return Ok(result)
|
|
|
|
|
|
test(e2e): port remaining wrapper tests from the interop repo (#4077)
* test(e2e): port remaining wrapper tests from the interop repo
The wrapper suite that moved into tests-e2e (#4027) was a reworked subset of
the one still living in logos-delivery-interop-tests. Comparing both sides
showed 21 tests here against 46 there, with no overlap in the delta: the 25
missing tests cover scenarios the reworked set never included.
Ports those 25 tests, bringing the in-repo suite to the full 46:
- 12 send scenarios: s01 (nil/destroyed handle), s03, s04, s05, s11, s13,
s16, s18 (both orderings), s25, s29
- 7 channel lifecycle tests (rc01-rc04)
- 6 wrapper corner cases: auto port allocation, MyBoundPorts, ENR
Supporting changes the ported tests need:
- wrapper_helpers: get_node_tcp_port, get_node_bound_ports, enr_udp_port
- WrapperManager: channel_create/send/close, destroy_keep_ctx
- vendored binding refreshed to the revision exposing the channel API
(additive only; cffi resolves symbols lazily, so nothing existing moves)
Two Edge senders were fixed while porting. build_node_config defaults relay
and store to True, and the flat-JSON config path applies mode=Edge before
explicit fields, so those defaults win: the Edge nodes in s11/s16/s25 came up
as relay and store servers and exercised the relay path instead of lightpush.
They now set relay=False and store=False, matching test_send_e2e_part2. s16
also dropped lightpush=True, which mounts the lightpush server and fails node
start once relay is off; the lightpush client mounts unconditionally.
Suite goes from 21 to 46 functions (53 collected). The docker subset grows
from 3 to 5 as s11 and s25 need a store peer. Local run against a freshly
built library: 45 passed, 2 skipped, 1 xfailed.
* test(e2e): enable autosharding in the channel lifecycle tests
channel_create subscribes to the channel's content topic since #4081, and
resolving that topic to a shard needs autosharding. build_node_config leaves
numShardsInNetwork at 0 and cluster 198 has no preset, so these nodes came up
with static sharding and every channel_create failed with "autosharding is not
configured; pass an explicit shard".
Adds numShardsInNetwork=1 to the six tests that create a channel, matching what
every other wrapper test that touches the send or channel API already does.
rc02 is left alone: channel_send rejects on the id lookup before any shard is
resolved.
Verified locally against a fresh build: the five tests that complete now pass
and the error string is gone from the run.
2026-08-10 08:36:28 +01:00
|
|
|
|
|
|
|
|
def destroy_keep_ctx(self, *, timeout_s: float = 20.0) -> Result[int, str]:
|
|
|
|
|
"""Destroy the node without nilling self.ctx afterwards.
|
|
|
|
|
|
|
|
|
|
Lets a library-contract test reach the C side with a dangling-but-non-nil
|
|
|
|
|
pointer, instead of relying on the binding's defensive nil-out.
|
|
|
|
|
"""
|
|
|
|
|
rc = lib.logosdelivery_destroy(self.ctx)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"destroy_keep_ctx: call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
return Ok(rc)
|
|
|
|
|
|
|
|
|
|
def channel_create(
|
|
|
|
|
self,
|
|
|
|
|
channel_id: str,
|
|
|
|
|
content_topic: str,
|
|
|
|
|
sender_id: str,
|
|
|
|
|
*,
|
|
|
|
|
timeout_s: float = 20.0,
|
|
|
|
|
) -> Result[str, str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_reply_cb(state)
|
|
|
|
|
|
|
|
|
|
channel_buffer = ffi.new("char[]", channel_id.encode("utf-8"))
|
|
|
|
|
topic_buffer = ffi.new("char[]", content_topic.encode("utf-8"))
|
|
|
|
|
sender_buffer = ffi.new("char[]", sender_id.encode("utf-8"))
|
|
|
|
|
req = ffi.new(
|
|
|
|
|
"ChannelCreateReq *",
|
|
|
|
|
{
|
|
|
|
|
"channelIdStr": channel_buffer,
|
|
|
|
|
"contentTopicStr": topic_buffer,
|
|
|
|
|
"senderIdStr": sender_buffer,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
rc = lib.logosdelivery_channel_create(self.ctx, cb, ffi.NULL, req)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"channel_create: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, f"channel_create({channel_id})", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(cb_msg.decode("utf-8") if cb_msg else f"channel_create({channel_id}): callback failed (ret={cb_ret})")
|
|
|
|
|
|
|
|
|
|
return Ok(cb_msg.decode("utf-8") if cb_msg else "")
|
|
|
|
|
|
|
|
|
|
def channel_send(self, channel_id: str, message: dict, *, timeout_s: float = 20.0) -> Result[str, str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_reply_cb(state)
|
|
|
|
|
|
|
|
|
|
message_json = json.dumps(message, separators=(",", ":"), ensure_ascii=False)
|
|
|
|
|
|
|
|
|
|
channel_buffer = ffi.new("char[]", channel_id.encode("utf-8"))
|
|
|
|
|
message_buffer = ffi.new("char[]", message_json.encode("utf-8"))
|
|
|
|
|
req = ffi.new("ChannelSendReq *", {"channelIdStr": channel_buffer, "messageJson": message_buffer})
|
|
|
|
|
rc = lib.logosdelivery_channel_send(self.ctx, cb, ffi.NULL, req)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"channel_send: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, f"channel_send({channel_id})", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(cb_msg.decode("utf-8") if cb_msg else f"channel_send({channel_id}): callback failed (ret={cb_ret})")
|
|
|
|
|
|
|
|
|
|
return Ok(cb_msg.decode("utf-8") if cb_msg else "")
|
|
|
|
|
|
|
|
|
|
def channel_close(self, channel_id: str, *, timeout_s: float = 20.0) -> Result[str, str]:
|
|
|
|
|
state = _new_cb_state()
|
|
|
|
|
cb = self._make_waiting_reply_cb(state)
|
|
|
|
|
|
|
|
|
|
channel_buffer = ffi.new("char[]", channel_id.encode("utf-8"))
|
|
|
|
|
req = ffi.new("ChannelCloseReq *", {"channelIdStr": channel_buffer})
|
|
|
|
|
rc = lib.logosdelivery_channel_close(self.ctx, cb, ffi.NULL, req)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
return Err(f"channel_close: immediate call failed (ret={rc})")
|
|
|
|
|
|
|
|
|
|
wait_result = _wait_cb_raw(state, f"channel_close({channel_id})", timeout_s)
|
|
|
|
|
if wait_result.is_err():
|
|
|
|
|
return Err(wait_result.err())
|
|
|
|
|
|
|
|
|
|
cb_ret, cb_msg = wait_result.ok_value
|
|
|
|
|
if cb_ret != 0:
|
|
|
|
|
return Err(cb_msg.decode("utf-8") if cb_msg else f"channel_close({channel_id}): callback failed (ret={cb_ret})")
|
|
|
|
|
|
|
|
|
|
return Ok(cb_msg.decode("utf-8") if cb_msg else "")
|