Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add /msg to criteria of active participants #894

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading