fix(ffi): Config parameters (#2949)

Co-authored-by: Daniel Sanchez <sanchez.quiros.daniel@gmail.com>
This commit is contained in:
Álex
2026-06-17 11:49:01 +02:00
committed by GitHub
co-authored by Daniel Sanchez
parent 93b44bd9ff
commit 6d8be574dd
7 changed files with 73 additions and 44 deletions
+21 -5
View File
@@ -10,9 +10,7 @@ use lb_node::cli::{EmbeddedInitArgs, InitArgs, MigrateArgs, ParticipateArgs, Upd
use multiaddr::Multiaddr;
use tokio::runtime::Runtime;
use crate::{
OperationStatus, api::types::config::Deployment, logging, return_error_if_null_pointer,
};
use crate::{OperationStatus, logging, return_error_if_null_pointer};
/// Converts a non-null C string pointer into a [`PathBuf`].
///
@@ -35,9 +33,10 @@ pub struct GenerateConfigArgs {
pub blend_port: *const u16,
pub http_addr: *const c_char,
pub external_address: *const c_char,
pub no_public_ip_check: *const bool,
pub deployment: *const Deployment,
pub state_path: *const c_char,
pub ibd: *const bool,
pub log_filter: *const c_char,
pub kms_file: *const c_char,
}
impl From<GenerateConfigArgs> for EmbeddedInitArgs {
@@ -103,6 +102,23 @@ impl From<GenerateConfigArgs> for EmbeddedInitArgs {
init_args.state_path = Some(state_path.to_string_lossy().to_string().into());
}
// ---- ibd ----
if !value.ibd.is_null() {
init_args.ibd = unsafe { *value.ibd };
}
// ---- log_filter ----
if !value.log_filter.is_null() {
let log_filter = unsafe { CStr::from_ptr(value.log_filter) };
init_args.log_filter = Some(log_filter.to_string_lossy().to_string());
}
// ---- kms_file ----
if !value.kms_file.is_null() {
let kms_file = unsafe { CStr::from_ptr(value.kms_file) };
init_args.kms_file = Some(kms_file.to_string_lossy().to_string().into());
}
init_args
}
}
-23
View File
@@ -1,23 +0,0 @@
use std::ffi::c_char;
#[repr(C)]
pub enum DeploymentType {
WellKnown = 0,
Custom = 1,
}
#[repr(C)]
pub enum WellKnownDeployment {
Devnet = 0,
}
#[repr(C)]
pub struct Deployment {
pub deployment_type: DeploymentType,
// Only valid if deployment_type is WellKnown.
pub well_known_deployment: WellKnownDeployment,
// Only valid if deployment_type is Custom.
pub custom_deployment_config_path: *const c_char,
}
-1
View File
@@ -1,5 +1,4 @@
pub mod block;
pub mod claimable_vouchers;
pub mod config;
pub mod known_addresses;
pub mod value;
+12 -11
View File
@@ -4,7 +4,7 @@ pub mod keys;
pub mod participate;
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
net::{Ipv4Addr, SocketAddr},
path::{Path, PathBuf},
};
@@ -20,8 +20,10 @@ use crate::{
},
config::{
ApiArgs, BlendArgs, CryptarchiaArgs, DeploymentArgs, DeploymentSettings, DeploymentType,
LogArgs, NetworkArgs, RunConfig, SdpArgs, StateArgs, UserConfig, update_api, update_blend,
update_cryptarchia, update_network, update_sdp, update_state, update_tracing,
LogArgs, NetworkArgs, RunConfig, SdpArgs, StateArgs, UserConfig,
api::serde::AxumBackendSettings, blend::serde::core::BackendConfig as BlendCoreConfig,
network::serde::SwarmConfig, update_api, update_blend, update_cryptarchia, update_network,
update_sdp, update_state, update_tracing,
},
};
@@ -223,11 +225,8 @@ impl From<EmbeddedInitArgs> for InitArgs {
.clone_from(&args.external_address);
init_args.network.initial_peers = Some(args.initial_peers.clone());
init_args.blend.blend_addr = Some(
format!("/ip4/0.0.0.0/tcp/{}", args.blend_port)
.parse()
.expect("Valid multiaddr structure"),
);
init_args.blend.blend_addr =
Some(BlendCoreConfig::default_listening_address(args.blend_port));
init_args.cryptarchia.ibd = args.ibd;
init_args.api.addr = Some(args.http_addr);
@@ -242,9 +241,11 @@ impl Default for EmbeddedInitArgs {
Self {
initial_peers: Vec::new(),
output: PathBuf::from("user_config.yaml"),
net_port: 3000,
blend_port: 3400,
http_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 3000),
net_port: SwarmConfig::default_port(),
blend_port: BlendCoreConfig::default_port(),
http_addr: AxumBackendSettings::default_listening_address(
AxumBackendSettings::default_port(),
),
external_address: None,
state_path: None,
ibd: false,
+14 -2
View File
@@ -18,7 +18,7 @@ pub struct Config {
pub struct AxumBackendSettings {
/// Listening address.
pub listen_address: core::net::SocketAddr,
/// Allowed origins for this server deployment requests.
/// Allowed origins for these server deployment requests.
pub cors_origins: Vec<String>,
/// Timeout for API requests in seconds.
#[serde_as(as = "serde_with::DurationSeconds<u64>")]
@@ -29,10 +29,22 @@ pub struct AxumBackendSettings {
pub max_concurrent_requests: u64,
}
impl AxumBackendSettings {
#[must_use]
pub const fn default_port() -> u16 {
8080
}
#[must_use]
pub fn default_listening_address(port: u16) -> core::net::SocketAddr {
SocketAddrV4::new(Ipv4Addr::LOCALHOST, port).into()
}
}
impl Default for AxumBackendSettings {
fn default() -> Self {
Self {
listen_address: SocketAddrV4::new(Ipv4Addr::LOCALHOST, 8080).into(),
listen_address: Self::default_listening_address(Self::default_port()),
cors_origins: Vec::default(),
timeout: Duration::from_secs(30),
max_body_size: 10 * 1024 * 1024,
@@ -26,10 +26,27 @@ pub struct BackendConfig {
pub max_dial_attempts_per_peer: NonZeroU64,
}
impl BackendConfig {
#[must_use]
pub const fn default_port() -> u16 {
3400
}
/// # Panics
///
/// This function will panic if the constructed multiaddr string is invalid.
#[must_use]
pub fn default_listening_address(port: u16) -> Multiaddr {
format!("/ip4/0.0.0.0/udp/{port}/quic-v1")
.parse()
.expect("Valid multiaddr structure")
}
}
impl Default for BackendConfig {
fn default() -> Self {
Self {
listening_address: "/ip4/0.0.0.0/udp/3400/quic-v1".parse().unwrap(),
listening_address: Self::default_listening_address(Self::default_port()),
core_peering_degree: 3..=5,
edge_node_connection_timeout: Duration::from_secs(1),
max_edge_node_incoming_connections: 300,
@@ -52,11 +52,18 @@ pub struct SwarmConfig {
pub nat: nat::Config,
}
impl SwarmConfig {
#[must_use]
pub const fn default_port() -> u16 {
3000
}
}
impl Default for SwarmConfig {
fn default() -> Self {
Self {
host: Ipv4Addr::UNSPECIFIED,
port: 3000,
port: Self::default_port(),
node_key: SecretKey::generate(),
gossipsub: gossipsub::Config::default(),
kademlia: kademlia::Config::default(),