-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update kernel peers on peer modification (#4622)
* Include wireguard in gw config * Support nym node first * Create wg keypair * Activate wg feature in gw dep * Move key paths to separate structure * Use client reg * Generate and use own private key * Rename network to ip for wg gw * Propagate wireguard setup error message * Remove logs * Bump gateway version number * Remove upgrade code * Init wireguard on migration * Upgrade code for nym-node too * Wireguard paths upgrade * Init wg keys on upgrade * Simplify pub key translatations * Fix clippy * Undo comment change * Fix tests * Don't bump version just yet * Remove redundant source attr * Remove unused wg details * Rename wg device * Init for mixnode migration as well * Add upgrade for gw wireguard deleted field * Move interface removal to Drop trait impl * Fix clippy * Wgapi could be included on other platforms * Handle peer control msgs * Send add peer msg * Handle double registration * Fix deadlock * Fix clippy * More clippy * Use same defguard * Fix unit test * Fix wasm build * Move implementations from types to wireguard crate * Fix linux
- Loading branch information
Showing
14 changed files
with
335 additions
and
190 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::Arc; | ||
|
||
use defguard_wireguard_rs::{host::Peer, key::Key, WireguardInterfaceApi}; | ||
use tokio::sync::mpsc; | ||
|
||
use crate::WgApiWrapper; | ||
|
||
pub enum PeerControlMessage { | ||
AddPeer(Peer), | ||
RemovePeer(Key), | ||
} | ||
|
||
pub struct PeerController { | ||
peer_rx: mpsc::UnboundedReceiver<PeerControlMessage>, | ||
wg_api: Arc<WgApiWrapper>, | ||
} | ||
|
||
impl PeerController { | ||
pub fn new( | ||
wg_api: Arc<WgApiWrapper>, | ||
peer_rx: mpsc::UnboundedReceiver<PeerControlMessage>, | ||
) -> Self { | ||
PeerController { wg_api, peer_rx } | ||
} | ||
|
||
pub async fn run(&mut self, mut task_client: nym_task::TaskClient) { | ||
loop { | ||
tokio::select! { | ||
_ = task_client.recv() => { | ||
log::trace!("PeerController handler: Received shutdown"); | ||
break; | ||
} | ||
msg = self.peer_rx.recv() => { | ||
match msg { | ||
Some(PeerControlMessage::AddPeer(peer)) => { | ||
if self.wg_api.inner.configure_peer(&peer).is_err() { | ||
log::error!("Could not configure peer {:?}", peer); | ||
} | ||
} | ||
Some(PeerControlMessage::RemovePeer(peer_pubkey)) => { | ||
if self.wg_api.inner.remove_peer(&peer_pubkey).is_err() { | ||
log::error!("Could not remove peer with key {:?}", peer_pubkey); | ||
} | ||
} | ||
None => { | ||
log::trace!("PeerController [main loop]: stopping since channel closed"); | ||
break; | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.