Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be5e311
manager: Add connection middleware trait
lexnv Apr 10, 2025
2756803
config: Expose connection middleware to builder
lexnv Apr 10, 2025
2f8ed64
manager: Inject middleware from the litep2p config
lexnv Apr 10, 2025
669134b
manager: Modify trait API to match transport manager
lexnv Apr 10, 2025
1feca62
manager: Use the provided API
lexnv Apr 10, 2025
f7b724a
manager: Implement middleware for connection limits
lexnv Apr 10, 2025
7d70ef2
config: Remove old connection limits entirely
lexnv Apr 10, 2025
0aac72c
manager: Make connection limts inner functions private
lexnv Apr 10, 2025
942981e
manager: Expose ConnectionLimits struct to users
lexnv Apr 10, 2025
3493398
manager: Add more docs and impl unusual methods
lexnv Apr 10, 2025
37ffd6a
manager/tests: Adjust testing to the new interface
lexnv Apr 10, 2025
fdda69a
tests: Adjust testing
lexnv Apr 10, 2025
e8fb1bd
manager: Expose connection id to the inbound check step
lexnv Apr 11, 2025
5e04ddf
manager: Open API to capture peer IDs before dialing
lexnv Apr 11, 2025
4a56968
manager: Enhance docs
lexnv Apr 11, 2025
30bd3ea
transport: Refactor `PendingInboundConnection` event with socket addr
lexnv Apr 11, 2025
f8c36a3
manager: Enhance API with pure socket address
lexnv Apr 11, 2025
4754dc1
tests: Adjust testing
lexnv Apr 11, 2025
c65cccd
manager: Update docs
lexnv Apr 11, 2025
bfccff6
tests: Fix import warnings and identify decode
lexnv Apr 11, 2025
de25dc6
tests: Add comment wrt identity codec
lexnv Apr 11, 2025
1c2f444
manager: Fix cargo docs
lexnv Apr 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/codec/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ mod tests {
fn decoding_smaller_payloads() {
let mut codec = Identity::new(100);
let bytes = vec![3u8; 64];
let copy = bytes.clone();
let mut bytes = BytesMut::from(&bytes[..]);

let decoded = codec.decode(&mut bytes);
// The smaller payload will not be decoded as the identity code needs 100 bytes.
assert!(codec.decode(&mut bytes).unwrap().is_none());
}

#[test]
Expand Down
24 changes: 12 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
notification, request_response, UserProtocol,
},
transport::{
manager::limits::ConnectionLimitsConfig, tcp::config::Config as TcpConfig,
manager::limits::ConnectionMiddleware, tcp::config::Config as TcpConfig,
KEEP_ALIVE_TIMEOUT, MAX_PARALLEL_DIALS,
},
types::protocol::ProtocolName,
Expand Down Expand Up @@ -119,11 +119,11 @@ pub struct ConfigBuilder {
/// Maximum number of parallel dial attempts.
max_parallel_dials: usize,

/// Connection limits config.
connection_limits: ConnectionLimitsConfig,

/// Close the connection if no substreams are open within this time frame.
keep_alive_timeout: Duration,

/// Connection middleware.
connection_middleware: Option<Box<dyn ConnectionMiddleware>>,
}

impl Default for ConfigBuilder {
Expand Down Expand Up @@ -155,8 +155,8 @@ impl ConfigBuilder {
notification_protocols: HashMap::new(),
request_response_protocols: HashMap::new(),
known_addresses: Vec::new(),
connection_limits: ConnectionLimitsConfig::default(),
keep_alive_timeout: KEEP_ALIVE_TIMEOUT,
connection_middleware: None,
}
}

Expand Down Expand Up @@ -266,9 +266,9 @@ impl ConfigBuilder {
self
}

