|
@@ -1,7 +1,9 @@
|
|
|
-use async_executor::Executor;
|
|
|
|
|
use async_std::sync::Arc;
|
|
use async_std::sync::Arc;
|
|
|
|
|
+
|
|
|
|
|
+use async_executor::Executor;
|
|
|
use async_trait::async_trait;
|
|
use async_trait::async_trait;
|
|
|
use log::{debug, error};
|
|
use log::{debug, error};
|
|
|
|
|
+use url::Url;
|
|
|
|
|
|
|
|
use crate::{
|
|
use crate::{
|
|
|
consensus::{Participant, ValidatorStatePtr},
|
|
consensus::{Participant, ValidatorStatePtr},
|
|
@@ -17,6 +19,7 @@ pub struct ProtocolParticipant {
|
|
|
jobsman: ProtocolJobsManagerPtr,
|
|
jobsman: ProtocolJobsManagerPtr,
|
|
|
state: ValidatorStatePtr,
|
|
state: ValidatorStatePtr,
|
|
|
p2p: P2pPtr,
|
|
p2p: P2pPtr,
|
|
|
|
|
+ channel_address: Url,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl ProtocolParticipant {
|
|
impl ProtocolParticipant {
|
|
@@ -30,17 +33,20 @@ impl ProtocolParticipant {
|
|
|
msg_subsystem.add_dispatch::<Participant>().await;
|
|
msg_subsystem.add_dispatch::<Participant>().await;
|
|
|
|
|
|
|
|
let participant_sub = channel.subscribe_msg::<Participant>().await?;
|
|
let participant_sub = channel.subscribe_msg::<Participant>().await?;
|
|
|
|
|
+ let channel_address = channel.address();
|
|
|
|
|
|
|
|
Ok(Arc::new(Self {
|
|
Ok(Arc::new(Self {
|
|
|
participant_sub,
|
|
participant_sub,
|
|
|
jobsman: ProtocolJobsManager::new("ParticipantProtocol", channel),
|
|
jobsman: ProtocolJobsManager::new("ParticipantProtocol", channel),
|
|
|
state,
|
|
state,
|
|
|
p2p,
|
|
p2p,
|
|
|
|
|
+ channel_address,
|
|
|
}))
|
|
}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async fn handle_receive_participant(self: Arc<Self>) -> Result<()> {
|
|
async fn handle_receive_participant(self: Arc<Self>) -> Result<()> {
|
|
|
debug!("ProtocolParticipant::handle_receive_participant() [START]");
|
|
debug!("ProtocolParticipant::handle_receive_participant() [START]");
|
|
|
|
|
+ let exclude_list = vec![self.channel_address.clone()];
|
|
|
loop {
|
|
loop {
|
|
|
let participant = match self.participant_sub.receive().await {
|
|
let participant = match self.participant_sub.receive().await {
|
|
|
Ok(v) => v,
|
|
Ok(v) => v,
|
|
@@ -53,8 +59,11 @@ impl ProtocolParticipant {
|
|
|
debug!("ProtocolParticipant::handle_receive_participant() recv: {:?}", participant);
|
|
debug!("ProtocolParticipant::handle_receive_participant() recv: {:?}", participant);
|
|
|
|
|
|
|
|
let participant_copy = (*participant).clone();
|
|
let participant_copy = (*participant).clone();
|
|
|
|
|
+
|
|
|
if self.state.write().await.append_participant(participant_copy.clone()) {
|
|
if self.state.write().await.append_participant(participant_copy.clone()) {
|
|
|
- if let Err(e) = self.p2p.broadcast(participant_copy).await {
|
|
|
|
|
|
|
+ if let Err(e) =
|
|
|
|
|
+ self.p2p.broadcast_with_exclude(participant_copy, &exclude_list).await
|
|
|
|
|
+ {
|
|
|
error!("ProtocolParticipant::handle_receive_participant(): p2p broadcast failed: {}", e);
|
|
error!("ProtocolParticipant::handle_receive_participant(): p2p broadcast failed: {}", e);
|
|
|
continue
|
|
continue
|
|
|
};
|
|
};
|