Skip to content

Commit

Permalink
Remove try_get_record() and other try_...() non-async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-markin committed Aug 29, 2024
1 parent 5432c9b commit feb493d
Showing 1 changed file with 0 additions and 64 deletions.
64 changes: 0 additions & 64 deletions src/protocol/libp2p/kademlia/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,70 +338,6 @@ impl KademliaHandle {
pub async fn store_record(&mut self, record: Record) {
let _ = self.cmd_tx.send(KademliaCommand::StoreRecord { record }).await;
}

/// Try to add known peer and if the channel is clogged, return an error.
pub fn try_add_known_peer(&self, peer: PeerId, addresses: Vec<Multiaddr>) -> Result<(), ()> {
self.cmd_tx
.try_send(KademliaCommand::AddKnownPeer { peer, addresses })
.map_err(|_| ())
}

/// Try to initiate `FIND_NODE` query and if the channel is clogged, return an error.
pub fn try_find_node(&mut self, peer: PeerId) -> Result<QueryId, ()> {
let query_id = self.next_query_id();
self.cmd_tx
.try_send(KademliaCommand::FindNode { peer, query_id })
.map(|_| query_id)
.map_err(|_| ())
}

/// Try to initiate `PUT_VALUE` query and if the channel is clogged, return an error.
pub fn try_put_record(&mut self, record: Record) -> Result<QueryId, ()> {
let query_id = self.next_query_id();
self.cmd_tx
.try_send(KademliaCommand::PutRecord { record, query_id })
.map(|_| query_id)
.map_err(|_| ())
}

/// Try to initiate `PUT_VALUE` query to the given peers and if the channel is clogged,
/// return an error.
pub fn try_put_record_to_peers(
&mut self,
record: Record,
peers: Vec<PeerId>,
update_local_store: bool,
) -> Result<QueryId, ()> {
let query_id = self.next_query_id();
self.cmd_tx
.try_send(KademliaCommand::PutRecordToPeers {
record,
query_id,
peers,
update_local_store,
})
.map(|_| query_id)
.map_err(|_| ())
}

/// Try to initiate `GET_VALUE` query and if the channel is clogged, return an error.
pub fn try_get_record(&mut self, key: RecordKey, quorum: Quorum) -> Result<QueryId, ()> {
let query_id = self.next_query_id();
self.cmd_tx
.try_send(KademliaCommand::GetRecord {
key,
quorum,
query_id,
})
.map(|_| query_id)
.map_err(|_| ())
}

/// Try to store the record in the local store, and if the channel is clogged, return an error.
/// Used in combination with [`IncomingRecordValidationMode::Manual`].
pub fn try_store_record(&mut self, record: Record) -> Result<(), ()> {
self.cmd_tx.try_send(KademliaCommand::StoreRecord { record }).map_err(|_| ())
}
}

impl Stream for KademliaHandle {
Expand Down

0 comments on commit feb493d

Please sign in to comment.