most of nym-node changes
This commit is contained in:
@@ -31,18 +31,29 @@ pub(crate) async fn host_information(
|
||||
let pre_announced = match state.x25519_sphinx_keys.secondary() {
|
||||
None => None,
|
||||
Some(secondary_key) => {
|
||||
todo!()
|
||||
if secondary_key.rotation_id() == primary_key.rotation_id() + 1 {
|
||||
Some(api_requests::v1::node::models::SphinxKey {
|
||||
rotation_id: secondary_key.rotation_id(),
|
||||
public_key: secondary_key.x25519_pubkey(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let primary_pubkey = primary_key.x25519_pubkey();
|
||||
|
||||
#[allow(deprecated)]
|
||||
let host_info = api_requests::v1::node::models::HostInformation {
|
||||
ip_address: state.static_information.ip_addresses.clone(),
|
||||
hostname: state.static_information.hostname.clone(),
|
||||
keys: api_requests::v1::node::models::HostKeys {
|
||||
ed25519_identity: *state.static_information.ed25519_identity_keys.public_key(),
|
||||
current_x25519_sphinx_key: api_requests::v1::node::models::SphinxKey {
|
||||
x25519_sphinx: primary_pubkey,
|
||||
primary_x25519_sphinx_key: api_requests::v1::node::models::SphinxKey {
|
||||
rotation_id: primary_key.rotation_id(),
|
||||
public_key: primary_key.x25519_pubkey(),
|
||||
public_key: primary_pubkey,
|
||||
},
|
||||
x25519_noise: state.static_information.x25519_noise_key,
|
||||
pre_announced_x25519_sphinx_key: pre_announced,
|
||||
|
||||
@@ -35,13 +35,12 @@ impl ActiveSphinxKeys {
|
||||
primary: SphinxPrivateKey,
|
||||
secondary: Option<SphinxPrivateKey>,
|
||||
) -> Self {
|
||||
todo!()
|
||||
// ActiveSphinxKeys {
|
||||
// inner: Arc::new(ActiveSphinxKeysInner {
|
||||
// primary_key: ArcSwap::from_pointee(primary),
|
||||
// secondary_key: ArcSwapOption::from_pointee(secondary),
|
||||
// }),
|
||||
// }
|
||||
ActiveSphinxKeys {
|
||||
inner: Arc::new(ActiveSphinxKeysInner {
|
||||
primary_key: ArcSwap::from_pointee(primary),
|
||||
secondary_key: ArcSwapOption::from_pointee(secondary),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn even(&self) -> Option<SphinxKeyGuard> {
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::node::key_rotation::manager::SphinxKeyManager;
|
||||
use crate::node::nym_apis_client::NymApisClient;
|
||||
use crate::node::replay_protection::manager::ReplayProtectionBloomfiltersManager;
|
||||
use futures::pin_mut;
|
||||
use nym_node_metrics::NymNodeMetrics;
|
||||
use nym_task::ShutdownToken;
|
||||
use nym_validator_client::models::{KeyRotationInfoResponse, KeyRotationState};
|
||||
use std::time::Duration;
|
||||
@@ -14,7 +13,7 @@ use time::OffsetDateTime;
|
||||
use tokio::time::{interval, sleep, Instant};
|
||||
use tracing::{error, info, trace, warn};
|
||||
|
||||
struct RotationConfig {
|
||||
pub(crate) struct RotationConfig {
|
||||
epoch_duration: Duration,
|
||||
rotation_state: KeyRotationState,
|
||||
}
|
||||
@@ -78,20 +77,24 @@ enum KeyRotationActionState {
|
||||
impl KeyRotationController {
|
||||
pub(crate) fn new(
|
||||
config: &Config,
|
||||
rotation_config: RotationConfig,
|
||||
client: NymApisClient,
|
||||
replay_protection_manager: ReplayProtectionBloomfiltersManager,
|
||||
metrics: NymNodeMetrics,
|
||||
managed_keys: SphinxKeyManager,
|
||||
shutdown_token: ShutdownToken,
|
||||
) -> Self {
|
||||
todo!()
|
||||
// KeyRotationController {
|
||||
// regular_polling_interval,
|
||||
// replay_protection_manager,
|
||||
// client,
|
||||
// managed_keys,
|
||||
// shutdown_token,
|
||||
// }
|
||||
KeyRotationController {
|
||||
regular_polling_interval: config
|
||||
.mixnet
|
||||
.key_rotation
|
||||
.debug
|
||||
.rotation_state_poling_interval,
|
||||
rotation_config,
|
||||
replay_protection_manager,
|
||||
client,
|
||||
managed_keys,
|
||||
shutdown_token,
|
||||
}
|
||||
}
|
||||
|
||||
async fn determine_next_action(&self) -> NextAction {
|
||||
@@ -234,7 +237,7 @@ impl KeyRotationController {
|
||||
polling_interval.reset();
|
||||
|
||||
let mut next_action = self.determine_next_action().await;
|
||||
let mut state_update_future = sleep(next_action.until_deadline());
|
||||
let state_update_future = sleep(next_action.until_deadline());
|
||||
pin_mut!(state_update_future);
|
||||
|
||||
while !self.shutdown_token.is_cancelled() {
|
||||
|
||||
@@ -180,7 +180,7 @@ impl SphinxKeyManager {
|
||||
// immediately rotate keys (but leave 1h grace period for current primary, i.e. set it as secondary)
|
||||
if primary.rotation_id() != current_rotation_id {
|
||||
warn!("this node has been inactive for more than a key rotation duration. the current primary key was generated for rotation {} while the current rotation is {current_rotation_id}. new key will be generated now.", primary.rotation_id());
|
||||
let mut this = SphinxKeyManager {
|
||||
let this = SphinxKeyManager {
|
||||
keys: ActiveSphinxKeys::new_loaded(primary, None),
|
||||
primary_key_path: primary_key_path.as_ref().to_path_buf(),
|
||||
secondary_key_path: secondary_key_path.as_ref().to_path_buf(),
|
||||
|
||||
@@ -1003,11 +1003,13 @@ impl NymNode {
|
||||
replay_protection_manager: ReplayProtectionBloomfiltersManager,
|
||||
) -> Result<(), NymNodeError> {
|
||||
let managed_keys = self.take_managed_sphinx_keys()?;
|
||||
let rotation_state = nym_apis_client.get_key_rotation_info().await?;
|
||||
|
||||
let rotation_controller = KeyRotationController::new(
|
||||
&self.config,
|
||||
rotation_state.into(),
|
||||
nym_apis_client,
|
||||
replay_protection_manager,
|
||||
self.metrics.clone(),
|
||||
managed_keys,
|
||||
self.shutdown_manager.clone_token("key-rotation-controller"),
|
||||
);
|
||||
|
||||
@@ -210,7 +210,7 @@ impl ReplayProtectionBloomfilters {
|
||||
})?;
|
||||
|
||||
let id = guard.primary.metadata.rotation_id;
|
||||
let bytes = guard.primary.data.to_bytes();
|
||||
let bytes = guard.primary.bytes();
|
||||
Ok((bytes, id))
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ impl ReplayProtectionBloomfilters {
|
||||
};
|
||||
|
||||
let id = secondary.metadata.rotation_id;
|
||||
let bytes = secondary.data.to_bytes();
|
||||
let bytes = secondary.bytes();
|
||||
Ok(Some((bytes, id)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user