Skip to content

Commit c9a0140

Browse files
committed
Merge branch 'master' into haiko-webrtc-outbound-multistream-nego-fix
2 parents 99f6547 + 3de3785 commit c9a0140

File tree

6 files changed

+53
-33
lines changed

6 files changed

+53
-33
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.12.1] - 2025-11-21
9+
10+
This release adds support for connecting to multiple Kademlia DHT networks. The change is backward-compatible, no client code modifications should be needed compared to v0.12.0.
11+
12+
### Changed
13+
14+
- kad: Allow connecting to more than one DHT network ([#473](https://github.com/paritytech/litep2p/pull/473))
15+
- service: Log services that have closed ([#474](https://github.com/paritytech/litep2p/pull/474))
16+
17+
### Fixed
18+
19+
- update simple-dns ([#470](https://github.com/paritytech/litep2p/pull/470))
20+
821
## [0.12.0] - 2025-11-11
922

1023
This release adds `KademliaEvent::PutRecordSuccess` & `KademliaEvent::AddProviderSuccess` events to Kademlia, allowing to track whether publishing a record or a provider was successfull. While `PutRecordSuccess` was present in the previous versions of litep2p, it was actually never emitted. Note that `AddProviderSuccess` and `QueryFailed` are also generated during automatic provider refresh, so those may be emitted for `QueryId`s not known to the client code.

Cargo.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "litep2p"
33
description = "Peer-to-peer networking library"
44
repository = "https://github.com/paritytech/litep2p"
55
license = "MIT"
6-
version = "0.12.0"
6+
version = "0.12.1"
77
edition = "2021"
88

99
# cargo-machete does not detect serde_millis usage, so we ignore the warning

src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct ConfigBuilder {
9393
identify: Option<identify::Config>,
9494

9595
/// Kademlia protocol config.
96-
kademlia: Option<kademlia::Config>,
96+
kademlia: Vec<kademlia::Config>,
9797

9898
/// Bitswap protocol config.
9999
bitswap: Option<bitswap::Config>,
@@ -149,7 +149,7 @@ impl ConfigBuilder {
149149
keypair: None,
150150
ping: None,
151151
identify: None,
152-
kademlia: None,
152+
kademlia: Vec::new(),
153153
bitswap: None,
154154
mdns: None,
155155
executor: None,
@@ -219,7 +219,7 @@ impl ConfigBuilder {
219219

220220
/// Enable IPFS Kademlia protocol.
221221
pub fn with_libp2p_kademlia(mut self, config: kademlia::Config) -> Self {
222-
self.kademlia = Some(config);
222+
self.kademlia.push(config);
223223
self
224224
}
225225

@@ -307,7 +307,7 @@ impl ConfigBuilder {
307307
websocket: self.websocket.take(),
308308
ping: self.ping.take(),
309309
identify: self.identify.take(),
310-
kademlia: self.kademlia.take(),
310+
kademlia: self.kademlia,
311311
bitswap: self.bitswap.take(),
312312
max_parallel_dials: self.max_parallel_dials,
313313
executor: self.executor.map_or(Arc::new(DefaultExecutor {}), |executor| executor),
@@ -349,7 +349,7 @@ pub struct Litep2pConfig {
349349
pub(crate) identify: Option<identify::Config>,
350350

351351
/// Kademlia protocol configuration, if enabled.
352-
pub(crate) kademlia: Option<kademlia::Config>,
352+
pub(crate) kademlia: Vec<kademlia::Config>,
353353

354354
/// Bitswap protocol configuration, if enabled.
355355
pub(crate) bitswap: Option<bitswap::Config>,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ impl Litep2p {
259259
}));
260260
}
261261

262-
// start kademlia protocol event loop if enabled
263-
if let Some(kademlia_config) = litep2p_config.kademlia.take() {
262+
// start kademlia protocol event loops
263+
for kademlia_config in litep2p_config.kademlia.into_iter() {
264264
tracing::debug!(
265265
target: LOG_TARGET,
266266
protocol_names = ?kademlia_config.protocol_names,

src/protocol/libp2p/kademlia/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ impl Kademlia {
240240
self.routing_table.on_connection_established(Key::from(peer), endpoint);
241241

242242
let Some(actions) = self.pending_dials.remove(&peer) else {
243-
entry.insert(PeerContext::new());
243+
// Note that we do not add peer entry if we don't have any pending actions.
244+
// This is done to not populate `self.peers` with peers that don't support
245+
// our Kademlia protocol.
244246
return Ok(());
245247
};
246248

@@ -343,6 +345,7 @@ impl Kademlia {
343345
let pending_action = &mut self
344346
.peers
345347
.get_mut(&peer)
348+
// If we opened an outbound substream, we must have pending actions for the peer.
346349
.ok_or(Error::PeerDoesntExist(peer))?
347350
.pending_actions
348351
.remove(&substream_id);
@@ -412,6 +415,10 @@ impl Kademlia {
412415
async fn on_inbound_substream(&mut self, peer: PeerId, substream: Substream) {
413416
tracing::trace!(target: LOG_TARGET, ?peer, "inbound substream opened");
414417

418+
// Ensure peer entry exists to treat peer as [`ConnectionType::Connected`].
419+
// when inserting into the routing table.
420+
self.peers.entry(peer).or_default();
421+
415422
self.executor.read_message(peer, None, substream);
416423
}
417424

0 commit comments

Comments
 (0)