mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Bump libp2p to 0.40.0 (#10035)
* Bump libp2p to 0.40.0-rc.1 * Fix PingFailure import * Reduce the number of compilation errors (this is a FIXME commit) * Bump libp2p to 0.40.0-rc.2 * Fix sc-network::Behaviour to inject events into fields * Fix some NetworkBehaviourAction types * More fixes * More fixes * More fixes * Fix DiscoveryBehaviour * Fix PeerInfoBehaviour * Fix RequestResponsesBehaviour * Fix RequestResponsesBehaviour * Fix Notifications * Fix NetworkWorker * Fix Behaviour * Please borrowchk * Please borrowchk * Please borrowchk * Fix fmt * Cover all cases in matches * Fix some clippy warnings * Fix into_peer_id -> to_peer_id * Fix some warnings * Fix some inject_dial_failure FIXMEs * Fix DiscoveryBehaviour::inject_dial_failure * Fix RequestResponsesBehaviour::inject_dial_failure * Fix the order of inject_connection_closed PeerInfoBehaviour events * Make KademliaEvent with filtering unreachable * Fix Notifications::inject_dial_failure * Use concurrent_dial_errors in NetworkWorker * Remove commented-out RequestResponsesBehaviour::inject_addr_reach_failure * Fix tests * Dont report new PendingConnectionError and DialError variants to metrics * Bump libp2p to 0.40.0 * Add fn inject_listen_failure and inject_address_change * Review fixes
This commit is contained in:
@@ -45,12 +45,12 @@ use libp2p::{
|
||||
ConnectedPoint, Multiaddr, PeerId,
|
||||
},
|
||||
request_response::{
|
||||
ProtocolSupport, RequestResponse, RequestResponseCodec, RequestResponseConfig,
|
||||
RequestResponseEvent, RequestResponseMessage, ResponseChannel,
|
||||
handler::RequestResponseHandler, ProtocolSupport, RequestResponse, RequestResponseCodec,
|
||||
RequestResponseConfig, RequestResponseEvent, RequestResponseMessage, ResponseChannel,
|
||||
},
|
||||
swarm::{
|
||||
protocols_handler::multi::MultiHandler, NetworkBehaviour, NetworkBehaviourAction,
|
||||
PollParameters, ProtocolsHandler,
|
||||
protocols_handler::multi::MultiHandler, IntoProtocolsHandler, NetworkBehaviour,
|
||||
NetworkBehaviourAction, PollParameters, ProtocolsHandler,
|
||||
},
|
||||
};
|
||||
use std::{
|
||||
@@ -377,6 +377,27 @@ impl RequestResponsesBehaviour {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn new_handler_with_replacement(
|
||||
&mut self,
|
||||
protocol: String,
|
||||
handler: RequestResponseHandler<GenericCodec>,
|
||||
) -> <RequestResponsesBehaviour as NetworkBehaviour>::ProtocolsHandler {
|
||||
let mut handlers: HashMap<_, _> = self
|
||||
.protocols
|
||||
.iter_mut()
|
||||
.map(|(p, (r, _))| (p.to_string(), NetworkBehaviour::new_handler(r)))
|
||||
.collect();
|
||||
|
||||
if let Some(h) = handlers.get_mut(&protocol) {
|
||||
*h = handler
|
||||
}
|
||||
|
||||
MultiHandler::try_from_iter(handlers).expect(
|
||||
"Protocols are in a HashMap and there can be at most one handler per protocol name, \
|
||||
which is the only possible error; qed",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
@@ -405,9 +426,16 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
peer_id: &PeerId,
|
||||
conn: &ConnectionId,
|
||||
endpoint: &ConnectedPoint,
|
||||
failed_addresses: Option<&Vec<Multiaddr>>,
|
||||
) {
|
||||
for (p, _) in self.protocols.values_mut() {
|
||||
NetworkBehaviour::inject_connection_established(p, peer_id, conn, endpoint)
|
||||
NetworkBehaviour::inject_connection_established(
|
||||
p,
|
||||
peer_id,
|
||||
conn,
|
||||
endpoint,
|
||||
failed_addresses,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,9 +450,11 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
peer_id: &PeerId,
|
||||
conn: &ConnectionId,
|
||||
endpoint: &ConnectedPoint,
|
||||
_handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
|
||||
) {
|
||||
for (p, _) in self.protocols.values_mut() {
|
||||
NetworkBehaviour::inject_connection_closed(p, peer_id, conn, endpoint)
|
||||
let handler = p.new_handler();
|
||||
NetworkBehaviour::inject_connection_closed(p, peer_id, conn, endpoint, handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,17 +464,6 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
fn inject_addr_reach_failure(
|
||||
&mut self,
|
||||
peer_id: Option<&PeerId>,
|
||||
addr: &Multiaddr,
|
||||
error: &dyn std::error::Error,
|
||||
) {
|
||||
for (p, _) in self.protocols.values_mut() {
|
||||
NetworkBehaviour::inject_addr_reach_failure(p, peer_id, addr, error)
|
||||
}
|
||||
}
|
||||
|
||||
fn inject_event(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
@@ -478,9 +497,15 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
}
|
||||
}
|
||||
|
||||
fn inject_dial_failure(&mut self, peer_id: &PeerId) {
|
||||
fn inject_dial_failure(
|
||||
&mut self,
|
||||
peer_id: Option<PeerId>,
|
||||
_: Self::ProtocolsHandler,
|
||||
error: &libp2p::swarm::DialError,
|
||||
) {
|
||||
for (p, _) in self.protocols.values_mut() {
|
||||
NetworkBehaviour::inject_dial_failure(p, peer_id)
|
||||
let handler = p.new_handler();
|
||||
NetworkBehaviour::inject_dial_failure(p, peer_id, handler, error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,12 +537,7 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
&mut self,
|
||||
cx: &mut Context,
|
||||
params: &mut impl PollParameters,
|
||||
) -> Poll<
|
||||
NetworkBehaviourAction<
|
||||
<Self::ProtocolsHandler as ProtocolsHandler>::InEvent,
|
||||
Self::OutEvent,
|
||||
>,
|
||||
> {
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
||||
'poll_all: loop {
|
||||
if let Some(message_request) = self.message_request.take() {
|
||||
// Now we can can poll `MessageRequest` until we get the reputation
|
||||
@@ -658,17 +678,26 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
|
||||
|
||||
// Other events generated by the underlying behaviour are transparently
|
||||
// passed through.
|
||||
NetworkBehaviourAction::DialAddress { address } => {
|
||||
NetworkBehaviourAction::DialAddress { address, handler } => {
|
||||
log::error!(
|
||||
"The request-response isn't supposed to start dialing peers"
|
||||
);
|
||||
return Poll::Ready(NetworkBehaviourAction::DialAddress { address })
|
||||
let protocol = protocol.to_string();
|
||||
let handler = self.new_handler_with_replacement(protocol, handler);
|
||||
return Poll::Ready(NetworkBehaviourAction::DialAddress {
|
||||
address,
|
||||
handler,
|
||||
})
|
||||
},
|
||||
NetworkBehaviourAction::DialPeer { peer_id, condition } =>
|
||||
NetworkBehaviourAction::DialPeer { peer_id, condition, handler } => {
|
||||
let protocol = protocol.to_string();
|
||||
let handler = self.new_handler_with_replacement(protocol, handler);
|
||||
return Poll::Ready(NetworkBehaviourAction::DialPeer {
|
||||
peer_id,
|
||||
condition,
|
||||
}),
|
||||
handler,
|
||||
})
|
||||
},
|
||||
NetworkBehaviourAction::NotifyHandler { peer_id, handler, event } =>
|
||||
return Poll::Ready(NetworkBehaviourAction::NotifyHandler {
|
||||
peer_id,
|
||||
@@ -1061,7 +1090,7 @@ mod tests {
|
||||
|
||||
let behaviour = RequestResponsesBehaviour::new(list, handle).unwrap();
|
||||
|
||||
let mut swarm = Swarm::new(transport, behaviour, keypair.public().into_peer_id());
|
||||
let mut swarm = Swarm::new(transport, behaviour, keypair.public().to_peer_id());
|
||||
let listen_addr: Multiaddr = format!("/memory/{}", rand::random::<u64>()).parse().unwrap();
|
||||
|
||||
swarm.listen_on(listen_addr.clone()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user