Skip to content

Commit

Permalink
[draft] separate lib/app
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugouel committed Jan 4, 2025
1 parent ccae3b3 commit 53f826e
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 100 deletions.
81 changes: 44 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 6 additions & 27 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
[package]
name = "risotto"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.8.1"
bgpkit-parser = { version = "0.10.11", features = ["serde"] }
bytes = "1.9.0"
chrono = "0.4.39"
clap = { version = "4.5.23", features = ["derive"] }
clap-verbosity-flag = "3.0.2"
config = "0.15.4"
env_logger = "0.11.6"
hex = "0.4.3"
kafka = "0.10.0"
log = "0.4.22"
metrics = "0.24.1"
metrics-exporter-prometheus = "0.16.0"
prefix-trie = "0.5.1"
rand = "0.8.5"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
tokio = { version = "1.42.0", features = ["full"] }
tokio-graceful = "0.2.2"
[workspace]
resolver = "2"
members = [
"risotto",
"risotto_lib",
]
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ WORKDIR /app

COPY . .

RUN cargo install --path .
RUN cargo build --release

FROM debian:stable-slim

RUN apt-get update \
&& apt-get install -y openssl \
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/local/cargo/bin/risotto /app/risotto
COPY --from=builder /app/target/release/risotto /app/risotto

EXPOSE 3000
EXPOSE 4000
Expand Down
26 changes: 26 additions & 0 deletions risotto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "risotto"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.8.1"
bgpkit-parser = { version = "0.10.11", features = ["serde"] }
bytes = "1.9.0"
chrono = "0.4.39"
clap = { version = "4.5.23", features = ["derive"] }
clap-verbosity-flag = "3.0.2"
config = "0.15.4"
env_logger = "0.11.6"
hex = "0.4.3"
kafka = "0.10.0"
log = "0.4.22"
metrics = "0.24.1"
metrics-exporter-prometheus = "0.16.0"
prefix-trie = "0.5.1"
rand = "0.8.5"
risotto_lib = { path = "../risotto_lib" }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
tokio = { version = "1.42.0", features = ["full"] }
tokio-graceful = "0.2.2"
File renamed without changes.
6 changes: 4 additions & 2 deletions src/bmp.rs → risotto/src/bmp.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::state::{self, AsyncState};
use crate::update::{decode_updates, format_update, synthesize_withdraw_update, UpdateHeader};
use bgpkit_parser::bmp::messages::PerPeerFlags;
use bgpkit_parser::models::Peer;
use bgpkit_parser::parse_bmp_msg;
use bgpkit_parser::parser::bmp::messages::{BmpMessage, BmpMessageBody};
use bytes::Bytes;
use chrono::Utc;
use core::net::IpAddr;
use risotto_lib::state::{self, AsyncState};
use risotto_lib::update::{
decode_updates, format_update, synthesize_withdraw_update, UpdateHeader,
};
use std::io::{Error, ErrorKind, Result};
use std::sync::mpsc::Sender;
use tokio::io::AsyncReadExt;
Expand Down
24 changes: 17 additions & 7 deletions src/main.rs → risotto/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ mod api;
mod bmp;
mod producer;
mod settings;
mod state;
mod update;

use chrono::Local;
use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity};
use config::Config;
use env_logger::Builder;
use log::{debug, info};
use risotto_lib::state;
use risotto_lib::state::{AsyncState, State};
use std::error::Error;
use std::io::Write;
use std::sync::mpsc::{channel, Receiver, Sender};
Expand All @@ -19,8 +19,6 @@ use std::time::Duration;
use tokio::net::TcpListener;
use tokio_graceful::Shutdown;

use crate::state::AsyncState;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct CLI {
Expand Down Expand Up @@ -92,7 +90,19 @@ async fn producer_handler(cfg: Arc<Config>, rx: Receiver<Vec<u8>>) {
async fn state_handler(state: AsyncState, cfg: Arc<Config>) {
let cfg = settings::get_state_config(&cfg).unwrap();

state::dump_handler(state.clone(), cfg.clone()).await;
loop {
{
let state_lock: std::sync::MutexGuard<'_, State> = state.lock().unwrap();
if !state_lock.enable {
continue;
}

log::debug!("state - dump handler - dumping state");
state::dump(state.clone());
}

tokio::time::sleep(Duration::from_secs(cfg.interval)).await;
}
}

#[tokio::main]
Expand All @@ -101,14 +111,14 @@ async fn main() -> Result<(), Box<dyn Error>> {

let cfg = load_settings(&cli.config);
let state_config = settings::get_state_config(&cfg).unwrap();
let state = state::new_state(&state_config);
let state = state::new_state(state_config.path, state_config.enable);
let shutdown: Shutdown = Shutdown::default();

set_logging(&cli);

// Load the state if enabled
if state_config.enable {
state::load(state.clone(), state_config.clone());
state::load(state.clone());
}

// MPSC channel to communicate between BMP tasks and producer task
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 53f826e

Please sign in to comment.