-
Notifications
You must be signed in to change notification settings - Fork 16
kad: Implement put_record_to and try_put_record_to #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
57fcf61
1f38a1b
96e827b
200a0fd
db5d9ef
99e88d8
ad3ec06
c0b4c8d
93674df
f7a0bf4
61d3995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ use futures::StreamExt; | |
use multiaddr::Multiaddr; | ||
use tokio::sync::mpsc::{Receiver, Sender}; | ||
|
||
use std::collections::{hash_map::Entry, HashMap}; | ||
use std::collections::{hash_map::Entry, HashMap, VecDeque}; | ||
|
||
pub use config::{Config, ConfigBuilder}; | ||
pub use handle::{KademliaEvent, KademliaHandle, Quorum, RoutingTableUpdateMode}; | ||
|
@@ -738,17 +738,36 @@ impl Kademlia { | |
self.routing_table.closest(Key::from(peer), self.replication_factor).into() | ||
); | ||
} | ||
Some(KademliaCommand::PutRecord { record, query_id }) => { | ||
Some(KademliaCommand::PutRecord { record, query_id, peers }) => { | ||
tracing::debug!(target: LOG_TARGET, ?query_id, key = ?record.key, "store record to DHT"); | ||
|
||
self.store.put(record.clone()); | ||
let key = Key::new(record.key.clone()); | ||
|
||
self.engine.start_put_record( | ||
query_id, | ||
record, | ||
self.routing_table.closest(key, self.replication_factor).into(), | ||
); | ||
|
||
if let Some(peers) = peers { | ||
// Put the record to the specified peers. | ||
let peers: VecDeque<_> = peers.into_iter().filter_map(|peer| { | ||
if let KBucketEntry::Occupied(entry) = self.routing_table.entry(Key::from(peer)) { | ||
Some(entry.clone()) | ||
} else { | ||
None | ||
} | ||
}).collect(); | ||
|
||
self.engine.start_put_record( | ||
query_id, | ||
record, | ||
peers | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going once again through To update specific peers, we can go two routes:
|
||
} else { | ||
self.store.put(record.clone()); | ||
|
||
self.engine.start_put_record( | ||
query_id, | ||
record, | ||
self.routing_table.closest(key, self.replication_factor).into(), | ||
); | ||
} | ||
} | ||
Some(KademliaCommand::GetRecord { key, quorum, query_id }) => { | ||
tracing::debug!(target: LOG_TARGET, ?key, "get record from DHT"); | ||
|
Uh oh!
There was an error while loading. Please reload this page.