From cfcc664e9e0138f4d5fe3299fd2af755831acf05 Mon Sep 17 00:00:00 2001 From: Giacomo Pasini Date: Thu, 12 Jan 2023 12:57:02 +0100 Subject: [PATCH] Add dummy binary (#5) * add dummy binary * add flags for macos * add metrics service * rename Services to Nomos --- Cargo.toml | 3 +- nomos-node/.cargo/config.toml | 4 +++ nomos-node/Cargo.toml | 19 ++++++++++++ nomos-node/src/main.rs | 55 +++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 nomos-node/.cargo/config.toml create mode 100644 nomos-node/Cargo.toml create mode 100644 nomos-node/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 409474d1..89b92406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,6 @@ members = [ "nomos-services/network", "nomos-services/storage", "nomos-services/consensus", - "nomos-services/mempool" + "nomos-services/mempool", + "nomos-node" ] \ No newline at end of file diff --git a/nomos-node/.cargo/config.toml b/nomos-node/.cargo/config.toml new file mode 100644 index 00000000..83eca5f7 --- /dev/null +++ b/nomos-node/.cargo/config.toml @@ -0,0 +1,4 @@ +[target.'cfg(target_os = "macos")'] +# when using osx, we need to link against some golang libraries, it did just work with this missing flags +# from: https://github.com/golang/go/issues/42459 +rustflags = ["-C", "link-args=-framework CoreFoundation -framework Security"] diff --git a/nomos-node/Cargo.toml b/nomos-node/Cargo.toml new file mode 100644 index 00000000..342d4052 --- /dev/null +++ b/nomos-node/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "nomos-node" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4", features = ["derive"] } +overwatch-rs = { git = "https://github.com/logos-co/Overwatch", branch = "main" } +overwatch-derive = { git = "https://github.com/logos-co/Overwatch", branch = "main" } +tracing = "0.1" +nomos-network = { path = "../nomos-services/network", features = ["waku"] } +metrics = { path = "../nomos-services/metrics", optional = true } +nomos-log = { path = "../nomos-services/log" } +tracing-subscriber = "0.3" +serde_yaml = "0.9" +color-eyre = "0.6.0" +serde = "1" diff --git a/nomos-node/src/main.rs b/nomos-node/src/main.rs new file mode 100644 index 00000000..272465fd --- /dev/null +++ b/nomos-node/src/main.rs @@ -0,0 +1,55 @@ +use clap::Parser; +use color_eyre::eyre::{eyre, Result}; +use nomos_log::Logger; +use nomos_network::{backends::waku::Waku, NetworkService}; +use overwatch_derive::*; +use overwatch_rs::{ + overwatch::*, + services::{handle::ServiceHandle, ServiceData}, +}; +use serde::Deserialize; + +#[cfg(feature = "metrics")] +use metrics::{backend::map::MapMetricsBackend, types::MetricsData, MetricsService}; + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Path for a yaml-encoded network config file + config: std::path::PathBuf, +} + +#[derive(Deserialize)] +struct Config { + log: ::Settings, + network: as ServiceData>::Settings, + #[cfg(feature = "metrics")] + metrics: > as ServiceData>::Settings, +} + +#[derive(Services)] +struct Nomos { + logging: ServiceHandle, + network: ServiceHandle>, + #[cfg(feature = "metrics")] + metrics: ServiceHandle>>, +} + +fn main() -> Result<()> { + tracing_subscriber::fmt::init(); + let Args { config } = Args::parse(); + let config = serde_yaml::from_reader::<_, Config>(std::fs::File::open(config)?)?; + let app = OverwatchRunner::::run( + NomosServiceSettings { + network: config.network, + logging: config.log, + #[cfg(feature = "metrics")] + metrics: config.metrics, + }, + None, + ) + .map_err(|e| eyre!("Error encountered: {}", e))?; + app.wait_finished(); + Ok(()) +}