Struct hotshot::traits::networking::libp2p_network::Libp2pNetwork
source · pub struct Libp2pNetwork<T: NodeType> {
inner: Arc<Libp2pNetworkInner<T>>,
}
Expand description
Networking implementation that uses libp2p
generic over M
which is the message type
Fields§
§inner: Arc<Libp2pNetworkInner<T>>
holds the state of the libp2p network
Implementations§
source§impl<T: NodeType> Libp2pNetwork<T>
impl<T: NodeType> Libp2pNetwork<T>
sourcepub async fn from_config(
config: NetworkConfig<T::SignatureKey>,
quorum_membership: T::Membership,
gossip_config: GossipConfig,
request_response_config: RequestResponseConfig,
bind_address: Multiaddr,
pub_key: &T::SignatureKey,
priv_key: &<T::SignatureKey as SignatureKey>::PrivateKey,
metrics: Libp2pMetricsValue,
) -> Result<Self>
pub async fn from_config( config: NetworkConfig<T::SignatureKey>, quorum_membership: T::Membership, gossip_config: GossipConfig, request_response_config: RequestResponseConfig, bind_address: Multiaddr, pub_key: &T::SignatureKey, priv_key: &<T::SignatureKey as SignatureKey>::PrivateKey, metrics: Libp2pMetricsValue, ) -> Result<Self>
sourcepub async fn wait_for_ready(&self)
pub async fn wait_for_ready(&self)
Returns only when the network is ready.
sourcepub async fn new(
metrics: Libp2pMetricsValue,
config: NetworkNodeConfig<T>,
pk: T::SignatureKey,
lookup_record_value: RecordValue<T::SignatureKey>,
bootstrap_addrs: Arc<RwLock<Vec<(PeerId, Multiaddr)>>>,
id: usize,
reliability_config: Option<Box<dyn NetworkReliability>>,
) -> Result<Libp2pNetwork<T>, NetworkError>
pub async fn new( metrics: Libp2pMetricsValue, config: NetworkNodeConfig<T>, pk: T::SignatureKey, lookup_record_value: RecordValue<T::SignatureKey>, bootstrap_addrs: Arc<RwLock<Vec<(PeerId, Multiaddr)>>>, id: usize, reliability_config: Option<Box<dyn NetworkReliability>>, ) -> Result<Libp2pNetwork<T>, NetworkError>
Constructs new network for a node. Note that this network is unconnected.
One must call connect
in order to connect.
config
: the configuration of the nodepk
: public key associated with the nodebootstrap_addrs
: rwlock containing the bootstrap addrs
§Errors
Returns error in the event that the underlying libp2p network is unable to create a network.
§Panics
This will panic if there are less than 5 bootstrap nodes
sourcefn spawn_node_lookup(
&self,
node_lookup_recv: Receiver<Option<(ViewNumber, T::SignatureKey)>>,
)
fn spawn_node_lookup( &self, node_lookup_recv: Receiver<Option<(ViewNumber, T::SignatureKey)>>, )
Spawns task for looking up nodes pre-emptively
sourcefn spawn_connect(
&mut self,
id: usize,
lookup_record_value: RecordValue<T::SignatureKey>,
)
fn spawn_connect( &mut self, id: usize, lookup_record_value: RecordValue<T::SignatureKey>, )
Initiates connection to the outside world
sourcefn handle_recvd_events(
&self,
msg: NetworkEvent,
sender: &Sender<Vec<u8>>,
) -> Result<(), NetworkError>
fn handle_recvd_events( &self, msg: NetworkEvent, sender: &Sender<Vec<u8>>, ) -> Result<(), NetworkError>
Handle events
sourcefn handle_event_generator(
&self,
sender: Sender<Vec<u8>>,
network_rx: NetworkNodeReceiver,
)
fn handle_event_generator( &self, sender: Sender<Vec<u8>>, network_rx: NetworkNodeReceiver, )
task to propagate messages to handlers terminates on shut down of network
Trait Implementations§
source§impl<T: Clone + NodeType> Clone for Libp2pNetwork<T>
impl<T: Clone + NodeType> Clone for Libp2pNetwork<T>
source§fn clone(&self) -> Libp2pNetwork<T>
fn clone(&self) -> Libp2pNetwork<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: NodeType> ConnectedNetwork<<T as NodeType>::SignatureKey> for Libp2pNetwork<T>
impl<T: NodeType> ConnectedNetwork<<T as NodeType>::SignatureKey> for Libp2pNetwork<T>
source§fn recv_message<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn recv_message<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receive one or many messages from the underlying network.
§Errors
If there is a network-related failure.
source§fn update_view<'a, 'life0, 'async_trait, TYPES>(
&'a self,
view: u64,
epoch: u64,
membership: &'life0 TYPES::Membership,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
TYPES: NodeType<SignatureKey = T::SignatureKey> + 'a + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn update_view<'a, 'life0, 'async_trait, TYPES>(
&'a self,
view: u64,
epoch: u64,
membership: &'life0 TYPES::Membership,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
TYPES: NodeType<SignatureKey = T::SignatureKey> + 'a + 'async_trait,
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
The libp2p view update is a special operation intrinsic to its internal behavior.
Libp2p needs to do a lookup because a libp2p address is not related to hotshot keys. So in libp2p we store a mapping of HotShot key to libp2p address in a distributed hash table.
This means to directly message someone on libp2p we need to lookup in the hash table what their libp2p address is, using their HotShot public key as the key.
So the logic with libp2p is to prefetch upcoming leaders libp2p address to save time when we later need to direct message the leader our vote. Hence the use of the future view and leader to queue the lookups.
source§fn wait_for_ready<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn wait_for_ready<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
source§fn shut_down<'a, 'b>(&'a self) -> BoxSyncFuture<'b, ()>where
Self: 'b,
'a: 'b,
fn shut_down<'a, 'b>(&'a self) -> BoxSyncFuture<'b, ()>where
Self: 'b,
'a: 'b,
source§fn broadcast_message<'life0, 'async_trait>(
&'life0 self,
message: Vec<u8>,
topic: Topic,
_broadcast_delay: BroadcastDelay,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn broadcast_message<'life0, 'async_trait>(
&'life0 self,
message: Vec<u8>,
topic: Topic,
_broadcast_delay: BroadcastDelay,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
source§fn da_broadcast_message<'life0, 'async_trait>(
&'life0 self,
message: Vec<u8>,
recipients: Vec<T::SignatureKey>,
_broadcast_delay: BroadcastDelay,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn da_broadcast_message<'life0, 'async_trait>(
&'life0 self,
message: Vec<u8>,
recipients: Vec<T::SignatureKey>,
_broadcast_delay: BroadcastDelay,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
source§fn direct_message<'life0, 'async_trait>(
&'life0 self,
message: Vec<u8>,
recipient: T::SignatureKey,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn direct_message<'life0, 'async_trait>(
&'life0 self,
message: Vec<u8>,
recipient: T::SignatureKey,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
source§fn queue_node_lookup(
&self,
view_number: ViewNumber,
pk: T::SignatureKey,
) -> Result<(), TrySendError<Option<(ViewNumber, T::SignatureKey)>>>
fn queue_node_lookup( &self, view_number: ViewNumber, pk: T::SignatureKey, ) -> Result<(), TrySendError<Option<(ViewNumber, T::SignatureKey)>>>
source§fn vid_broadcast_message<'life0, 'async_trait>(
&'life0 self,
messages: HashMap<K, Vec<u8>>,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn vid_broadcast_message<'life0, 'async_trait>(
&'life0 self,
messages: HashMap<K, Vec<u8>>,
) -> Pin<Box<dyn Future<Output = Result<(), NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
source§fn is_primary_down(&self) -> bool
fn is_primary_down(&self) -> bool
source§impl<T: NodeType> Debug for Libp2pNetwork<T>
impl<T: NodeType> Debug for Libp2pNetwork<T>
source§impl<T: NodeType> TestableNetworkingImplementation<T> for Libp2pNetwork<T>
impl<T: NodeType> TestableNetworkingImplementation<T> for Libp2pNetwork<T>
source§fn generator(
expected_node_count: usize,
num_bootstrap: usize,
_network_id: usize,
da_committee_size: usize,
reliability_config: Option<Box<dyn NetworkReliability>>,
_secondary_network_delay: Duration,
) -> AsyncGenerator<Arc<Self>>
fn generator( expected_node_count: usize, num_bootstrap: usize, _network_id: usize, da_committee_size: usize, reliability_config: Option<Box<dyn NetworkReliability>>, _secondary_network_delay: Duration, ) -> AsyncGenerator<Arc<Self>>
Returns a boxed function f(node_id, public_key) -> Libp2pNetwork
with the purpose of generating libp2p networks.
Generates num_bootstrap
bootstrap nodes. The remainder of nodes are normal
nodes with sane defaults.
§Panics
Returned function may panic either:
- An invalid configuration (probably an issue with the defaults of this function)
- An inability to spin up the replica’s network
Auto Trait Implementations§
impl<T> Freeze for Libp2pNetwork<T>
impl<T> !RefUnwindSafe for Libp2pNetwork<T>
impl<T> Send for Libp2pNetwork<T>
impl<T> Sync for Libp2pNetwork<T>
impl<T> Unpin for Libp2pNetwork<T>
impl<T> !UnwindSafe for Libp2pNetwork<T>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Conv for T
impl<T> Conv for T
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.