Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win: reintegrate network fetch fix + file logging #1768

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nym-vpn-core/crates/nym-vpnd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tonic-reflection.workspace = true
tonic.workspace = true
tower-http = { workspace = true, features = ["cors"] }
tracing-appender.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "ansi"] }
tracing.workspace = true
url.workspace = true
zeroize.workspace = true
Expand All @@ -57,7 +57,7 @@ nym-vpn-account-controller = { path = "../nym-vpn-account-controller" }
nym-vpn-api-client = { path = "../nym-vpn-api-client" }
nym-vpn-lib = { path = "../nym-vpn-lib" }
nym-vpn-network-config = { path = "../nym-vpn-network-config" }
nym-vpn-proto = { path = "../nym-vpn-proto", features = ["conversions"]}
nym-vpn-proto = { path = "../nym-vpn-proto", features = ["conversions"] }
nym-vpn-store = { path = "../nym-vpn-store" }
nym-vpnd-types = { path = "../nym-vpnd-types" }

Expand Down
1 change: 1 addition & 0 deletions nym-vpn-core/crates/nym-vpnd/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn setup_logging_to_file() -> WorkerGuard {
.with_env_filter(filter)
.compact()
.with_writer(file_writer)
.with_ansi(false)
.init();

std::panic::set_hook(Box::new(|panic| {
Expand Down
3 changes: 1 addition & 2 deletions nym-vpn-core/crates/nym-vpnd/src/windows_service/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ pub(super) fn start_service() -> windows_service::Result<()> {
let service = service_manager.open_service(SERVICE_NAME, service_access)?;

if service.query_status()?.current_state != ServiceState::Running {
// TODO: figure out how to pass an empty array or null
service.start(&[std::ffi::OsStr::new("")])?;
service.start(&[] as &[&std::ffi::OsStr])?;
}
Ok(())
}
32 changes: 18 additions & 14 deletions nym-vpn-core/crates/nym-vpnd/src/windows_service/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

use std::{env, ffi::OsString, time::Duration};
use std::{env, ffi::OsString, io, time::Duration};

use tokio::sync::broadcast;
use tokio_util::sync::CancellationToken;
Expand All @@ -27,35 +27,39 @@ pub(crate) static SERVICE_DESCRIPTION: &str =
static SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS;

fn service_main(arguments: Vec<OsString>) {
let result = runtime::new_runtime().block_on(run_service(arguments));

if let Err(err) = result {
// Handle error in some way.
println!("service_main: {:?}", err);
if let Err(err) = run_service(arguments) {
println!("service_main {:?}", err);
tracing::error!("service_main: {:?}", err);
}
}

async fn run_service(_arguments: Vec<OsString>) -> windows_service::Result<()> {
tracing::info!("Setting up event handler");

fn run_service(_args: Vec<OsString>) -> windows_service::Result<()> {
// TODO: network selection is not yet implemented/supported
let network_name = "mainnet";
let network_env = match nym_vpn_network_config::Network::fetch(network_name) {
match nym_vpn_network_config::Network::fetch(network_name) {
Ok(network_env) => {
network_env.export_to_env();
network_env
let rt = runtime::new_runtime();
rt.block_on(run_service_inner(network_env))
}
Err(err) => {
tracing::error!(
"Failed to fetch network environment for '{}': {}",
network_name,
err
);
// TODO: just picking something here to make it compile
return Err(windows_service::Error::LaunchArgumentsNotSupported);
Err(windows_service::Error::Winapi(io::Error::new(
io::ErrorKind::Other,
"Failed to fetch network environment",
)))
}
};
}
}

async fn run_service_inner(
network_env: nym_vpn_network_config::Network,
) -> windows_service::Result<()> {
tracing::info!("Setting up event handler");

let shutdown_token = CancellationToken::new();
let cloned_shutdown_token = shutdown_token.clone();
Expand Down
Loading