Skip to content

Commit

Permalink
Implement handler for NewAccessMethodEvent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarkusPettersson98 committed Jan 3, 2024
1 parent fb35fc2 commit 1f4be82
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,29 @@ where
}
}

fn handle_access_method_event(&mut self, event: NewAccessMethodEvent) {}
fn handle_access_method_event(&mut self, event: NewAccessMethodEvent) {
// 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.
if let Some(event_source) = event.update_finished_tx {
let _ = event_source.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,
Expand Down

0 comments on commit 1f4be82

Please sign in to comment.