Upgrade to libp2p 0.44.0 (#11009)

* Update libp2p to 0.43.0, lru to 0.7.3

* Fix websoket Incoming::Data

* Rename ProtocolsHandler -> ConnectionHandler, remove inject_dis/connected, minor fixes

* Fix args for inject_connection* callbacks

* Fix DialPeer/DialAddress

* Fix debug fmt

* Add Endpoint to NetworkState

* Fix Kad::get_record by key

* Fix Sha2_256::digest

* Fix IntoConnectionHandler

* Fix borrowchk

* Fix DialError::WrongPeerId

* Remove NodeHandlerWrapperError

* Fix KademliaEvent variants

* Fix impl Add for String

* Fix tabs in network_state

* Apply cargo fmt

* Fix a typo in req/resp

* Fix tests

* Fix peer_info:entry.info_expire

* Fix PeerInfoBehaviour inject_address_change and inject_connection_closed

* Patch libp2p to 0.44.0#6cc3b4e

* Fix inject_connection_closed kad, req/resp

* Apply cargo fmt

* Use libp2p from crates.io

* Fix review notes
This commit is contained in:
Roman
2022-04-29 12:49:05 +04:00
committed by GitHub
parent 51915ebe4a
commit 887acda7d0
24 changed files with 759 additions and 542 deletions
+26 -23
View File
@@ -36,8 +36,8 @@ use libp2p::{
},
request_response::OutboundFailure,
swarm::{
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
ProtocolsHandler,
ConnectionHandler, IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction,
PollParameters,
},
Multiaddr, PeerId,
};
@@ -1367,10 +1367,10 @@ pub enum CustomMessageOutcome<B: BlockT> {
}
impl<B: BlockT> NetworkBehaviour for Protocol<B> {
type ProtocolsHandler = <Notifications as NetworkBehaviour>::ProtocolsHandler;
type ConnectionHandler = <Notifications as NetworkBehaviour>::ConnectionHandler;
type OutEvent = CustomMessageOutcome<B>;
fn new_handler(&mut self) -> Self::ProtocolsHandler {
fn new_handler(&mut self) -> Self::ConnectionHandler {
self.behaviour.new_handler()
}
@@ -1384,9 +1384,15 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
conn: &ConnectionId,
endpoint: &ConnectedPoint,
failed_addresses: Option<&Vec<Multiaddr>>,
other_established: usize,
) {
self.behaviour
.inject_connection_established(peer_id, conn, endpoint, failed_addresses)
self.behaviour.inject_connection_established(
peer_id,
conn,
endpoint,
failed_addresses,
other_established,
)
}
fn inject_connection_closed(
@@ -1394,24 +1400,23 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
peer_id: &PeerId,
conn: &ConnectionId,
endpoint: &ConnectedPoint,
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
remaining_established: usize,
) {
self.behaviour.inject_connection_closed(peer_id, conn, endpoint, handler)
}
fn inject_connected(&mut self, peer_id: &PeerId) {
self.behaviour.inject_connected(peer_id)
}
fn inject_disconnected(&mut self, peer_id: &PeerId) {
self.behaviour.inject_disconnected(peer_id)
self.behaviour.inject_connection_closed(
peer_id,
conn,
endpoint,
handler,
remaining_established,
)
}
fn inject_event(
&mut self,
peer_id: PeerId,
connection: ConnectionId,
event: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
event: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
) {
self.behaviour.inject_event(peer_id, connection, event)
}
@@ -1420,7 +1425,7 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
&mut self,
cx: &mut std::task::Context,
params: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
if let Some(message) = self.pending_messages.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(message))
}
@@ -1581,10 +1586,8 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
let event = match self.behaviour.poll(cx, params) {
Poll::Pending => return Poll::Pending,
Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev)) => ev,
Poll::Ready(NetworkBehaviourAction::DialAddress { address, handler }) =>
return Poll::Ready(NetworkBehaviourAction::DialAddress { address, handler }),
Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition, handler }) =>
return Poll::Ready(NetworkBehaviourAction::DialPeer { peer_id, condition, handler }),
Poll::Ready(NetworkBehaviourAction::Dial { opts, handler }) =>
return Poll::Ready(NetworkBehaviourAction::Dial { opts, handler }),
Poll::Ready(NetworkBehaviourAction::NotifyHandler { peer_id, handler, event }) =>
return Poll::Ready(NetworkBehaviourAction::NotifyHandler {
peer_id,
@@ -1800,7 +1803,7 @@ impl<B: BlockT> NetworkBehaviour for Protocol<B> {
fn inject_dial_failure(
&mut self,
peer_id: Option<PeerId>,
handler: Self::ProtocolsHandler,
handler: Self::ConnectionHandler,
error: &libp2p::swarm::DialError,
) {
self.behaviour.inject_dial_failure(peer_id, handler, error);