refactor: rename to to better reflect meaning
This commit is contained in:
@@ -48,7 +48,7 @@ impl Bootstrapper {
|
||||
let row_count: i64 = {
|
||||
let mut conn = db.get().await?;
|
||||
|
||||
schema::useragent_client::table
|
||||
schema::operator_client::table
|
||||
.count()
|
||||
.get_result(&mut conn)
|
||||
.await?
|
||||
|
||||
@@ -134,7 +134,7 @@ impl EvmActor {
|
||||
#[messages]
|
||||
impl EvmActor {
|
||||
#[message]
|
||||
pub async fn useragent_create_grant(
|
||||
pub async fn operator_create_grant(
|
||||
&mut self,
|
||||
basic: SharedGrantSettings,
|
||||
grant: SpecificGrant,
|
||||
@@ -161,7 +161,7 @@ impl EvmActor {
|
||||
|
||||
#[message]
|
||||
#[expect(clippy::unused_async, reason = "reserved for impl")]
|
||||
pub async fn useragent_delete_grant(&mut self, _grant_id: i32) -> Result<(), Error> {
|
||||
pub async fn operator_delete_grant(&mut self, _grant_id: i32) -> Result<(), Error> {
|
||||
// let mut conn = self.db.get().await.map_err(DatabaseError::from)?;
|
||||
// let vault = self.vault.clone();
|
||||
|
||||
@@ -186,7 +186,7 @@ impl EvmActor {
|
||||
}
|
||||
|
||||
#[message]
|
||||
pub async fn useragent_list_grants(&mut self) -> Result<Vec<Grant<SpecificGrant>>, Error> {
|
||||
pub async fn operator_list_grants(&mut self) -> Result<Vec<Grant<SpecificGrant>>, Error> {
|
||||
match self.engine.list_all_grants().await {
|
||||
Ok(grants) => Ok(grants),
|
||||
Err(ListError::Database(db_err)) => Err(Error::Database(db_err)),
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
actors::flow_coordinator::ApprovalError,
|
||||
peers::{
|
||||
client::ClientProfile,
|
||||
user_agent::{UserAgentSession, session::BeginNewClientApproval},
|
||||
operator::{OperatorSession, session::BeginNewClientApproval},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -15,12 +15,12 @@ use std::ops::ControlFlow;
|
||||
|
||||
pub struct Args {
|
||||
pub client: ClientProfile,
|
||||
pub user_agents: Vec<ActorRef<UserAgentSession>>,
|
||||
pub operators: Vec<ActorRef<OperatorSession>>,
|
||||
pub reply: ReplySender<Result<bool, ApprovalError>>,
|
||||
}
|
||||
|
||||
pub struct ClientApprovalController {
|
||||
/// Number of UAs that have not yet responded (approval or denial) or died.
|
||||
/// Number of operators that have not yet responded (approval or denial) or died.
|
||||
pending: usize,
|
||||
/// Number of approvals received so far.
|
||||
approved: usize,
|
||||
@@ -42,21 +42,21 @@ impl Actor for ClientApprovalController {
|
||||
async fn on_start(
|
||||
Args {
|
||||
client,
|
||||
user_agents,
|
||||
operators,
|
||||
reply,
|
||||
}: Self::Args,
|
||||
actor_ref: ActorRef<Self>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
let this = Self {
|
||||
pending: user_agents.len(),
|
||||
pending: operators.len(),
|
||||
approved: 0,
|
||||
reply: Some(reply),
|
||||
};
|
||||
|
||||
for user_agent in user_agents {
|
||||
actor_ref.link(&user_agent).await;
|
||||
for operator in operators {
|
||||
actor_ref.link(&operator).await;
|
||||
|
||||
let _ = user_agent
|
||||
let _ = operator
|
||||
.tell(BeginNewClientApproval {
|
||||
client: client.clone(),
|
||||
controller: actor_ref.clone(),
|
||||
@@ -73,10 +73,10 @@ impl Actor for ClientApprovalController {
|
||||
_: ActorId,
|
||||
_: ActorStopReason,
|
||||
) -> Result<ControlFlow<ActorStopReason>, Self::Error> {
|
||||
// A linked UA died before responding — counts as a non-approval.
|
||||
// A linked operator died before responding — counts as a non-approval.
|
||||
self.pending = self.pending.saturating_sub(1);
|
||||
if self.pending == 0 {
|
||||
// At least one UA didn't approve: deny.
|
||||
// At least one operator didn't approve: deny.
|
||||
self.send_reply(Ok(false));
|
||||
return Ok(ControlFlow::Break(ActorStopReason::Normal));
|
||||
}
|
||||
@@ -99,7 +99,7 @@ impl ClientApprovalController {
|
||||
self.pending = self.pending.saturating_sub(1);
|
||||
|
||||
if self.pending == 0 {
|
||||
// Every connected UA approved.
|
||||
// Every connected operator approved.
|
||||
self.send_reply(Ok(true));
|
||||
ctx.stop();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
actors::{
|
||||
flow_coordinator::client_connect_approval::ClientApprovalController,
|
||||
useragent_registry::{GetConnected, UserAgentRegistry},
|
||||
operator_registry::{GetConnected, OperatorRegistry},
|
||||
},
|
||||
peers::client::{ClientProfile, session::ClientSession},
|
||||
};
|
||||
@@ -20,14 +20,14 @@ pub mod client_connect_approval;
|
||||
|
||||
pub struct FlowCoordinator {
|
||||
pub clients: HashMap<ActorId, ActorRef<ClientSession>>,
|
||||
useragent_registry: ActorRef<UserAgentRegistry>,
|
||||
operator_registry: ActorRef<OperatorRegistry>,
|
||||
}
|
||||
|
||||
impl FlowCoordinator {
|
||||
pub fn new(useragent_registry: ActorRef<UserAgentRegistry>) -> Self {
|
||||
pub fn new(operator_registry: ActorRef<OperatorRegistry>) -> Self {
|
||||
Self {
|
||||
clients: HashMap::default(),
|
||||
useragent_registry,
|
||||
operator_registry,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,8 @@ impl Actor for FlowCoordinator {
|
||||
|
||||
#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ApprovalError {
|
||||
#[error("No user agents connected")]
|
||||
NoUserAgentsConnected,
|
||||
#[error("No operators connected")]
|
||||
NoOperatorsConnected,
|
||||
}
|
||||
|
||||
#[messages]
|
||||
@@ -93,19 +93,19 @@ impl FlowCoordinator {
|
||||
unreachable!("Expected `request_client_approval` to have callback channel");
|
||||
};
|
||||
|
||||
let Ok(refs) = self.useragent_registry.ask(GetConnected).await else {
|
||||
reply_sender.send(Err(ApprovalError::NoUserAgentsConnected));
|
||||
let Ok(refs) = self.operator_registry.ask(GetConnected).await else {
|
||||
reply_sender.send(Err(ApprovalError::NoOperatorsConnected));
|
||||
return reply;
|
||||
};
|
||||
|
||||
if refs.is_empty() {
|
||||
reply_sender.send(Err(ApprovalError::NoUserAgentsConnected));
|
||||
reply_sender.send(Err(ApprovalError::NoOperatorsConnected));
|
||||
return reply;
|
||||
}
|
||||
|
||||
ClientApprovalController::spawn(client_connect_approval::Args {
|
||||
client,
|
||||
user_agents: refs,
|
||||
operators: refs,
|
||||
reply: reply_sender,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
actors::{
|
||||
bootstrap::Bootstrapper, evm::EvmActor, flow_coordinator::FlowCoordinator,
|
||||
useragent_registry::UserAgentRegistry, vault::Vault,
|
||||
operator_registry::OperatorRegistry, vault::Vault,
|
||||
},
|
||||
db,
|
||||
};
|
||||
@@ -13,7 +13,7 @@ use thiserror::Error;
|
||||
pub mod bootstrap;
|
||||
pub mod evm;
|
||||
pub mod flow_coordinator;
|
||||
pub mod useragent_registry;
|
||||
pub mod operator_registry;
|
||||
pub mod vault;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -31,7 +31,7 @@ pub struct GlobalActors {
|
||||
pub vault: ActorRef<Vault>,
|
||||
pub bootstrapper: ActorRef<Bootstrapper>,
|
||||
pub flow_coordinator: ActorRef<FlowCoordinator>,
|
||||
pub useragent_registry: ActorRef<UserAgentRegistry>,
|
||||
pub operator_registry: ActorRef<OperatorRegistry>,
|
||||
pub evm: ActorRef<EvmActor>,
|
||||
pub events: ActorRef<MessageBus>,
|
||||
}
|
||||
@@ -44,15 +44,15 @@ impl GlobalActors {
|
||||
pub async fn spawn(db: db::DatabasePool) -> Result<Self, SpawnError> {
|
||||
let message_bus = Self::spawn_message_bus();
|
||||
let key_holder = Vault::spawn(Vault::new(db.clone(), message_bus.clone()).await?);
|
||||
let useragent_registry = UserAgentRegistry::spawn(UserAgentRegistry::default());
|
||||
let operator_registry = OperatorRegistry::spawn(OperatorRegistry::default());
|
||||
Ok(Self {
|
||||
bootstrapper: Bootstrapper::spawn(Bootstrapper::new(&db).await?),
|
||||
evm: EvmActor::spawn(EvmActor::new(key_holder.clone(), db)),
|
||||
vault: key_holder,
|
||||
flow_coordinator: FlowCoordinator::spawn(FlowCoordinator::new(
|
||||
useragent_registry.clone(),
|
||||
operator_registry.clone(),
|
||||
)),
|
||||
useragent_registry,
|
||||
operator_registry,
|
||||
events: message_bus,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::peers::user_agent::UserAgentSession;
|
||||
use crate::peers::operator::OperatorSession;
|
||||
|
||||
use kameo::{
|
||||
Actor,
|
||||
@@ -11,11 +11,11 @@ use std::{collections::HashMap, ops::ControlFlow};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct UserAgentRegistry {
|
||||
connected: HashMap<ActorId, ActorRef<UserAgentSession>>,
|
||||
pub struct OperatorRegistry {
|
||||
connected: HashMap<ActorId, ActorRef<OperatorSession>>,
|
||||
}
|
||||
|
||||
impl Actor for UserAgentRegistry {
|
||||
impl Actor for OperatorRegistry {
|
||||
type Args = Self;
|
||||
|
||||
type Error = Infallible;
|
||||
@@ -33,8 +33,8 @@ impl Actor for UserAgentRegistry {
|
||||
if self.connected.remove(&id).is_some() {
|
||||
info!(
|
||||
?id,
|
||||
actor = "UserAgentRegistry",
|
||||
event = "useragent.disconnected"
|
||||
actor = "OperatorRegistry",
|
||||
event = "operator.disconnected"
|
||||
);
|
||||
}
|
||||
Ok(ControlFlow::Continue(()))
|
||||
@@ -42,20 +42,20 @@ impl Actor for UserAgentRegistry {
|
||||
}
|
||||
|
||||
#[messages]
|
||||
impl UserAgentRegistry {
|
||||
impl OperatorRegistry {
|
||||
#[message(ctx)]
|
||||
pub async fn connect_useragent(
|
||||
pub async fn connect_operator(
|
||||
&mut self,
|
||||
actor: ActorRef<UserAgentSession>,
|
||||
actor: ActorRef<OperatorSession>,
|
||||
ctx: &mut Context<Self, ()>,
|
||||
) {
|
||||
info!(id = %actor.id(), actor = "UserAgentRegistry", event = "useragent.connected");
|
||||
info!(id = %actor.id(), actor = "OperatorRegistry", event = "operator.connected");
|
||||
ctx.actor_ref().link(&actor).await;
|
||||
self.connected.insert(actor.id(), actor);
|
||||
}
|
||||
|
||||
#[message]
|
||||
pub fn get_connected(&self) -> Vec<ActorRef<UserAgentSession>> {
|
||||
pub fn get_connected(&self) -> Vec<ActorRef<OperatorSession>> {
|
||||
self.connected.values().cloned().collect()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user