mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-22 12:39:30 +00:00
* remove --mode from the CLI * move WakuMode to the messaging layer * expose store backend (db url, max connections) and a remote store node on the messaging surface * wakunode2 with no flags now runs as a full service node (store still opt-in) * add rateLimitMessagesPerEpoch * channel rate-limiting auto-enables if epochPeriodSec or messagesPerEpoch is set * fix JSON conf parser to be generic (works over all config types) * messaging config = mode + preset + messagingOverrides + channelsOverrides * add full messaging plus selective kernel config options to MessagingClientConf * mode (Core/Edge) expands to kernel protocol flags in the messaging layer * create_node parses the messaging config, drops the flat WakuNodeConf JSON entrypoint * wire channelsOverrides (segmentation/SDS/rate-limit) into channel creation * fix liblogosdelivery.h comments and README for the new config shape * messaging conf tests: switch names, reject-unknown, set-twice, field->kernel * add kernel log-level, log-format, nodekey to the messaging surface * Port 0 (ephemeral) default for messaging entry points * KernelConf alias for WakuNodeConf * rewrite the FFI examples to the new config shape * C/C++ examples use preset status.prod * drop operator-only confs from the examples * remove duplicate tests & misc test fixes * Delete p2pReliability from Kernel (Waku) resolver and config (keep preset definition) * Delete NodeConfig API (deprecation completed by p2pReliability removal from kernel) * Rename test_messaging_conf.nim to test_conf.nim (tests Logos Delivery config in general) * Rename messaging_conf_json.nim to logos_delivery_conf_json.nim * Add logos_delivery_conf.nim (defines LogosDeliveryConf aggregate) * misc docs/comments cleanups
114 lines
3.4 KiB
Rust
114 lines
3.4 KiB
Rust
use std::cell::OnceCell;
|
|
use std::ffi::CString;
|
|
use std::os::raw::{c_char, c_int, c_void};
|
|
use std::{slice, thread, time};
|
|
|
|
pub type FFICallBack = unsafe extern "C" fn(c_int, *const c_char, usize, *const c_void);
|
|
|
|
extern "C" {
|
|
pub fn logosdelivery_create_node(
|
|
config_json: *const u8,
|
|
cb: FFICallBack,
|
|
user_data: *const c_void,
|
|
) -> *mut c_void;
|
|
|
|
pub fn waku_version(ctx: *const c_void, cb: FFICallBack, user_data: *const c_void) -> c_int;
|
|
|
|
pub fn logosdelivery_start_node(ctx: *const c_void, cb: FFICallBack, user_data: *const c_void) -> c_int;
|
|
|
|
pub fn waku_default_pubsub_topic(
|
|
ctx: *mut c_void,
|
|
cb: FFICallBack,
|
|
user_data: *const c_void,
|
|
) -> *mut c_void;
|
|
}
|
|
|
|
pub unsafe extern "C" fn trampoline<C>(
|
|
return_val: c_int,
|
|
buffer: *const c_char,
|
|
buffer_len: usize,
|
|
data: *const c_void,
|
|
) where
|
|
C: FnMut(i32, &str),
|
|
{
|
|
let closure = &mut *(data as *mut C);
|
|
|
|
let buffer_utf8 =
|
|
String::from_utf8(slice::from_raw_parts(buffer as *mut u8, buffer_len).to_vec())
|
|
.expect("valid utf8");
|
|
|
|
closure(return_val, &buffer_utf8);
|
|
}
|
|
|
|
pub fn get_trampoline<C>(_closure: &C) -> FFICallBack
|
|
where
|
|
C: FnMut(i32, &str),
|
|
{
|
|
trampoline::<C>
|
|
}
|
|
|
|
fn main() {
|
|
let config_json = "\
|
|
{ \
|
|
\"mode\": \"Core\",\
|
|
\"messagingOverrides\": { \
|
|
\"listen-address\": \"127.0.0.1\",\
|
|
\"tcp-port\": 60000, \
|
|
\"nodekey\": \"0d714a1fada214dead6dc9c7274581ec20ff292451866e7d6d677dc818e8ccd2\", \
|
|
\"log-level\": \"DEBUG\"
|
|
}
|
|
}";
|
|
|
|
unsafe {
|
|
// Create the waku node
|
|
let closure = |ret: i32, data: &str| {
|
|
println!("Ret {ret}. logosdelivery_create_node closure called {data}");
|
|
};
|
|
let cb = get_trampoline(&closure);
|
|
let config_json_str = CString::new(config_json).unwrap();
|
|
let ctx = logosdelivery_create_node(
|
|
config_json_str.as_ptr() as *const u8,
|
|
cb,
|
|
&closure as *const _ as *const c_void,
|
|
);
|
|
|
|
// Extracting the current waku version
|
|
let version: OnceCell<String> = OnceCell::new();
|
|
let closure = |ret: i32, data: &str| {
|
|
println!("version_closure. Ret: {ret}. Data: {data}");
|
|
let _ = version.set(data.to_string());
|
|
};
|
|
let cb = get_trampoline(&closure);
|
|
let _ret = waku_version(
|
|
&ctx as *const _ as *const c_void,
|
|
cb,
|
|
&closure as *const _ as *const c_void,
|
|
);
|
|
|
|
// Extracting the default pubsub topic
|
|
let default_pubsub_topic: OnceCell<String> = OnceCell::new();
|
|
let closure = |_ret: i32, data: &str| {
|
|
let _ = default_pubsub_topic.set(data.to_string());
|
|
};
|
|
let cb = get_trampoline(&closure);
|
|
let _ret = waku_default_pubsub_topic(ctx, cb, &closure as *const _ as *const c_void);
|
|
|
|
println!("Version: {}", version.get_or_init(|| unreachable!()));
|
|
println!(
|
|
"Default pubsubTopic: {}",
|
|
default_pubsub_topic.get_or_init(|| unreachable!())
|
|
);
|
|
|
|
// Start the Waku node
|
|
let closure = |ret: i32, data: &str| {
|
|
println!("Ret {ret}. logosdelivery_start_node closure called {data}");
|
|
};
|
|
let cb = get_trampoline(&closure);
|
|
let _ret = logosdelivery_start_node(ctx, cb, &closure as *const _ as *const c_void);
|
|
}
|
|
|
|
loop {
|
|
thread::sleep(time::Duration::from_millis(10000));
|
|
}
|
|
}
|