Skip to content

Commit 08a3c3f

Browse files
committed
fix[kad]: enable putting Record with None publisher in a confusing way. Sorry for that, see <libp2p#6176 (comment)> for some details.
1 parent 2fb2486 commit 08a3c3f

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

protocols/kad/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- minimized #6176
2+
13
## 0.49.0
24

35
- Remove no longer constructed GetRecordError::QuorumFailed.

protocols/kad/src/behaviour.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,9 @@ where
870870
mut record: Record,
871871
quorum: Quorum,
872872
) -> Result<QueryId, store::Error> {
873-
record.publisher = Some(*self.kbuckets.local_key().preimage());
873+
if record.publisher.is_some() {
874+
record.publisher = Some(*self.kbuckets.local_key().preimage())
875+
}
874876
self.store.put(record.clone())?;
875877
record.expires = record
876878
.expires

protocols/kad/src/behaviour/test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,11 @@ fn get_record_not_found() {
562562
/// is equal to the configured replication factor.
563563
#[test]
564564
fn put_record() {
565-
fn prop(records: Vec<Record>, seed: Seed, filter_records: bool, drop_records: bool) {
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+
566570
let mut rng = StdRng::from_seed(seed.0);
567571
let replication_factor =
568572
NonZeroUsize::new(rng.gen_range(1..(K_VALUE.get() / 2) + 1)).unwrap();

protocols/kad/src/record.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ impl Record {
9494
where
9595
K: Into<Key>,
9696
{
97+
Record {
98+
key: key.into(),
99+
value,
100+
publisher: Some(PeerId::random()),
101+
expires: None,
102+
}
103+
}
104+
105+
/// Creates a new record for insertion into the DHT.
106+
pub fn new_anonymous(key: impl Into<Key>, value: Vec<u8>) -> Self {
97107
Record {
98108
key: key.into(),
99109
value,

0 commit comments

Comments
 (0)