diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-12-22 13:28:51 +0100 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-01-08 09:04:50 +0100 |
| commit | 9cace32ee3ea1c1d90991f75cf68d0d4208e0bf6 (patch) | |
| tree | 34a9bf334b7d4db889c45aca115896e9c0c624e1 | |
| parent | 1dbf5cda197562ee95eb62db1be815d2682b92f4 (diff) | |
| download | mullvadvpn-9cace32ee3ea1c1d90991f75cf68d0d4208e0bf6.tar.xz mullvadvpn-9cace32ee3ea1c1d90991f75cf68d0d4208e0bf6.zip | |
Implement handler for `NewAccessMethodEvent`
This commit implements the daemon logic for handling a
`NewAccessMethodEvent`. Such an event occur when `AccessModeSelector`
announces that a new access method is active, and it will cause the
daemon to except some API endpoint in the firewall. It may conditionally
broadcast the new access method to all clients.
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 88f85a3abc..b760c46d86 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -1336,7 +1336,31 @@ where } } - fn handle_access_method_event(&mut self, event: NewAccessMethodEvent) {} + fn handle_access_method_event( + &mut self, + event: NewAccessMethodEvent, + endpoint_active_tx: oneshot::Sender<()>, + ) { + // Update the firewall to exempt a new API endpoint. + let (completion_tx, completion_rx) = oneshot::channel(); + self.send_tunnel_command(TunnelCommand::AllowEndpoint(event.endpoint, completion_tx)); + // If the `NewAccessMethodEvent` should be announced to any client + // listening for updates of the currently active access method, we need + // to clone the handle to the broadcaster of such events. The + // announcement should be made after the firewall policy has been + // updated, since the new access method will be useless before then. + let event_listener = self.event_listener.clone(); + tokio::spawn(async move { + // Wait for the firewall policy to be updated. + let _ = completion_rx.await; + // Let the emitter of this event know that the firewall has been updated. + let _ = endpoint_active_tx.send(()); + // Notify clients about the change if necessary. + if event.announce { + event_listener.notify_new_access_method_event(event.setting); + } + }); + } fn handle_device_migration_event( &mut self, |
