Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Jun 7, 2023
1 parent cb8b729 commit 902638d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions aries_vcx/src/handlers/connection/mediated_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl MediatedConnection {
let (connection_sm, new_cloud_agent_info) = match &self.connection_sm {
SmConnection::Inviter(sm_inviter) => {
let send_message = self.send_message_closure_connection(Arc::clone(wallet));
let new_pairwise_info = PairwiseInfo::create(&profile.inject_wallet()).await?;
let new_pairwise_info = PairwiseInfo::create(wallet).await?;
let new_cloud_agent = CloudAgentInfo::create(agency_client, &new_pairwise_info).await?;
let new_routing_keys = new_cloud_agent.routing_keys(agency_client)?;
let new_service_endpoint = agency_client.get_agency_url_full()?;
Expand Down Expand Up @@ -346,12 +346,12 @@ impl MediatedConnection {
Ok(())
}

pub async fn send_response(&mut self, profile: &Arc<dyn Profile>) -> VcxResult<()> {
pub async fn send_response(&mut self, wallet: &Arc<dyn BaseWallet>) -> VcxResult<()> {
trace!("MediatedConnection::send_response >>>");
let connection_sm = match self.connection_sm.clone() {
SmConnection::Inviter(sm_inviter) => {
if let InviterFullState::Requested(_) = sm_inviter.state_object() {
let send_message = self.send_message_closure_connection(profile);
let send_message = self.send_message_closure_connection(Arc::clone(wallet));
sm_inviter.handle_send_response(send_message).await?
} else {
return Err(AriesVcxError::from_msg(AriesVcxErrorKind::NotReady, "Invalid action"));
Expand Down Expand Up @@ -380,21 +380,23 @@ impl MediatedConnection {
}
}

// TODO:::: check usage of this method in regards to profile usage
// TODO:::: check usage of this method in regards to profile usage
// TODO:::: check usage of this method in regards to profile usage
pub fn update_state_with_message(
&mut self,
profile: &Arc<dyn Profile>,
wallet: Arc<dyn BaseWallet>,
agency_client: AgencyClient,
message: Option<AriesMessage>,
) -> BoxFuture<'_, VcxResult<()>> {
let profile = Arc::clone(profile);
Box::pin(async move {
let (new_connection_sm, can_autohop) = match &self.connection_sm {
SmConnection::Inviter(_) => self.step_inviter(&profile, message, &agency_client).await?,
SmConnection::Invitee(_) => self.step_invitee(&profile, message).await?,
SmConnection::Inviter(_) => self.step_inviter(&wallet, message, &agency_client).await?,
SmConnection::Invitee(_) => self.step_invitee(&wallet, message).await?,
};
*self = new_connection_sm;
if can_autohop && self.autohop_enabled {
self.update_state_with_message(&profile, agency_client, None).await
self.update_state_with_message(wallet, agency_client, None).await
} else {
Ok(())
}
Expand Down Expand Up @@ -543,7 +545,7 @@ impl MediatedConnection {

async fn step_inviter(
&self,
profile: &Arc<dyn Profile>,
wallet: &Arc<dyn BaseWallet>,
message: Option<AriesMessage>,
agency_client: &AgencyClient,
) -> VcxResult<(Self, bool)> {
Expand All @@ -552,15 +554,15 @@ impl MediatedConnection {
let (sm_inviter, new_cloud_agent_info, can_autohop) = match message {
Some(message) => match message {
AriesMessage::Connection(Connection::Request(request)) => {
let send_message = self.send_message_closure_connection(profile);
let send_message = self.send_message_closure_connection(Arc::clone(wallet));
let new_pairwise_info = PairwiseInfo::create(&profile.inject_wallet()).await?;
let new_cloud_agent = CloudAgentInfo::create(agency_client, &new_pairwise_info).await?;
let new_routing_keys = new_cloud_agent.routing_keys(agency_client)?;
let new_service_endpoint = new_cloud_agent.service_endpoint(agency_client)?;

let sm_connection = sm_inviter
.handle_connection_request(
profile.inject_wallet(),
wallet,
request,
&new_pairwise_info,
new_routing_keys,
Expand All @@ -580,7 +582,7 @@ impl MediatedConnection {
},
None => {
if let InviterFullState::Requested(_) = sm_inviter.state_object() {
let send_message = self.send_message_closure_connection(profile);
let send_message = self.send_message_closure_connection(Arc::clone(wallet));
(sm_inviter.handle_send_response(send_message).await?, None, false)
} else {
(sm_inviter.clone(), None, false)
Expand All @@ -604,7 +606,7 @@ impl MediatedConnection {
}
}

async fn step_invitee(&self, profile: &Arc<dyn Profile>, message: Option<AriesMessage>) -> VcxResult<(Self, bool)> {
async fn step_invitee(&self, wallet: &Arc<dyn BaseWallet>,, message: Option<AriesMessage>) -> VcxResult<(Self, bool)> {
match self.connection_sm.clone() {
SmConnection::Invitee(sm_invitee) => {
let (sm_invitee, can_autohop) = match message {
Expand All @@ -618,10 +620,10 @@ impl MediatedConnection {
false,
),
AriesMessage::Connection(Connection::Response(response)) => {
let send_message = self.send_message_closure_connection(profile);
let send_message = self.send_message_closure_connection(Arc::clone(wallet));
(
sm_invitee
.handle_connection_response(&profile.inject_wallet(), response, send_message)
.handle_connection_response(wallet, response, send_message)
.await?,
true,
)
Expand All @@ -632,7 +634,7 @@ impl MediatedConnection {
_ => (sm_invitee, false),
},
None => {
let send_message = self.send_message_closure_connection(profile);
let send_message = self.send_message_closure_connection(Arc::clone(wallet));
(sm_invitee.handle_send_ack(send_message).await?, false)
}
};
Expand Down

0 comments on commit 902638d

Please sign in to comment.