Skip to content

Commit

Permalink
[TestLoop] (3.4/n) Remove MsgRecipient and NetworkRecipient which are…
Browse files Browse the repository at this point in the history
… no longer used. (near#8585)

They have been superseded by Sender/AsyncSender and LateBoundSender.
  • Loading branch information
robin-near authored Feb 21, 2023
1 parent 9be8da2 commit 7e71791
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions chain/network/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub use crate::network_protocol::{
};
use crate::routing::routing_table_view::RoutingTableInfo;
use crate::time;
use futures::future::BoxFuture;
use futures::FutureExt;
use near_async::messaging::{
AsyncSender, CanSend, CanSendAsync, IntoAsyncSender, IntoSender, Sender,
};
Expand All @@ -19,7 +17,6 @@ use near_primitives::sharding::PartialEncodedChunkWithArcReceipts;
use near_primitives::transaction::SignedTransaction;
use near_primitives::types::BlockHeight;
use near_primitives::types::{AccountId, ShardId};
use once_cell::sync::OnceCell;
use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
use std::net::SocketAddr;
Expand Down Expand Up @@ -399,53 +396,6 @@ pub enum NetworkAdversarialMessage {
AdvCheckStorageConsistency,
}

// TODO: remove trait and all related traits once migration is complete.
pub trait MsgRecipient<M: actix::Message>: Send + Sync + 'static {
fn send(&self, msg: M) -> BoxFuture<'static, Result<M::Result, actix::MailboxError>>;
fn do_send(&self, msg: M);
}

impl<A, M> MsgRecipient<M> for actix::Addr<A>
where
M: actix::Message + Send + 'static,
M::Result: Send,
A: actix::Actor + actix::Handler<M>,
A::Context: actix::dev::ToEnvelope<A, M>,
{
fn send(&self, msg: M) -> BoxFuture<'static, Result<M::Result, actix::MailboxError>> {
actix::Addr::send(self, msg).boxed()
}
fn do_send(&self, msg: M) {
actix::Addr::do_send(self, msg)
}
}

// TODO: rename to a more generic name.
pub struct NetworkRecipient<T> {
recipient: OnceCell<Arc<T>>,
}

impl<T> Default for NetworkRecipient<T> {
fn default() -> Self {
Self { recipient: OnceCell::default() }
}
}

impl<T> NetworkRecipient<T> {
pub fn set_recipient(&self, t: T) {
self.recipient.set(Arc::new(t)).ok().expect("cannot set recipient twice");
}
}

impl<M: actix::Message, T: MsgRecipient<M>> MsgRecipient<M> for NetworkRecipient<T> {
fn send(&self, msg: M) -> BoxFuture<'static, Result<M::Result, actix::MailboxError>> {
self.recipient.wait().send(msg)
}
fn do_send(&self, msg: M) {
self.recipient.wait().do_send(msg);
}
}

#[derive(Clone, derive_more::AsRef)]
pub struct PeerManagerAdapter {
pub async_request_sender:
Expand Down

0 comments on commit 7e71791

Please sign in to comment.