Skip to content

Commit

Permalink
add /msg to criteria of active participants (#894)
Browse files Browse the repository at this point in the history
* add /msg to criteria of active participants 

---------

Co-authored-by: Serhii Volovyk <[email protected]>
  • Loading branch information
ppca and volovyks authored Oct 25, 2024
1 parent 20aacf6 commit a8fa2aa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chain-signatures/node/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum SendError {
ParticipantNotAlive(String),
}

async fn send_encrypted<U: IntoUrl>(
pub async fn send_encrypted<U: IntoUrl>(
from: Participant,
client: &Client,
url: U,
Expand Down
43 changes: 35 additions & 8 deletions chain-signatures/node/src/mesh/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::protocol::contract::primitives::Participants;
use crate::protocol::ParticipantInfo;
use crate::protocol::ProtocolState;
use crate::web::StateView;
use mpc_keys::hpke::Ciphered;

// TODO: this is a basic connection pool and does not do most of the work yet. This is
// mostly here just to facilitate offline node handling for now.
Expand Down Expand Up @@ -71,10 +72,15 @@ impl Pool {
let mut participants = Participants::default();
for (participant, info) in connections.iter() {
match self.fetch_participant_state(info).await {
Ok(state) => {
status.insert(*participant, state);
participants.insert(participant, info.clone());
}
Ok(state) => match self.send_empty_msg(participant, info).await {
Ok(()) => {
status.insert(*participant, state);
participants.insert(participant, info.clone());
}
Err(e) => {
tracing::warn!("Send empty msg for participant {participant:?} with url {} has failed with error {e}.", info.url);
}
},
Err(e) => {
tracing::warn!("Fetch state for participant {participant:?} with url {} has failed with error {e}.", info.url);
}
Expand All @@ -100,10 +106,15 @@ impl Pool {
let mut participants = Participants::default();
for (participant, info) in connections.iter() {
match self.fetch_participant_state(info).await {
Ok(state) => {
status.insert(*participant, state);
participants.insert(participant, info.clone());
}
Ok(state) => match self.send_empty_msg(participant, info).await {
Ok(()) => {
status.insert(*participant, state);
participants.insert(participant, info.clone());
}
Err(e) => {
tracing::warn!("Send empty msg for participant {participant:?} with url {} has failed with error {e}.", info.url);
}
},
Err(e) => {
tracing::warn!("Fetch state for participant {participant:?} with url {} has failed with error {e}.", info.url);
}
Expand Down Expand Up @@ -186,4 +197,20 @@ impl Pool {
Err(_) => Err(FetchParticipantError::Timeout),
}
}

async fn send_empty_msg(
&self,
participant: &Participant,
participant_info: &ParticipantInfo,
) -> Result<(), crate::http_client::SendError> {
let empty_msg: Vec<Ciphered> = Vec::new();
crate::http_client::send_encrypted(
*participant,
&self.http,
participant_info.url.clone(),
empty_msg,
self.fetch_participant_timeout,
)
.await
}
}

0 comments on commit a8fa2aa

Please sign in to comment.