Commit 64c6814d authored by nanamicat's avatar nanamicat

config

parent d5b52d94
Pipeline #41944 passed with stages
in 2 minutes and 18 seconds
use crate::router::SECRET_LENGTH; use crate::router::SECRET_LENGTH;
use base64::prelude::BASE64_STANDARD;
use base64::Engine; use base64::Engine;
use base64::prelude::BASE64_STANDARD;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use socket2::Domain; use socket2::Domain;
#[derive(Deserialize, Clone)]
pub struct Config {
// 预留未来的全局配置,不把顶层删掉
pub routers: Vec<ConfigRouter>,
}
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone)]
pub struct ConfigRouter { pub struct ConfigRouter {
pub local_id: u8, pub local_id: u8,
......
mod config; mod config;
mod router; mod router;
use crate::config::{ConfigRouter, Schema}; use crate::config::{Config, Schema};
use crate::router::{Meta, Router, META_SIZE}; use crate::router::{META_SIZE, Meta, Router};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use crossbeam::epoch::{pin, Owned}; use crossbeam::epoch::{Owned, pin};
use crossbeam_utils::thread; use crossbeam_utils::thread;
use itertools::Itertools; use itertools::Itertools;
use std::net::Shutdown; use std::net::Shutdown;
use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::Ordering;
use std::time::Duration; use std::time::Duration;
use std::{collections::HashMap, env, mem::MaybeUninit}; use std::{collections::HashMap, env, mem::MaybeUninit};
fn main() -> Result<()> { fn main() -> Result<()> {
println!("Starting"); println!("Starting");
let config = serde_json::from_str::<Vec<ConfigRouter>>(env::args().nth(1).context("need param")?.as_str())?; let config = serde_json::from_str::<Config>(env::args().nth(1).context("need param")?.as_str())?;
let routers = &config let routers = &config
.routers
.into_iter() .into_iter()
.sorted_by_key(|r| r.remote_id) .sorted_by_key(|r| r.remote_id)
.map(|c| { .map(|c| Router::new(c).map(|router| (router.config.remote_id, router)))
let remote_id = c.remote_id;
Router::new(c).map(|router| (remote_id, router))
})
.collect::<Result<HashMap<u8, Router>, _>>()?; .collect::<Result<HashMap<u8, Router>, _>>()?;
for (_, group) in &routers for (_, group) in &routers
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment