-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
305 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use ahash::AHashMap; | ||
use libp2p::kad::{GetRecordOk, GetRecordResult, PeerRecord, QueryId}; | ||
use tokio::sync::mpsc::Sender; | ||
|
||
pub struct DhtGetQuery { | ||
response_channel: Sender<anyhow::Result<PeerRecord>>, | ||
} | ||
|
||
impl DhtGetQuery { | ||
pub fn new(response_channel: Sender<anyhow::Result<PeerRecord>>) -> DhtGetQuery { | ||
DhtGetQuery { response_channel } | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct DhtRecords { | ||
current_queries: AHashMap<QueryId, DhtGetQuery>, | ||
} | ||
|
||
impl DhtRecords { | ||
pub fn insert(&mut self, query_id: QueryId, query: DhtGetQuery) { | ||
self.current_queries.insert(query_id, query); | ||
} | ||
|
||
pub fn handle_get_record_result(&mut self, id: QueryId, get_record_result: GetRecordResult) { | ||
if let Some(query) = self.current_queries.remove(&id) { | ||
match get_record_result { | ||
Ok(GetRecordOk::FoundRecord(record)) => { | ||
tokio::spawn(async move { query.response_channel.send(Ok(record)).await.ok() }); | ||
} | ||
Ok(GetRecordOk::FinishedWithNoAdditionalRecord { cache_candidates }) => {} | ||
Err(_) => todo!(), | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod behaviour; | ||
pub mod cli; | ||
pub mod config; | ||
mod dht_records; | ||
mod keys; | ||
pub mod metrics; | ||
mod node; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
syntax = "proto2"; | ||
|
||
package ipns_pb; | ||
|
||
message IpnsEntry { | ||
enum ValidityType { | ||
// setting an EOL says "this record is valid until..." | ||
EOL = 0; | ||
} | ||
optional bytes value = 1; | ||
optional bytes signatureV1 = 2; | ||
|
||
optional ValidityType validityType = 3; | ||
optional bytes validity = 4; | ||
|
||
optional uint64 sequence = 5; | ||
|
||
optional uint64 ttl = 6; | ||
|
||
// in order for nodes to properly validate a record upon receipt, they need the public | ||
// key associated with it. For old RSA keys, its easiest if we just send this as part of | ||
// the record itself. For newer ed25519 keys, the public key can be embedded in the | ||
// peerID, making this field unnecessary. | ||
optional bytes pubKey = 7; | ||
|
||
optional bytes signatureV2 = 8; | ||
|
||
optional bytes data = 9; | ||
} | ||
|
||
message IpnsSignatureV2Checker { | ||
optional bytes pubKey = 7; | ||
optional bytes signatureV2 = 8; | ||
} |
Oops, something went wrong.