Skip to content

Commit 26b1997

Browse files
committed
address review
1 parent 8783cf9 commit 26b1997

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

protocols/autonat/src/v2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! The implementation follows the [libp2p spec](https://github.com/libp2p/specs/blob/03718ef0f2dea4a756a85ba716ee33f97e4a6d6c/autonat/autonat-v2.md).
44
//!
5-
//! The new version fixes the issues of the first version:
5+
//! The new version fixes the issues of the first version.
66
//! - The server now always dials back over a newly allocated port. This greatly reduces the risk of
77
//! false positives that often occurred in the first version, when the client-server connection
88
//! occurred over a hole-punched port.

protocols/dcutr/src/behaviour.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ impl NetworkBehaviour for Behaviour {
325325
#[tracing::instrument(level = "trace", name = "NetworkBehaviour::poll", skip(self))]
326326
fn poll(&mut self, _: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
327327
if let Some(event) = self.queued_events.pop_front() {
328-
return Poll::Ready(event);
328+
Poll::Ready(event)
329+
} else {
330+
Poll::Pending
329331
}
330-
331-
Poll::Pending
332332
}
333333

334334
fn on_swarm_event(&mut self, event: FromSwarm) {

protocols/kad/src/behaviour.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,10 @@ where
870870
mut record: Record,
871871
quorum: Quorum,
872872
) -> Result<QueryId, store::Error> {
873-
if record.publisher.is_some() {
874-
record.publisher = Some(*self.kbuckets.local_key().preimage())
875-
}
873+
record
874+
.publisher
875+
.and(Some(*self.kbuckets.local_key().preimage()));
876+
876877
self.store.put(record.clone())?;
877878
record.expires = record
878879
.expires

protocols/kad/src/behaviour/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,12 @@ fn get_record_not_found() {
557557
}))
558558
}
559559

560-
/// A node joining a fully connected network via three (ALPHA_VALUE) bootnodes
560+
/// A node joining a fully connected network via three (`ALPHA_VALUE`) bootnodes
561561
/// should be able to put a record to the X closest nodes of the network where X
562562
/// is equal to the configured replication factor.
563563
#[test]
564564
fn put_record() {
565-
fn prop(mut records: Vec<Record>, seed: Seed, filter_records: bool, drop_records: bool) {
566-
tracing::trace!("remove records without a publisher");
567-
// this test relies on counting republished `Record` against `records.len()`
568-
records.retain(|r| r.publisher.is_some());
569-
565+
fn prop(records: Vec<Record>, seed: Seed, filter_records: bool, drop_records: bool) {
570566
let mut rng = StdRng::from_seed(seed.0);
571567
let replication_factor =
572568
NonZeroUsize::new(rng.gen_range(1..(K_VALUE.get() / 2) + 1)).unwrap();
@@ -613,6 +609,8 @@ fn put_record() {
613609
#[allow(clippy::mutable_key_type)] // False positive, we never modify `Bytes`.
614610
let records = records
615611
.into_iter()
612+
// Exclude records without a publisher.
613+
.filter(|r| r.publisher.is_some())
616614
.take(num_total)
617615
.map(|mut r| {
618616
// We don't want records to expire prematurely, as they would

swarm/src/behaviour.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ pub enum FromSwarm<'a> {
449449
/// Informs the behaviour that the [`ConnectedPoint`] of an existing
450450
/// connection has changed.
451451
AddressChange(AddressChange<'a>),
452-
/// Informs the behaviour that the dial to a known
453-
/// or unknown node failed.
452+
/// Informs the behaviour that the dial to a known or unknown node failed.
454453
DialFailure(DialFailure<'a>),
455454
/// Informs the behaviour that an error
456455
/// happened on an incoming connection during its initial handshake.

0 commit comments

Comments
 (0)