mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 09:37:55 +00:00
Ensure the listen addresses are consistent with the transport (#6436)
* Initial commit
Forked at: 82bdf1a891
No parent branch.
* Ensure the listen addresses are consistent with the transport
* Update client/network/src/error.rs
* Update client/network/src/service.rs
* Better implementation
* Fix bad previous impl
* add boot_nodes
* reserved nodes
* test boot nodes
* reserved nodes tests
* add public_addresses and make specific error type
* Update client/network/src/error.rs
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
@@ -107,6 +107,24 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
/// for the network processing to advance. From it, you can extract a `NetworkService` using
|
||||
/// `worker.service()`. The `NetworkService` can be shared through the codebase.
|
||||
pub fn new(params: Params<B, H>) -> Result<NetworkWorker<B, H>, Error> {
|
||||
// Ensure the listen addresses are consistent with the transport.
|
||||
ensure_addresses_consistent_with_transport(
|
||||
params.network_config.listen_addresses.iter(),
|
||||
¶ms.network_config.transport,
|
||||
)?;
|
||||
ensure_addresses_consistent_with_transport(
|
||||
params.network_config.boot_nodes.iter().map(|x| &x.multiaddr),
|
||||
¶ms.network_config.transport,
|
||||
)?;
|
||||
ensure_addresses_consistent_with_transport(
|
||||
params.network_config.reserved_nodes.iter().map(|x| &x.multiaddr),
|
||||
¶ms.network_config.transport,
|
||||
)?;
|
||||
ensure_addresses_consistent_with_transport(
|
||||
params.network_config.public_addresses.iter(),
|
||||
¶ms.network_config.transport,
|
||||
)?;
|
||||
|
||||
let (to_worker, from_worker) = tracing_unbounded("mpsc_network_worker");
|
||||
|
||||
if let Some(path) = params.network_config.net_config_path {
|
||||
@@ -1469,3 +1487,40 @@ impl<'a, B: BlockT, H: ExHashT> Link<B> for NetworkLink<'a, B, H> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_addresses_consistent_with_transport<'a>(
|
||||
addresses: impl Iterator<Item = &'a Multiaddr>,
|
||||
transport: &TransportConfig,
|
||||
) -> Result<(), Error> {
|
||||
if matches!(transport, TransportConfig::MemoryOnly) {
|
||||
let addresses: Vec<_> = addresses
|
||||
.filter(|x| x.iter()
|
||||
.any(|y| !matches!(y, libp2p::core::multiaddr::Protocol::Memory(_)))
|
||||
)
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
if !addresses.is_empty() {
|
||||
return Err(Error::AddressesForAnotherTransport {
|
||||
transport: transport.clone(),
|
||||
addresses,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let addresses: Vec<_> = addresses
|
||||
.filter(|x| x.iter()
|
||||
.any(|y| matches!(y, libp2p::core::multiaddr::Protocol::Memory(_)))
|
||||
)
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
if !addresses.is_empty() {
|
||||
return Err(Error::AddressesForAnotherTransport {
|
||||
transport: transport.clone(),
|
||||
addresses,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user