refactor: rename to to better reflect meaning
This commit is contained in:
@@ -54,7 +54,7 @@ impl From<diesel::result::Error> for Error {
|
||||
pub enum ApproveError {
|
||||
#[error("Internal error")]
|
||||
Internal,
|
||||
#[error("Client connection denied by user agents")]
|
||||
#[error("Client connection denied by operators")]
|
||||
Denied,
|
||||
#[error("Upstream error: {0}")]
|
||||
Upstream(flow_coordinator::ApprovalError),
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod client;
|
||||
pub mod user_agent;
|
||||
pub mod operator;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{Credentials, UserAgentConnection};
|
||||
use super::{Credentials, OperatorConnection};
|
||||
use arbiter_crypto::authn::{self, AuthChallenge};
|
||||
use arbiter_proto::transport::Bi;
|
||||
|
||||
@@ -69,7 +69,7 @@ fn parse_auth_event(payload: Inbound) -> AuthEvents {
|
||||
}
|
||||
|
||||
pub async fn authenticate<T>(
|
||||
props: &mut UserAgentConnection,
|
||||
props: &mut OperatorConnection,
|
||||
transport: &mut T,
|
||||
) -> Result<Credentials, Error>
|
||||
where
|
||||
@@ -1,13 +1,13 @@
|
||||
use super::{
|
||||
super::{Credentials, UserAgentConnection},
|
||||
super::{Credentials, OperatorConnection},
|
||||
Error,
|
||||
};
|
||||
use crate::{
|
||||
actors::bootstrap::ConsumeToken,
|
||||
db::{DatabasePool, schema::useragent_client},
|
||||
peers::user_agent::auth::Outbound,
|
||||
db::{DatabasePool, schema::operator_client},
|
||||
peers::operator::auth::Outbound,
|
||||
};
|
||||
use arbiter_crypto::authn::{self, AuthChallenge, USERAGENT_CONTEXT};
|
||||
use arbiter_crypto::authn::{self, AuthChallenge, OPERATOR_CONTEXT};
|
||||
use arbiter_proto::transport::Bi;
|
||||
|
||||
use diesel::{ExpressionMethods as _, OptionalExtension as _, QueryDsl};
|
||||
@@ -44,9 +44,9 @@ async fn get_client_id(db: &DatabasePool, pubkey: &authn::PublicKey) -> Result<O
|
||||
Error::internal("Database unavailable")
|
||||
})?;
|
||||
|
||||
useragent_client::table
|
||||
.filter(useragent_client::public_key.eq(pubkey.to_bytes()))
|
||||
.select(useragent_client::id)
|
||||
operator_client::table
|
||||
.filter(operator_client::public_key.eq(pubkey.to_bytes()))
|
||||
.select(operator_client::id)
|
||||
.first::<i32>(&mut conn)
|
||||
.await
|
||||
.optional()
|
||||
@@ -63,9 +63,9 @@ async fn register_key(db: &DatabasePool, pubkey: &authn::PublicKey) -> Result<i3
|
||||
Error::internal("Database unavailable")
|
||||
})?;
|
||||
|
||||
let id: i32 = diesel::insert_into(useragent_client::table)
|
||||
.values((useragent_client::public_key.eq(pubkey_bytes),))
|
||||
.returning(useragent_client::id)
|
||||
let id: i32 = diesel::insert_into(operator_client::table)
|
||||
.values((operator_client::public_key.eq(pubkey_bytes),))
|
||||
.returning(operator_client::id)
|
||||
.get_result(&mut conn)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
@@ -77,12 +77,12 @@ async fn register_key(db: &DatabasePool, pubkey: &authn::PublicKey) -> Result<i3
|
||||
}
|
||||
|
||||
pub(super) struct AuthContext<'a, T: ?Sized> {
|
||||
pub(super) conn: &'a mut UserAgentConnection,
|
||||
pub(super) conn: &'a mut OperatorConnection,
|
||||
pub(super) transport: &'a mut T,
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized> AuthContext<'a, T> {
|
||||
pub(super) const fn new(conn: &'a mut UserAgentConnection, transport: &'a mut T) -> Self {
|
||||
pub(super) const fn new(conn: &'a mut OperatorConnection, transport: &'a mut T) -> Self {
|
||||
Self { conn, transport }
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ where
|
||||
Error::InvalidChallengeSolution
|
||||
})?;
|
||||
|
||||
let valid = pubkey.verify(challenge, USERAGENT_CONTEXT, &signature);
|
||||
let valid = pubkey.verify(challenge, OPERATOR_CONTEXT, &signature);
|
||||
|
||||
if !valid {
|
||||
self.transport
|
||||
@@ -17,7 +17,7 @@ use tokio::sync::oneshot;
|
||||
use tracing::{error, warn};
|
||||
|
||||
pub use auth::authenticate;
|
||||
pub use session::UserAgentSession;
|
||||
pub use session::OperatorSession;
|
||||
|
||||
pub mod auth;
|
||||
pub mod session;
|
||||
@@ -30,10 +30,10 @@ pub struct Credentials {
|
||||
}
|
||||
|
||||
impl Integrable for Credentials {
|
||||
const KIND: &'static str = "useragent_credentials";
|
||||
const KIND: &'static str = "operator_credentials";
|
||||
}
|
||||
|
||||
// Messages, sent by user agent to connection client without having a request
|
||||
// Messages, sent by operator to connection client without having a request
|
||||
#[derive(Debug)]
|
||||
pub enum OutOfBand {
|
||||
ClientConnectionRequest { profile: ClientProfile },
|
||||
@@ -41,12 +41,12 @@ pub enum OutOfBand {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UserAgentConnection {
|
||||
pub struct OperatorConnection {
|
||||
pub(crate) db: DatabasePool,
|
||||
pub(crate) actors: GlobalActors,
|
||||
}
|
||||
|
||||
impl UserAgentConnection {
|
||||
impl OperatorConnection {
|
||||
pub const fn new(db: DatabasePool, actors: GlobalActors) -> Self {
|
||||
Self { db, actors }
|
||||
}
|
||||
@@ -106,7 +106,7 @@ async fn should_run_gate(vault: &ActorRef<Vault>) -> Result<bool, Error> {
|
||||
}
|
||||
|
||||
async fn run_vault_gate<T>(
|
||||
props: &UserAgentConnection,
|
||||
props: &OperatorConnection,
|
||||
transport: &mut T,
|
||||
auth_creds: Credentials,
|
||||
) -> Result<(), Error>
|
||||
@@ -160,10 +160,10 @@ where
|
||||
}
|
||||
|
||||
pub async fn start<T>(
|
||||
props: &mut UserAgentConnection,
|
||||
props: &mut OperatorConnection,
|
||||
mut transport: T,
|
||||
oob_sender: Box<dyn Sender<OutOfBand>>,
|
||||
) -> Result<ActorRef<UserAgentSession>, Error>
|
||||
) -> Result<ActorRef<OperatorSession>, Error>
|
||||
where
|
||||
T: Bi<auth::Inbound, Result<auth::Outbound, auth::Error>> + Send,
|
||||
T: Bi<vault_gate::Inbound, Result<vault_gate::Outbound, vault_gate::Error>> + Send,
|
||||
@@ -178,7 +178,7 @@ where
|
||||
// checking the integrity
|
||||
verify_integrity(&props.db, &props.actors.vault, &creds).await?;
|
||||
|
||||
Ok(UserAgentSession::spawn(UserAgentSession::new(
|
||||
Ok(OperatorSession::spawn(OperatorSession::new(
|
||||
props.clone(),
|
||||
oob_sender,
|
||||
)))
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::{Error, UserAgentSession};
|
||||
use super::{Error, OperatorSession};
|
||||
use crate::{
|
||||
actors::evm::{
|
||||
ClientSignTransaction, Generate, ListWallets, SignTransactionError as EvmSignError,
|
||||
UseragentCreateGrant, UseragentListGrants,
|
||||
OperatorCreateGrant, OperatorListGrants,
|
||||
},
|
||||
actors::flow_coordinator::client_connect_approval::ClientApprovalAnswer,
|
||||
actors::vault::VaultState,
|
||||
@@ -36,7 +36,7 @@ pub enum GrantMutationError {
|
||||
}
|
||||
|
||||
#[messages]
|
||||
impl UserAgentSession {
|
||||
impl OperatorSession {
|
||||
#[message]
|
||||
pub(crate) async fn handle_query_vault_state(&mut self) -> Result<VaultState, Error> {
|
||||
use crate::actors::vault::GetState;
|
||||
@@ -44,7 +44,7 @@ impl UserAgentSession {
|
||||
let vault_state = match self.props.actors.vault.ask(GetState {}).await {
|
||||
Ok(state) => state,
|
||||
Err(err) => {
|
||||
error!(?err, actor = "useragent", "vault.query.failed");
|
||||
error!(?err, actor = "operator", "vault.query.failed");
|
||||
return Err(Error::internal("Vault is in broken state"));
|
||||
}
|
||||
};
|
||||
@@ -54,7 +54,7 @@ impl UserAgentSession {
|
||||
}
|
||||
|
||||
#[messages]
|
||||
impl UserAgentSession {
|
||||
impl OperatorSession {
|
||||
#[message]
|
||||
pub(crate) async fn handle_evm_wallet_create(&mut self) -> Result<(i32, Address), Error> {
|
||||
match self.props.actors.evm.ask(Generate {}).await {
|
||||
@@ -82,10 +82,10 @@ impl UserAgentSession {
|
||||
}
|
||||
|
||||
#[messages]
|
||||
impl UserAgentSession {
|
||||
impl OperatorSession {
|
||||
#[message]
|
||||
pub(crate) async fn handle_grant_list(&mut self) -> Result<Vec<Grant<SpecificGrant>>, Error> {
|
||||
match self.props.actors.evm.ask(UseragentListGrants {}).await {
|
||||
match self.props.actors.evm.ask(OperatorListGrants {}).await {
|
||||
Ok(grants) => Ok(grants),
|
||||
Err(err) => {
|
||||
error!(?err, "EVM grant list failed");
|
||||
@@ -104,7 +104,7 @@ impl UserAgentSession {
|
||||
.props
|
||||
.actors
|
||||
.evm
|
||||
.ask(UseragentCreateGrant { basic, grant })
|
||||
.ask(OperatorCreateGrant { basic, grant })
|
||||
.await
|
||||
{
|
||||
Ok(grant_id) => Ok(grant_id),
|
||||
@@ -121,7 +121,7 @@ impl UserAgentSession {
|
||||
// .props
|
||||
// .actors
|
||||
// .evm
|
||||
// .ask(UseragentDeleteGrant { grant_id })
|
||||
// .ask(OperatorDeleteGrant { grant_id })
|
||||
// .await
|
||||
// {
|
||||
// Ok(()) => Ok(()),
|
||||
@@ -157,7 +157,7 @@ impl UserAgentSession {
|
||||
Err(SignTransactionError::Vet(vet_error))
|
||||
}
|
||||
Err(err) => {
|
||||
error!(?err, "EVM sign transaction failed in user-agent session");
|
||||
error!(?err, "EVM sign transaction failed in operator session");
|
||||
Err(SignTransactionError::Internal)
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ impl UserAgentSession {
|
||||
}
|
||||
|
||||
#[messages]
|
||||
impl UserAgentSession {
|
||||
impl OperatorSession {
|
||||
#[message(ctx)]
|
||||
pub(crate) async fn handle_new_client_approve(
|
||||
&mut self,
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::{OutOfBand, UserAgentConnection};
|
||||
use super::{OutOfBand, OperatorConnection};
|
||||
use crate::{
|
||||
actors::{
|
||||
flow_coordinator::client_connect_approval::ClientApprovalController,
|
||||
useragent_registry::ConnectUseragent,
|
||||
operator_registry::ConnectOperator,
|
||||
},
|
||||
peers::client::ClientProfile,
|
||||
};
|
||||
@@ -49,8 +49,8 @@ pub struct PendingClientApproval {
|
||||
controller: ActorRef<ClientApprovalController>,
|
||||
}
|
||||
|
||||
pub struct UserAgentSession {
|
||||
props: UserAgentConnection,
|
||||
pub struct OperatorSession {
|
||||
props: OperatorConnection,
|
||||
sender: Box<dyn Sender<OutOfBand>>,
|
||||
|
||||
pending_client_approvals: HashMap<Vec<u8>, PendingClientApproval>,
|
||||
@@ -58,8 +58,8 @@ pub struct UserAgentSession {
|
||||
|
||||
pub mod handlers;
|
||||
|
||||
impl UserAgentSession {
|
||||
pub(crate) fn new(props: UserAgentConnection, sender: Box<dyn Sender<OutOfBand>>) -> Self {
|
||||
impl OperatorSession {
|
||||
pub(crate) fn new(props: OperatorConnection, sender: Box<dyn Sender<OutOfBand>>) -> Self {
|
||||
Self {
|
||||
props,
|
||||
sender,
|
||||
@@ -69,7 +69,7 @@ impl UserAgentSession {
|
||||
}
|
||||
|
||||
#[messages]
|
||||
impl UserAgentSession {
|
||||
impl OperatorSession {
|
||||
#[message]
|
||||
pub async fn begin_new_client_approval(
|
||||
&mut self,
|
||||
@@ -85,7 +85,7 @@ impl UserAgentSession {
|
||||
{
|
||||
error!(
|
||||
?e,
|
||||
actor = "user_agent",
|
||||
actor = "operator",
|
||||
event = "failed to announce new client connection"
|
||||
);
|
||||
return;
|
||||
@@ -101,7 +101,7 @@ impl UserAgentSession {
|
||||
}
|
||||
}
|
||||
|
||||
impl Actor for UserAgentSession {
|
||||
impl Actor for OperatorSession {
|
||||
type Args = Self;
|
||||
|
||||
type Error = Error;
|
||||
@@ -109,17 +109,17 @@ impl Actor for UserAgentSession {
|
||||
async fn on_start(args: Self::Args, this: ActorRef<Self>) -> Result<Self, Self::Error> {
|
||||
args.props
|
||||
.actors
|
||||
.useragent_registry
|
||||
.ask(ConnectUseragent {
|
||||
.operator_registry
|
||||
.ask(ConnectOperator {
|
||||
actor: this.clone(),
|
||||
})
|
||||
.await
|
||||
.map_err(|err| {
|
||||
error!(
|
||||
?err,
|
||||
"Failed to register user agent connection with user agent registry"
|
||||
"Failed to register operator connection with operator registry"
|
||||
);
|
||||
Error::internal("Failed to register user agent connection with user agent registry")
|
||||
Error::internal("Failed to register operator connection with operator registry")
|
||||
})?;
|
||||
Ok(args)
|
||||
}
|
||||
@@ -149,7 +149,7 @@ impl Actor for UserAgentSession {
|
||||
{
|
||||
error!(
|
||||
?e,
|
||||
actor = "user_agent",
|
||||
actor = "operator",
|
||||
event = "failed to announce client connection cancellation"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user