/// Set connection limits configuration.
pub fn with_connection_limits(mut self, config: ConnectionLimitsConfig) -> Self {
self.connection_limits = config;
/// Set connection middleware.
pub fn with_connection_middleware(mut self, middleware: Box<dyn ConnectionMiddleware>) -> Self {
self.connection_middleware = Some(middleware);
self
}

Expand Down Expand Up @@ -305,8 +305,8 @@ impl ConfigBuilder {
notification_protocols: self.notification_protocols,
request_response_protocols: self.request_response_protocols,
known_addresses: self.known_addresses,
connection_limits: self.connection_limits,
keep_alive_timeout: self.keep_alive_timeout,
connection_middleware: self.connection_middleware.take(),
}
}
}
Expand Down Expand Up @@ -364,9 +364,9 @@ pub struct Litep2pConfig {
/// Known addresses.
pub(crate) known_addresses: Vec<(PeerId, Vec<Multiaddr>)>,

/// Connection limits config.
pub(crate) connection_limits: ConnectionLimitsConfig,

/// Close the connection if no substreams are open within this time frame.
pub(crate) keep_alive_timeout: Duration,

/// Connection middleware.
pub(crate) connection_middleware: Option<Box<dyn ConnectionMiddleware>>,
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl Litep2p {
supported_transports,
bandwidth_sink.clone(),
litep2p_config.max_parallel_dials,
litep2p_config.connection_limits,
litep2p_config.connection_middleware,
);

// add known addresses to `TransportManager`, if any exist
Expand Down
7 changes: 2 additions & 5 deletions src/protocol/libp2p/kademlia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,10 +1230,7 @@ mod tests {
use crate::{
codec::ProtocolCodec,
crypto::ed25519::Keypair,
transport::{
manager::{limits::ConnectionLimitsConfig, TransportManager},
KEEP_ALIVE_TIMEOUT,
},
transport::{manager::TransportManager, ConnectionLimits, KEEP_ALIVE_TIMEOUT},
types::protocol::ProtocolName,
BandwidthSink,
};
Expand All @@ -1251,7 +1248,7 @@ mod tests {
HashSet::new(),
BandwidthSink::new(),
8usize,
ConnectionLimitsConfig::default(),
Some(Box::new(ConnectionLimits::new(Default::default()))),
);

let peer = PeerId::random();
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/mdns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ mod tests {
use super::*;
use crate::{
crypto::ed25519::Keypair,
transport::manager::{limits::ConnectionLimitsConfig, TransportManager},
transport::{manager::TransportManager, ConnectionLimits},
BandwidthSink,
};
use futures::StreamExt;
Expand All @@ -354,7 +354,7 @@ mod tests {
HashSet::new(),
BandwidthSink::new(),
8usize,
ConnectionLimitsConfig::default(),
Some(Box::new(ConnectionLimits::new(Default::default()))),
);

let mdns1 = Mdns::new(
Expand All @@ -377,7 +377,7 @@ mod tests {
HashSet::new(),
BandwidthSink::new(),
8usize,
ConnectionLimitsConfig::default(),
Some(Box::new(ConnectionLimits::new(Default::default()))),
);

let mdns2 = Mdns::new(
Expand Down
7 changes: 2 additions & 5 deletions src/protocol/notification/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use crate::{
},
InnerTransportEvent, ProtocolCommand, TransportService,
},
transport::{
manager::{limits::ConnectionLimitsConfig, TransportManager},
KEEP_ALIVE_TIMEOUT,
},
transport::{manager::TransportManager, ConnectionLimits, KEEP_ALIVE_TIMEOUT},
types::protocol::ProtocolName,
BandwidthSink, PeerId,
};
Expand All @@ -56,7 +53,7 @@ fn make_notification_protocol() -> (
HashSet::new(),
BandwidthSink::new(),
8usize,
ConnectionLimitsConfig::default(),
Some(Box::new(ConnectionLimits::new(Default::default()))),
);

let peer = PeerId::random();
Expand Down
7 changes: 2 additions & 5 deletions src/protocol/request_response/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use crate::{
InnerTransportEvent, SubstreamError, TransportService,
},
substream::Substream,
transport::{
manager::{limits::ConnectionLimitsConfig, TransportManager},
KEEP_ALIVE_TIMEOUT,
},
transport::{manager::TransportManager, ConnectionLimits, KEEP_ALIVE_TIMEOUT},
types::{RequestId, SubstreamId},
BandwidthSink, Error, PeerId, ProtocolName,
};
Expand All @@ -54,7 +51,7 @@ fn protocol() -> (
HashSet::new(),
BandwidthSink::new(),
8usize,
ConnectionLimitsConfig::default(),
Some(Box::new(ConnectionLimits::new(Default::default()))),
);

let peer = PeerId::random();
Expand Down
Loading
Loading