Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Add new `new_anonymous` function to enable putting Records without a publisher.
See [PR 6176](https://github.com/libp2p/rust-libp2p/pull/6176)

## 0.49.0

- Remove no longer constructed GetRecordError::QuorumFailed.
Expand Down
5 changes: 4 additions & 1 deletion protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,10 @@ where
mut record: Record,
quorum: Quorum,
) -> Result<QueryId, store::Error> {
record.publisher = Some(*self.kbuckets.local_key().preimage());
record
.publisher
.and(Some(*self.kbuckets.local_key().preimage()));

self.store.put(record.clone())?;
record.expires = record
.expires
Expand Down
4 changes: 3 additions & 1 deletion protocols/kad/src/behaviour/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ fn get_record_not_found() {
}))
}

/// A node joining a fully connected network via three (ALPHA_VALUE) bootnodes
/// A node joining a fully connected network via three (`ALPHA_VALUE`) bootnodes
/// should be able to put a record to the X closest nodes of the network where X
/// is equal to the configured replication factor.
#[test]
Expand Down Expand Up @@ -609,6 +609,8 @@ fn put_record() {
#[allow(clippy::mutable_key_type)] // False positive, we never modify `Bytes`.
let records = records
.into_iter()
// Exclude records without a publisher.
.filter(|r| r.publisher.is_some())
.take(num_total)
.map(|mut r| {
// We don't want records to expire prematurely, as they would
Expand Down
10 changes: 10 additions & 0 deletions protocols/kad/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ impl Record {
where
K: Into<Key>,
{
Record {
key: key.into(),
value,
publisher: Some(PeerId::random()),
expires: None,
}
}

/// Creates a new record for insertion into the DHT.
pub fn new_anonymous(key: impl Into<Key>, value: Vec<u8>) -> Self {
Record {
key: key.into(),
value,
Expand Down
Loading