-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from EspressoSystems/rm/retroactive-whitelist
Retroactively remove users based on the whitelist
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ pub mod heartbeat; | |
pub mod listener; | ||
pub mod sender; | ||
pub mod sync; | ||
pub mod whitelist; |
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,45 @@ | ||
// Copyright (c) 2024 Espresso Systems (espressosys.com) | ||
// This file is part of the Push-CDN repository. | ||
|
||
// You should have received a copy of the MIT License | ||
// along with the Push-CDN repository. If not, see <https://mit-license.org/>. | ||
|
||
//! The sync task syncs both users and topics to other brokers. | ||
use std::{sync::Arc, time::Duration}; | ||
|
||
use cdn_proto::{def::RunDef, discovery::DiscoveryClient}; | ||
use tokio::time::sleep; | ||
|
||
use crate::Inner; | ||
|
||
impl<Def: RunDef> Inner<Def> { | ||
/// Run the whitelist task. This is responsible for checking if users are still whitelisted | ||
/// and kicking them off the network if they are not. | ||
pub async fn run_whitelist_task(self: Arc<Self>) { | ||
// Clone the discovery client because it's behind an `Arc` | ||
let mut discovery_client = self.discovery_client.clone(); | ||
|
||
loop { | ||
// Run every minute | ||
sleep(Duration::from_secs(60)).await; | ||
|
||
// Get a list of all users | ||
let users = self.connections.read().all_users(); | ||
|
||
// Make sure each user is still whitelisted | ||
for user in users { | ||
if !discovery_client | ||
.check_whitelist(&user) | ||
.await | ||
.unwrap_or(true) | ||
{ | ||
// Kick the user off the network if they are not | ||
self.connections | ||
.write() | ||
.remove_user(user, "not in whitelist"); | ||
} | ||
} | ||
} | ||
} | ||
} |