优化部署

This commit is contained in:
xiuting.xu
2026-05-12 15:23:09 +08:00
parent a4d674190a
commit 4c6b441753
18 changed files with 273 additions and 69 deletions

10
src/rtr/cache/core.rs vendored
View File

@@ -65,7 +65,7 @@ pub struct VersionState {
impl VersionState {
fn new(session_id: u16, serial: u32, snapshot: Snapshot, max_delta: u8) -> Self {
let rtr_payloads = Arc::new(snapshot.payloads_for_rtr());
let rtr_payloads = snapshot.rtr_payloads_for_rtr_arc();
Self {
session_id,
serial,
@@ -199,7 +199,7 @@ impl RtrCacheBuilder {
VersionState {
session_id: session_ids.as_array()[idx],
serial: serials[idx],
rtr_payloads: Arc::new(snapshot.payloads_for_rtr()),
rtr_payloads: snapshot.rtr_payloads_for_rtr_arc(),
snapshot: Arc::new(snapshot),
deltas: deltas[idx].clone(),
}
@@ -230,7 +230,7 @@ impl RtrCache {
self.availability = CacheAvailability::NoDataAvailable;
for version_state in &mut self.versions {
version_state.snapshot = Arc::new(Snapshot::empty());
version_state.rtr_payloads = Arc::new(Vec::new());
version_state.rtr_payloads = version_state.snapshot.rtr_payloads_for_rtr_arc();
version_state.deltas.clear();
}
}
@@ -247,7 +247,7 @@ impl RtrCache {
state.session_id = new_session_ids.get(v);
state.serial = 1;
state.snapshot = Arc::new(project_snapshot_for_version(source_snapshot, v));
state.rtr_payloads = Arc::new(state.snapshot.as_ref().payloads_for_rtr());
state.rtr_payloads = state.snapshot.rtr_payloads_for_rtr_arc();
state.deltas.clear();
}
self.last_update_end = DualTime::now();
@@ -362,7 +362,7 @@ impl RtrCache {
}
state.snapshot = Arc::new(projected);
state.rtr_payloads = Arc::new(state.snapshot.as_ref().payloads_for_rtr());
state.rtr_payloads = state.snapshot.rtr_payloads_for_rtr_arc();
Self::push_delta(
state,
self.max_delta,

View File

@@ -13,7 +13,7 @@ use crate::rtr::cache::SharedRtrCache;
use crate::rtr::server::config::RtrServiceConfig;
use crate::rtr::server::listener::RtrServer;
use crate::rtr::server::notifier::RtrNotifier;
use crate::rtr::server::ssh::load_rtr_ssh_runtime_config;
use crate::rtr::server::ssh::{SshAuthMode, load_rtr_ssh_runtime_config};
pub struct RtrService {
cache: SharedRtrCache,
@@ -167,6 +167,7 @@ impl RtrService {
authorized_keys_path: impl AsRef<Path>,
username: &str,
subsystem_name: &str,
auth_mode: SshAuthMode,
password: Option<&str>,
) -> JoinHandle<()> {
let host_key_path = host_key_path.as_ref().to_path_buf();
@@ -184,6 +185,7 @@ impl RtrService {
&authorized_keys_path,
&username,
&subsystem_name,
auth_mode,
password.as_deref(),
inactivity_timeout,
keepalive_interval,
@@ -213,6 +215,7 @@ impl RtrService {
authorized_keys_path: impl AsRef<Path>,
username: &str,
subsystem_name: &str,
auth_mode: SshAuthMode,
password: Option<&str>,
) -> RunningRtrService {
let tcp_handle = self.spawn_tcp(tcp_bind_addr);
@@ -222,6 +225,7 @@ impl RtrService {
authorized_keys_path,
username,
subsystem_name,
auth_mode,
password,
);
@@ -244,6 +248,7 @@ impl RtrService {
authorized_keys_path: impl AsRef<Path>,
username: &str,
subsystem_name: &str,
auth_mode: SshAuthMode,
password: Option<&str>,
) -> RunningRtrService {
let tcp_handle = self.spawn_tcp(tcp_bind_addr);
@@ -255,6 +260,7 @@ impl RtrService {
authorized_keys_path,
username,
subsystem_name,
auth_mode,
password,
);

View File

@@ -9,6 +9,32 @@ use russh::keys::ssh_key::{self, AuthorizedKeys};
use russh::server::Config as RusshServerConfig;
use russh::{MethodKind, MethodSet};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SshAuthMode {
Key,
Password,
Both,
}
impl SshAuthMode {
pub fn parse(value: &str) -> Option<Self> {
match value.trim().to_ascii_lowercase().as_str() {
"key" | "publickey" => Some(Self::Key),
"password" => Some(Self::Password),
"both" => Some(Self::Both),
_ => None,
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::Key => "key",
Self::Password => "password",
Self::Both => "both",
}
}
}
#[derive(Debug, Clone)]
pub struct RtrSshRuntimeConfig {
pub server_config: Arc<RusshServerConfig>,
@@ -23,6 +49,7 @@ pub fn load_rtr_ssh_runtime_config(
authorized_keys_path: impl AsRef<Path>,
username: &str,
subsystem_name: &str,
auth_mode: SshAuthMode,
password: Option<&str>,
inactivity_timeout: Option<Duration>,
keepalive_interval: Option<Duration>,
@@ -35,12 +62,21 @@ pub fn load_rtr_ssh_runtime_config(
}
let host_key = load_host_key(host_key_path.as_ref())?;
let authorized_keys = load_authorized_keys(authorized_keys_path.as_ref())?;
let authorized_keys = if matches!(auth_mode, SshAuthMode::Key | SshAuthMode::Both) {
load_authorized_keys(authorized_keys_path.as_ref())?
} else {
Vec::new()
};
let password = password.map(str::trim).filter(|value| !value.is_empty());
if matches!(auth_mode, SshAuthMode::Password | SshAuthMode::Both) && password.is_none() {
bail!("SSH auth mode '{}' requires non-empty password", auth_mode.as_str());
}
let mut methods = MethodSet::empty();
methods.push(MethodKind::PublicKey);
if password.is_some() {
if matches!(auth_mode, SshAuthMode::Key | SshAuthMode::Both) {
methods.push(MethodKind::PublicKey);
}
if matches!(auth_mode, SshAuthMode::Password | SshAuthMode::Both) {
methods.push(MethodKind::Password);
}