mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-02-14 13:41:30 -05:00
add multi-subnode execution for veilid-server
This commit is contained in:
parent
766aca4502
commit
5f594e2aa7
@ -27,6 +27,7 @@ logging:
|
|||||||
enabled: false
|
enabled: false
|
||||||
testing:
|
testing:
|
||||||
subnode_index: 0
|
subnode_index: 0
|
||||||
|
subnode_count: 1
|
||||||
core:
|
core:
|
||||||
protected_store:
|
protected_store:
|
||||||
allow_insecure_fallback: true
|
allow_insecure_fallback: true
|
||||||
|
@ -138,6 +138,7 @@ otlp:
|
|||||||
```yaml
|
```yaml
|
||||||
testing:
|
testing:
|
||||||
subnode_index: 0
|
subnode_index: 0
|
||||||
|
subnode_count: 1
|
||||||
```
|
```
|
||||||
|
|
||||||
### core
|
### core
|
||||||
|
@ -289,7 +289,10 @@ impl Network {
|
|||||||
if !from.ip().is_unspecified() {
|
if !from.ip().is_unspecified() {
|
||||||
vec![from]
|
vec![from]
|
||||||
} else {
|
} else {
|
||||||
let addrs = self.last_network_state().stable_interface_addresses;
|
let addrs = self
|
||||||
|
.last_network_state()
|
||||||
|
.unwrap()
|
||||||
|
.stable_interface_addresses;
|
||||||
addrs
|
addrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|a| {
|
.filter_map(|a| {
|
||||||
|
@ -41,8 +41,8 @@ impl Network {
|
|||||||
addrs
|
addrs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn last_network_state(&self) -> NetworkState {
|
pub(super) fn last_network_state(&self) -> Option<NetworkState> {
|
||||||
self.inner.lock().network_state.clone().unwrap()
|
self.inner.lock().network_state.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn is_stable_interface_address(&self, addr: IpAddr) -> bool {
|
pub(super) fn is_stable_interface_address(&self, addr: IpAddr) -> bool {
|
||||||
|
@ -29,7 +29,7 @@ impl Network {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_network_state != last_network_state {
|
if last_network_state.is_none() || new_network_state != last_network_state.unwrap() {
|
||||||
// Save new network state
|
// Save new network state
|
||||||
{
|
{
|
||||||
let mut inner = self.inner.lock();
|
let mut inner = self.inner.lock();
|
||||||
|
@ -39,7 +39,7 @@ struct RequestLine {
|
|||||||
// Request to process
|
// Request to process
|
||||||
line: String,
|
line: String,
|
||||||
// Where to send the response
|
// Where to send the response
|
||||||
responses_tx: flume::Sender<String>,
|
responses_tx: flume::Sender<Arc<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ClientApiInner {
|
struct ClientApiInner {
|
||||||
@ -48,7 +48,7 @@ struct ClientApiInner {
|
|||||||
settings: Settings,
|
settings: Settings,
|
||||||
stop: Option<StopSource>,
|
stop: Option<StopSource>,
|
||||||
join_handle: Option<ClientApiAllFuturesJoinHandle>,
|
join_handle: Option<ClientApiAllFuturesJoinHandle>,
|
||||||
update_channels: HashMap<u64, flume::Sender<String>>,
|
update_channels: HashMap<u64, flume::Sender<Arc<String>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -305,7 +305,8 @@ impl ClientApi {
|
|||||||
debug!("JSONAPI: Response: {:?}", response);
|
debug!("JSONAPI: Response: {:?}", response);
|
||||||
|
|
||||||
// Marshal json + newline => NDJSON
|
// Marshal json + newline => NDJSON
|
||||||
let response_string = serialize_json(json_api::RecvMessage::Response(response)) + "\n";
|
let response_string =
|
||||||
|
Arc::new(serialize_json(json_api::RecvMessage::Response(response)) + "\n");
|
||||||
if let Err(e) = responses_tx.send_async(response_string).await {
|
if let Err(e) = responses_tx.send_async(response_string).await {
|
||||||
eprintln!("response not sent: {}", e)
|
eprintln!("response not sent: {}", e)
|
||||||
}
|
}
|
||||||
@ -322,7 +323,7 @@ impl ClientApi {
|
|||||||
self,
|
self,
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
requests_tx: flume::Sender<Option<RequestLine>>,
|
requests_tx: flume::Sender<Option<RequestLine>>,
|
||||||
responses_tx: flume::Sender<String>,
|
responses_tx: flume::Sender<Arc<String>>,
|
||||||
) -> VeilidAPIResult<Option<RequestLine>> {
|
) -> VeilidAPIResult<Option<RequestLine>> {
|
||||||
let mut linebuf = String::new();
|
let mut linebuf = String::new();
|
||||||
while let Ok(size) = reader.read_line(&mut linebuf).await {
|
while let Ok(size) = reader.read_line(&mut linebuf).await {
|
||||||
@ -356,7 +357,7 @@ impl ClientApi {
|
|||||||
|
|
||||||
async fn send_responses<W: AsyncWriteExt + Unpin>(
|
async fn send_responses<W: AsyncWriteExt + Unpin>(
|
||||||
self,
|
self,
|
||||||
responses_rx: flume::Receiver<String>,
|
responses_rx: flume::Receiver<Arc<String>>,
|
||||||
mut writer: W,
|
mut writer: W,
|
||||||
) -> VeilidAPIResult<Option<RequestLine>> {
|
) -> VeilidAPIResult<Option<RequestLine>> {
|
||||||
while let Ok(resp) = responses_rx.recv_async().await {
|
while let Ok(resp) = responses_rx.recv_async().await {
|
||||||
@ -521,11 +522,16 @@ impl ClientApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_update(&self, veilid_update: veilid_core::VeilidUpdate) {
|
pub fn handle_update(&self, veilid_update: veilid_core::VeilidUpdate) {
|
||||||
// serialize update to NDJSON
|
|
||||||
let veilid_update = serialize_json(json_api::RecvMessage::Update(veilid_update)) + "\n";
|
|
||||||
|
|
||||||
// Pass other updates to clients
|
|
||||||
let inner = self.inner.lock();
|
let inner = self.inner.lock();
|
||||||
|
if inner.update_channels.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// serialize update to NDJSON
|
||||||
|
let veilid_update =
|
||||||
|
Arc::new(serialize_json(json_api::RecvMessage::Update(veilid_update)) + "\n");
|
||||||
|
|
||||||
|
// Pass updates to clients
|
||||||
for ch in inner.update_channels.values() {
|
for ch in inner.update_channels.values() {
|
||||||
if ch.send(veilid_update.clone()).is_err() {
|
if ch.send(veilid_update.clone()).is_err() {
|
||||||
// eprintln!("failed to send update: {}", e);
|
// eprintln!("failed to send update: {}", e);
|
||||||
|
@ -99,7 +99,7 @@ pub struct CmdlineArgs {
|
|||||||
|
|
||||||
/// Run several nodes in parallel on the same machine for testing purposes
|
/// Run several nodes in parallel on the same machine for testing purposes
|
||||||
///
|
///
|
||||||
/// Will run subnodes N though N+(subnode_count-1), where N is 0 or set via --subnode_index
|
/// Will run subnodes N through N+(subnode_count-1), where N is 0 or set via --subnode_index
|
||||||
#[arg(long, value_name = "COUNT")]
|
#[arg(long, value_name = "COUNT")]
|
||||||
subnode_count: Option<u16>,
|
subnode_count: Option<u16>,
|
||||||
|
|
||||||
@ -214,10 +214,6 @@ fn main() -> EyreResult<()> {
|
|||||||
if args.foreground {
|
if args.foreground {
|
||||||
settingsrw.daemon.enabled = false;
|
settingsrw.daemon.enabled = false;
|
||||||
}
|
}
|
||||||
if let Some(subnode_index) = args.subnode_index {
|
|
||||||
settingsrw.testing.subnode_index = subnode_index;
|
|
||||||
};
|
|
||||||
|
|
||||||
if args.logging.debug {
|
if args.logging.debug {
|
||||||
settingsrw.logging.terminal.enabled = true;
|
settingsrw.logging.terminal.enabled = true;
|
||||||
settingsrw.logging.terminal.level = LogLevel::Debug;
|
settingsrw.logging.terminal.level = LogLevel::Debug;
|
||||||
@ -226,21 +222,31 @@ fn main() -> EyreResult<()> {
|
|||||||
settingsrw.logging.terminal.enabled = true;
|
settingsrw.logging.terminal.enabled = true;
|
||||||
settingsrw.logging.terminal.level = LogLevel::Trace;
|
settingsrw.logging.terminal.level = LogLevel::Trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(subnode_index) = args.subnode_index {
|
||||||
|
settingsrw.testing.subnode_index = subnode_index;
|
||||||
|
};
|
||||||
|
if let Some(subnode_count) = args.subnode_count {
|
||||||
|
if subnode_count == 0 {
|
||||||
|
bail!("subnode count must be positive");
|
||||||
|
}
|
||||||
|
settingsrw.testing.subnode_count = subnode_count;
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "opentelemetry-otlp")]
|
#[cfg(feature = "opentelemetry-otlp")]
|
||||||
if args.otlp.is_some() {
|
if let Some(otlp) = args.otlp {
|
||||||
println!("Enabling OTLP tracing");
|
println!("Enabling OTLP tracing");
|
||||||
settingsrw.logging.otlp.enabled = true;
|
settingsrw.logging.otlp.enabled = true;
|
||||||
settingsrw.logging.otlp.grpc_endpoint = NamedSocketAddrs::from_str(
|
settingsrw.logging.otlp.grpc_endpoint =
|
||||||
args.otlp
|
NamedSocketAddrs::from_str(&otlp).wrap_err("failed to parse OTLP address")?;
|
||||||
.expect("should not be null because of default missing value")
|
|
||||||
.as_str(),
|
|
||||||
)
|
|
||||||
.wrap_err("failed to parse OTLP address")?;
|
|
||||||
settingsrw.logging.otlp.level = LogLevel::Trace;
|
settingsrw.logging.otlp.level = LogLevel::Trace;
|
||||||
}
|
}
|
||||||
if let Some(flame) = args.flame {
|
if let Some(flame) = args.flame {
|
||||||
let flame = if flame.is_empty() {
|
let flame = if flame.is_empty() {
|
||||||
Settings::get_default_flame_path(settingsrw.testing.subnode_index)
|
Settings::get_default_flame_path(
|
||||||
|
settingsrw.testing.subnode_index,
|
||||||
|
settingsrw.testing.subnode_count,
|
||||||
|
)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string()
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
@ -253,7 +259,10 @@ fn main() -> EyreResult<()> {
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
if let Some(perfetto) = args.perfetto {
|
if let Some(perfetto) = args.perfetto {
|
||||||
let perfetto = if perfetto.is_empty() {
|
let perfetto = if perfetto.is_empty() {
|
||||||
Settings::get_default_perfetto_path(settingsrw.testing.subnode_index)
|
Settings::get_default_perfetto_path(
|
||||||
|
settingsrw.testing.subnode_index,
|
||||||
|
settingsrw.testing.subnode_count,
|
||||||
|
)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string()
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
@ -297,6 +306,10 @@ fn main() -> EyreResult<()> {
|
|||||||
}
|
}
|
||||||
let mut node_id_set = false;
|
let mut node_id_set = false;
|
||||||
if let Some(key_set) = args.set_node_id {
|
if let Some(key_set) = args.set_node_id {
|
||||||
|
if settingsrw.testing.subnode_count != 1 {
|
||||||
|
bail!("subnode count must be 1 if setting node id/secret");
|
||||||
|
}
|
||||||
|
|
||||||
node_id_set = true;
|
node_id_set = true;
|
||||||
// Turn off terminal logging so we can be interactive
|
// Turn off terminal logging so we can be interactive
|
||||||
settingsrw.logging.terminal.enabled = false;
|
settingsrw.logging.terminal.enabled = false;
|
||||||
@ -360,11 +373,6 @@ fn main() -> EyreResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply subnode index if we're testing
|
|
||||||
settings
|
|
||||||
.apply_subnode_index()
|
|
||||||
.wrap_err("failed to apply subnode index")?;
|
|
||||||
|
|
||||||
// --- Verify Config ---
|
// --- Verify Config ---
|
||||||
settings.verify()?;
|
settings.verify()?;
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ pub fn shutdown() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[instrument(err, skip_all)]
|
pub async fn run_veilid_server_subnode(
|
||||||
pub async fn run_veilid_server(
|
subnode: u16,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
server_mode: ServerMode,
|
server_mode: ServerMode,
|
||||||
veilid_logs: VeilidLogs,
|
veilid_logs: VeilidLogs,
|
||||||
@ -44,17 +44,34 @@ pub async fn run_veilid_server(
|
|||||||
settings_client_api_network_enabled,
|
settings_client_api_network_enabled,
|
||||||
settings_client_api_ipc_directory,
|
settings_client_api_ipc_directory,
|
||||||
settings_client_api_listen_address_addrs,
|
settings_client_api_listen_address_addrs,
|
||||||
subnode_index,
|
subnode_offset,
|
||||||
) = {
|
) = {
|
||||||
let settingsr = settings.read();
|
let settingsr = settings.read();
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "virtual-network")] {
|
||||||
|
let subnode_offset = if inner.core.network.virtual_network.enabled {
|
||||||
|
// Don't offset ports when using virtual networking
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
subnode
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
let subnode_offset = subnode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
settingsr.auto_attach,
|
settingsr.auto_attach,
|
||||||
settingsr.client_api.ipc_enabled,
|
settingsr.client_api.ipc_enabled,
|
||||||
settingsr.client_api.network_enabled,
|
settingsr.client_api.network_enabled,
|
||||||
settingsr.client_api.ipc_directory.clone(),
|
settingsr.client_api.ipc_directory.clone(),
|
||||||
settingsr.client_api.listen_address.addrs.clone(),
|
settingsr
|
||||||
settingsr.testing.subnode_index,
|
.client_api
|
||||||
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)?
|
||||||
|
.addrs,
|
||||||
|
subnode_offset,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,7 +89,7 @@ pub async fn run_veilid_server(
|
|||||||
eprintln!("error sending veilid update callback: {:?}", change);
|
eprintln!("error sending veilid update callback: {:?}", change);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let config_callback = settings.get_core_config_callback();
|
let config_callback = settings.get_core_config_callback(subnode, subnode_offset);
|
||||||
|
|
||||||
// Start Veilid Core and get API
|
// Start Veilid Core and get API
|
||||||
let veilid_api = veilid_core::api_startup(update_callback, config_callback)
|
let veilid_api = veilid_core::api_startup(update_callback, config_callback)
|
||||||
@ -86,7 +103,7 @@ pub async fn run_veilid_server(
|
|||||||
client_api::ClientApi::new(veilid_api.clone(), veilid_logs.clone(), settings.clone());
|
client_api::ClientApi::new(veilid_api.clone(), veilid_logs.clone(), settings.clone());
|
||||||
some_capi.clone().run(
|
some_capi.clone().run(
|
||||||
if settings_client_api_ipc_enabled {
|
if settings_client_api_ipc_enabled {
|
||||||
Some(settings_client_api_ipc_directory.join(subnode_index.to_string()))
|
Some(settings_client_api_ipc_directory.join(subnode.to_string()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
@ -108,7 +125,7 @@ pub async fn run_veilid_server(
|
|||||||
let capi2 = capi.clone();
|
let capi2 = capi.clone();
|
||||||
let update_receiver_shutdown = SingleShotEventual::new(Some(()));
|
let update_receiver_shutdown = SingleShotEventual::new(Some(()));
|
||||||
let mut update_receiver_shutdown_instance = update_receiver_shutdown.instance().fuse();
|
let mut update_receiver_shutdown_instance = update_receiver_shutdown.instance().fuse();
|
||||||
let update_receiver_jh = spawn_local(
|
let update_receiver_jh = spawn(
|
||||||
"update_receiver",
|
"update_receiver",
|
||||||
async move {
|
async move {
|
||||||
loop {
|
loop {
|
||||||
@ -116,7 +133,7 @@ pub async fn run_veilid_server(
|
|||||||
res = receiver.recv_async() => {
|
res = receiver.recv_async() => {
|
||||||
if let Ok(change) = res {
|
if let Ok(change) = res {
|
||||||
if let Some(capi) = &capi2 {
|
if let Some(capi) = &capi2 {
|
||||||
// Handle state changes on main thread for capnproto rpc
|
// Handle state changes for JSON API
|
||||||
capi.clone().handle_update(change);
|
capi.clone().handle_update(change);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -201,9 +218,48 @@ pub async fn run_veilid_server(
|
|||||||
// Wait for update receiver to exit
|
// Wait for update receiver to exit
|
||||||
let _ = update_receiver_jh.await;
|
let _ = update_receiver_jh.await;
|
||||||
|
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
//#[instrument(err, skip_all)]
|
||||||
|
pub async fn run_veilid_server(
|
||||||
|
settings: Settings,
|
||||||
|
server_mode: ServerMode,
|
||||||
|
veilid_logs: VeilidLogs,
|
||||||
|
) -> EyreResult<()> {
|
||||||
|
let (subnode_index, subnode_count) = {
|
||||||
|
let settingsr = settings.read();
|
||||||
|
(
|
||||||
|
settingsr.testing.subnode_index,
|
||||||
|
settingsr.testing.subnode_count,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ensure we only try to spawn multiple subnodes in 'normal' execution mode
|
||||||
|
if !matches!(server_mode, ServerMode::Normal) && subnode_count != 1 {
|
||||||
|
bail!("can only have multiple subnodes in 'normal' execution mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run all subnodes
|
||||||
|
let mut all_subnodes_jh = vec![];
|
||||||
|
for subnode in subnode_index..(subnode_index + subnode_count) {
|
||||||
|
debug!("Spawning subnode {}", subnode);
|
||||||
|
let jh = spawn(
|
||||||
|
&format!("subnode{}", subnode),
|
||||||
|
run_veilid_server_subnode(subnode, settings.clone(), server_mode, veilid_logs.clone()),
|
||||||
|
);
|
||||||
|
all_subnodes_jh.push(jh);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for all subnodes to complete
|
||||||
|
for (sn, jh) in all_subnodes_jh.into_iter().enumerate() {
|
||||||
|
jh.await?;
|
||||||
|
debug!("Subnode {} exited", sn);
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, drop logs
|
// Finally, drop logs
|
||||||
// this is explicit to ensure we don't accidentally drop them too soon via a move
|
// this is explicit to ensure we don't accidentally drop them too soon via a move
|
||||||
drop(veilid_logs);
|
drop(veilid_logs);
|
||||||
|
|
||||||
out
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -377,6 +377,11 @@ impl ParsedUrl {
|
|||||||
self.urlstring = self.url.to_string();
|
self.urlstring = self.url.to_string();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
pub fn with_offset_port(&self, offset: u16) -> EyreResult<Self> {
|
||||||
|
let mut x = self.clone();
|
||||||
|
x.offset_port(offset)?;
|
||||||
|
Ok(x)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ParsedUrl {
|
impl FromStr for ParsedUrl {
|
||||||
@ -481,6 +486,12 @@ impl NamedSocketAddrs {
|
|||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_offset_port(&self, offset: u16) -> EyreResult<Self> {
|
||||||
|
let mut x = self.clone();
|
||||||
|
x.offset_port(offset)?;
|
||||||
|
Ok(x)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
@ -863,75 +874,6 @@ impl Settings {
|
|||||||
self.inner.write()
|
self.inner.write()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_subnode_index(&self) -> EyreResult<()> {
|
|
||||||
let mut settingsrw = self.write();
|
|
||||||
let idx = settingsrw.testing.subnode_index;
|
|
||||||
if idx == 0 {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// bump client api port
|
|
||||||
settingsrw.client_api.listen_address.offset_port(idx)?;
|
|
||||||
|
|
||||||
// bump protocol ports
|
|
||||||
settingsrw
|
|
||||||
.core
|
|
||||||
.network
|
|
||||||
.protocol
|
|
||||||
.udp
|
|
||||||
.listen_address
|
|
||||||
.offset_port(idx)?;
|
|
||||||
settingsrw
|
|
||||||
.core
|
|
||||||
.network
|
|
||||||
.protocol
|
|
||||||
.tcp
|
|
||||||
.listen_address
|
|
||||||
.offset_port(idx)?;
|
|
||||||
settingsrw
|
|
||||||
.core
|
|
||||||
.network
|
|
||||||
.protocol
|
|
||||||
.ws
|
|
||||||
.listen_address
|
|
||||||
.offset_port(idx)?;
|
|
||||||
if let Some(url) = &mut settingsrw.core.network.protocol.ws.url {
|
|
||||||
url.offset_port(idx)?;
|
|
||||||
}
|
|
||||||
settingsrw
|
|
||||||
.core
|
|
||||||
.network
|
|
||||||
.protocol
|
|
||||||
.wss
|
|
||||||
.listen_address
|
|
||||||
.offset_port(idx)?;
|
|
||||||
if let Some(url) = &mut settingsrw.core.network.protocol.wss.url {
|
|
||||||
url.offset_port(idx)?;
|
|
||||||
}
|
|
||||||
// bump application ports
|
|
||||||
settingsrw
|
|
||||||
.core
|
|
||||||
.network
|
|
||||||
.application
|
|
||||||
.http
|
|
||||||
.listen_address
|
|
||||||
.offset_port(idx)?;
|
|
||||||
if let Some(url) = &mut settingsrw.core.network.application.http.url {
|
|
||||||
url.offset_port(idx)?;
|
|
||||||
}
|
|
||||||
settingsrw
|
|
||||||
.core
|
|
||||||
.network
|
|
||||||
.application
|
|
||||||
.https
|
|
||||||
.listen_address
|
|
||||||
.offset_port(idx)?;
|
|
||||||
if let Some(url) = &mut settingsrw.core.network.application.https.url {
|
|
||||||
url.offset_port(idx)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Determine default config path
|
/// Determine default config path
|
||||||
///
|
///
|
||||||
/// In a unix-like environment, veilid-server will look for its config file
|
/// In a unix-like environment, veilid-server will look for its config file
|
||||||
@ -962,22 +904,40 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Determine default flamegraph output path
|
/// Determine default flamegraph output path
|
||||||
pub fn get_default_flame_path(subnode_index: u16) -> PathBuf {
|
pub fn get_default_flame_path(subnode_index: u16, subnode_count: u16) -> PathBuf {
|
||||||
std::env::temp_dir().join(if subnode_index == 0 {
|
let name = if subnode_count == 1 {
|
||||||
|
if subnode_index == 0 {
|
||||||
"veilid-server.folded".to_owned()
|
"veilid-server.folded".to_owned()
|
||||||
} else {
|
} else {
|
||||||
format!("veilid-server-{}.folded", subnode_index)
|
format!("veilid-server-{}.folded", subnode_index)
|
||||||
})
|
}
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"veilid-server-{}-{}.folded",
|
||||||
|
subnode_index,
|
||||||
|
subnode_index + subnode_count - 1
|
||||||
|
)
|
||||||
|
};
|
||||||
|
std::env::temp_dir().join(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine default perfetto output path
|
/// Determine default perfetto output path
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn get_default_perfetto_path(subnode_index: u16) -> PathBuf {
|
pub fn get_default_perfetto_path(subnode_index: u16, subnode_count: u16) -> PathBuf {
|
||||||
std::env::temp_dir().join(if subnode_index == 0 {
|
let name = if subnode_count == 1 {
|
||||||
|
if subnode_index == 0 {
|
||||||
"veilid-server.pftrace".to_owned()
|
"veilid-server.pftrace".to_owned()
|
||||||
} else {
|
} else {
|
||||||
format!("veilid-server-{}.pftrace", subnode_index)
|
format!("veilid-server-{}.pftrace", subnode_index)
|
||||||
})
|
}
|
||||||
|
} else {
|
||||||
|
format!(
|
||||||
|
"veilid-server-{}-{}.pftrace",
|
||||||
|
subnode_index,
|
||||||
|
subnode_index + subnode_count - 1
|
||||||
|
)
|
||||||
|
};
|
||||||
|
std::env::temp_dir().join(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(windows, expect(dead_code))]
|
#[cfg_attr(windows, expect(dead_code))]
|
||||||
@ -1270,17 +1230,22 @@ impl Settings {
|
|||||||
Err(eyre!("settings key '{key}' not found"))
|
Err(eyre!("settings key '{key}' not found"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_core_config_callback(&self) -> veilid_core::ConfigCallback {
|
pub fn get_core_config_callback(
|
||||||
|
&self,
|
||||||
|
subnode: u16,
|
||||||
|
subnode_offset: u16,
|
||||||
|
) -> veilid_core::ConfigCallback {
|
||||||
let inner = self.inner.clone();
|
let inner = self.inner.clone();
|
||||||
|
|
||||||
Arc::new(move |key: String| {
|
Arc::new(move |key: String| {
|
||||||
let inner = inner.read();
|
let inner = inner.read();
|
||||||
|
|
||||||
let out: ConfigCallbackReturn = match key.as_str() {
|
let out: ConfigCallbackReturn = match key.as_str() {
|
||||||
"program_name" => Ok(Box::new("veilid-server".to_owned())),
|
"program_name" => Ok(Box::new("veilid-server".to_owned())),
|
||||||
"namespace" => Ok(Box::new(if inner.testing.subnode_index == 0 {
|
"namespace" => Ok(Box::new(if subnode == 0 {
|
||||||
"".to_owned()
|
"".to_owned()
|
||||||
} else {
|
} else {
|
||||||
format!("subnode{}", inner.testing.subnode_index)
|
format!("subnode{}", subnode)
|
||||||
})),
|
})),
|
||||||
"capabilities.disable" => {
|
"capabilities.disable" => {
|
||||||
let mut caps = Vec::<FourCC>::new();
|
let mut caps = Vec::<FourCC>::new();
|
||||||
@ -1492,6 +1457,8 @@ impl Settings {
|
|||||||
.application
|
.application
|
||||||
.https
|
.https
|
||||||
.listen_address
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)
|
||||||
|
.map_err(VeilidAPIError::internal)?
|
||||||
.name
|
.name
|
||||||
.clone(),
|
.clone(),
|
||||||
)),
|
)),
|
||||||
@ -1505,16 +1472,16 @@ impl Settings {
|
|||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)),
|
)),
|
||||||
"network.application.https.url" => Ok(Box::new(
|
"network.application.https.url" => {
|
||||||
inner
|
Ok(Box::new(match inner.core.network.application.https.url {
|
||||||
.core
|
Some(ref a) => Some(
|
||||||
.network
|
a.with_offset_port(subnode_offset)
|
||||||
.application
|
.map_err(VeilidAPIError::internal)
|
||||||
.https
|
.map(|x| x.urlstring.clone())?,
|
||||||
.url
|
),
|
||||||
.as_ref()
|
None => None,
|
||||||
.map(|a| a.urlstring.clone()),
|
}))
|
||||||
)),
|
}
|
||||||
"network.application.http.enabled" => {
|
"network.application.http.enabled" => {
|
||||||
Ok(Box::new(inner.core.network.application.http.enabled))
|
Ok(Box::new(inner.core.network.application.http.enabled))
|
||||||
}
|
}
|
||||||
@ -1525,6 +1492,8 @@ impl Settings {
|
|||||||
.application
|
.application
|
||||||
.http
|
.http
|
||||||
.listen_address
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)
|
||||||
|
.map_err(VeilidAPIError::internal)?
|
||||||
.name
|
.name
|
||||||
.clone(),
|
.clone(),
|
||||||
)),
|
)),
|
||||||
@ -1538,16 +1507,16 @@ impl Settings {
|
|||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)),
|
)),
|
||||||
"network.application.http.url" => Ok(Box::new(
|
"network.application.http.url" => {
|
||||||
inner
|
Ok(Box::new(match inner.core.network.application.http.url {
|
||||||
.core
|
Some(ref a) => Some(
|
||||||
.network
|
a.with_offset_port(subnode_offset)
|
||||||
.application
|
.map_err(VeilidAPIError::internal)
|
||||||
.http
|
.map(|x| x.urlstring.clone())?,
|
||||||
.url
|
),
|
||||||
.as_ref()
|
None => None,
|
||||||
.map(|a| a.urlstring.clone()),
|
}))
|
||||||
)),
|
}
|
||||||
"network.protocol.udp.enabled" => {
|
"network.protocol.udp.enabled" => {
|
||||||
Ok(Box::new(inner.core.network.protocol.udp.enabled))
|
Ok(Box::new(inner.core.network.protocol.udp.enabled))
|
||||||
}
|
}
|
||||||
@ -1555,7 +1524,16 @@ impl Settings {
|
|||||||
Ok(Box::new(inner.core.network.protocol.udp.socket_pool_size))
|
Ok(Box::new(inner.core.network.protocol.udp.socket_pool_size))
|
||||||
}
|
}
|
||||||
"network.protocol.udp.listen_address" => Ok(Box::new(
|
"network.protocol.udp.listen_address" => Ok(Box::new(
|
||||||
inner.core.network.protocol.udp.listen_address.name.clone(),
|
inner
|
||||||
|
.core
|
||||||
|
.network
|
||||||
|
.protocol
|
||||||
|
.udp
|
||||||
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)
|
||||||
|
.map_err(VeilidAPIError::internal)?
|
||||||
|
.name
|
||||||
|
.clone(),
|
||||||
)),
|
)),
|
||||||
"network.protocol.udp.public_address" => Ok(Box::new(
|
"network.protocol.udp.public_address" => Ok(Box::new(
|
||||||
inner
|
inner
|
||||||
@ -1577,7 +1555,16 @@ impl Settings {
|
|||||||
Ok(Box::new(inner.core.network.protocol.tcp.max_connections))
|
Ok(Box::new(inner.core.network.protocol.tcp.max_connections))
|
||||||
}
|
}
|
||||||
"network.protocol.tcp.listen_address" => Ok(Box::new(
|
"network.protocol.tcp.listen_address" => Ok(Box::new(
|
||||||
inner.core.network.protocol.tcp.listen_address.name.clone(),
|
inner
|
||||||
|
.core
|
||||||
|
.network
|
||||||
|
.protocol
|
||||||
|
.tcp
|
||||||
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)
|
||||||
|
.map_err(VeilidAPIError::internal)?
|
||||||
|
.name
|
||||||
|
.clone(),
|
||||||
)),
|
)),
|
||||||
"network.protocol.tcp.public_address" => Ok(Box::new(
|
"network.protocol.tcp.public_address" => Ok(Box::new(
|
||||||
inner
|
inner
|
||||||
@ -1597,7 +1584,16 @@ impl Settings {
|
|||||||
Ok(Box::new(inner.core.network.protocol.ws.max_connections))
|
Ok(Box::new(inner.core.network.protocol.ws.max_connections))
|
||||||
}
|
}
|
||||||
"network.protocol.ws.listen_address" => Ok(Box::new(
|
"network.protocol.ws.listen_address" => Ok(Box::new(
|
||||||
inner.core.network.protocol.ws.listen_address.name.clone(),
|
inner
|
||||||
|
.core
|
||||||
|
.network
|
||||||
|
.protocol
|
||||||
|
.ws
|
||||||
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)
|
||||||
|
.map_err(VeilidAPIError::internal)?
|
||||||
|
.name
|
||||||
|
.clone(),
|
||||||
)),
|
)),
|
||||||
"network.protocol.ws.path" => Ok(Box::new(
|
"network.protocol.ws.path" => Ok(Box::new(
|
||||||
inner
|
inner
|
||||||
@ -1609,16 +1605,16 @@ impl Settings {
|
|||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)),
|
)),
|
||||||
"network.protocol.ws.url" => Ok(Box::new(
|
"network.protocol.ws.url" => {
|
||||||
inner
|
Ok(Box::new(match inner.core.network.protocol.ws.url {
|
||||||
.core
|
Some(ref a) => Some(
|
||||||
.network
|
a.with_offset_port(subnode_offset)
|
||||||
.protocol
|
.map_err(VeilidAPIError::internal)
|
||||||
.ws
|
.map(|x| x.urlstring.clone())?,
|
||||||
.url
|
),
|
||||||
.as_ref()
|
None => None,
|
||||||
.map(|a| a.urlstring.clone()),
|
}))
|
||||||
)),
|
}
|
||||||
"network.protocol.wss.connect" => {
|
"network.protocol.wss.connect" => {
|
||||||
Ok(Box::new(inner.core.network.protocol.wss.connect))
|
Ok(Box::new(inner.core.network.protocol.wss.connect))
|
||||||
}
|
}
|
||||||
@ -1629,7 +1625,16 @@ impl Settings {
|
|||||||
Ok(Box::new(inner.core.network.protocol.wss.max_connections))
|
Ok(Box::new(inner.core.network.protocol.wss.max_connections))
|
||||||
}
|
}
|
||||||
"network.protocol.wss.listen_address" => Ok(Box::new(
|
"network.protocol.wss.listen_address" => Ok(Box::new(
|
||||||
inner.core.network.protocol.wss.listen_address.name.clone(),
|
inner
|
||||||
|
.core
|
||||||
|
.network
|
||||||
|
.protocol
|
||||||
|
.wss
|
||||||
|
.listen_address
|
||||||
|
.with_offset_port(subnode_offset)
|
||||||
|
.map_err(VeilidAPIError::internal)?
|
||||||
|
.name
|
||||||
|
.clone(),
|
||||||
)),
|
)),
|
||||||
"network.protocol.wss.path" => Ok(Box::new(
|
"network.protocol.wss.path" => Ok(Box::new(
|
||||||
inner
|
inner
|
||||||
@ -1641,16 +1646,16 @@ impl Settings {
|
|||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)),
|
)),
|
||||||
"network.protocol.wss.url" => Ok(Box::new(
|
"network.protocol.wss.url" => {
|
||||||
inner
|
Ok(Box::new(match inner.core.network.protocol.wss.url {
|
||||||
.core
|
Some(ref a) => Some(
|
||||||
.network
|
a.with_offset_port(subnode_offset)
|
||||||
.protocol
|
.map_err(VeilidAPIError::internal)
|
||||||
.wss
|
.map(|x| x.urlstring.clone())?,
|
||||||
.url
|
),
|
||||||
.as_ref()
|
None => None,
|
||||||
.map(|a| a.urlstring.clone()),
|
}))
|
||||||
)),
|
}
|
||||||
#[cfg(feature = "geolocation")]
|
#[cfg(feature = "geolocation")]
|
||||||
"network.privacy.country_code_denylist" => Ok(Box::new(
|
"network.privacy.country_code_denylist" => Ok(Box::new(
|
||||||
inner.core.network.privacy.country_code_denylist.clone(),
|
inner.core.network.privacy.country_code_denylist.clone(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user