Skip to content

Commit

Permalink
- build_transport moved to [`finality-aleph/src/network/build/trans…
Browse files Browse the repository at this point in the history
…port.rs`]

- removed references to [`libp2p`] from [`finality-aleph/src/network/build/mod.rs`]
  • Loading branch information
fixxxedpoint committed Jul 10, 2024
1 parent f977951 commit 04c0718
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
17 changes: 1 addition & 16 deletions finality-aleph/src/network/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::{atomic::AtomicBool, Arc};

use libp2p::core::transport::Transport;
use log::error;
use rate_limiter::SleepingRateLimiter;
use sc_client_api::Backend;
Expand Down Expand Up @@ -36,7 +35,6 @@ use base::network as base_network;
use own_protocols::Networks;
use rpc::spawn_rpc_service;
use transactions::spawn_transaction_handler;
use transport::RateLimitedStreamMuxer;

const SPAWN_CATEGORY: Option<&str> = Some("networking");

Expand Down Expand Up @@ -86,20 +84,7 @@ where

let network_rate_limit = network_config.substrate_network_bit_rate;
let rate_limiter = SleepingRateLimiter::new(network_rate_limit);
let transport_builder = move |config: sc_network::transport::NetworkConfig| {
let default_transport = sc_network::transport::build_transport(
config.keypair,
config.memory_only,
config.muxer_window_size,
config.muxer_maximum_buffer_size,
);
default_transport.map(move |(peer_id, stream_muxer), _| {
(
peer_id,
RateLimitedStreamMuxer::new(stream_muxer, rate_limiter),
)
})
};
let transport_builder = |config| transport::build_transport(rate_limiter, config);

let (
network,
Expand Down
30 changes: 28 additions & 2 deletions finality-aleph/src/network/build/transport.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use libp2p::core::muxing::StreamMuxer;
use libp2p::{core::muxing::StreamMuxer, PeerId, Transport};
use rate_limiter::{FuturesRateLimitedAsyncReadWrite, FuturesRateLimiter, SleepingRateLimiter};

pub struct RateLimitedStreamMuxer<SM> {
struct RateLimitedStreamMuxer<SM> {
rate_limiter: SleepingRateLimiter,
stream_muxer: SM,
}
Expand Down Expand Up @@ -76,3 +76,29 @@ where
self.inner().poll(cx)
}
}

pub fn build_transport(
rate_limiter: SleepingRateLimiter,
config: sc_network::transport::NetworkConfig,
) -> impl Transport<
Output = (
PeerId,
impl StreamMuxer<Substream = impl Send, Error = impl Send> + Send,
),
Dial = impl Send,
ListenerUpgrade = impl Send,
Error = impl Send,
> + Send {
let default_transport = sc_network::transport::build_transport(
config.keypair,
config.memory_only,
config.muxer_window_size,
config.muxer_maximum_buffer_size,
);
default_transport.map(move |(peer_id, stream_muxer), _| {
(
peer_id,
RateLimitedStreamMuxer::new(stream_muxer, rate_limiter),
)
})
}

0 comments on commit 04c0718

Please sign in to comment.