dht search fixes
This commit is contained in:
@@ -228,12 +228,15 @@ impl Database {
|
|||||||
|
|
||||||
/// Returns non-expired replicas stored under `key`, including tombstones
|
/// Returns non-expired replicas stored under `key`, including tombstones
|
||||||
/// (they inform other peers about deletions). Capped at
|
/// (they inform other peers about deletions). Capped at
|
||||||
/// [`MAX_RECORDS_PER_RESPONSE`].
|
/// [`MAX_RECORDS_PER_RESPONSE`] with a deterministic order (freshest
|
||||||
|
/// replicas first), so an overfull bucket always returns the same
|
||||||
|
/// subset instead of an arbitrary one.
|
||||||
pub async fn dht_records_by_key(&self, key: DhtKey, now_ms: u64) -> Result<Vec<StoredRecord>> {
|
pub async fn dht_records_by_key(&self, key: DhtKey, now_ms: u64) -> Result<Vec<StoredRecord>> {
|
||||||
self.call(move |conn| {
|
self.call(move |conn| {
|
||||||
let mut stmt = conn.prepare(
|
let mut stmt = conn.prepare(
|
||||||
"SELECT payload FROM dht_records
|
"SELECT payload FROM dht_records
|
||||||
WHERE dht_key = ?1 AND expires_at_ms > ?2
|
WHERE dht_key = ?1 AND expires_at_ms > ?2
|
||||||
|
ORDER BY expires_at_ms DESC, artist_id
|
||||||
LIMIT ?3",
|
LIMIT ?3",
|
||||||
)?;
|
)?;
|
||||||
let rows = stmt.query_map(
|
let rows = stmt.query_map(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub const DHT_PROTOCOL_VERSION: u16 = 1;
|
|||||||
/// Maximum number of contacts in a single [`PeerExchange`].
|
/// Maximum number of contacts in a single [`PeerExchange`].
|
||||||
pub const MAX_PEER_EXCHANGE_CONTACTS: usize = 32;
|
pub const MAX_PEER_EXCHANGE_CONTACTS: usize = 32;
|
||||||
/// Maximum number of records in a single [`FindValueResponse`].
|
/// Maximum number of records in a single [`FindValueResponse`].
|
||||||
pub const MAX_RECORDS_PER_RESPONSE: usize = 100;
|
pub const MAX_RECORDS_PER_RESPONSE: usize = 256;
|
||||||
|
|
||||||
/// Correlates a response with its request.
|
/// Correlates a response with its request.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -163,6 +163,9 @@ impl MusicDhtService {
|
|||||||
.data_dir(&config.data_dir)
|
.data_dir(&config.data_dir)
|
||||||
.network_id(config.network_id)
|
.network_id(config.network_id)
|
||||||
.schema_id(SchemaId::from_name(SCHEMA_NAME))
|
.schema_id(SchemaId::from_name(SCHEMA_NAME))
|
||||||
|
// A full FindValue response (MAX_RECORDS_PER_RESPONSE records
|
||||||
|
// with long names and artist lists) must fit into one frame.
|
||||||
|
.max_message_size(1024 * 1024)
|
||||||
.request_timeout(config.transport_timeout);
|
.request_timeout(config.transport_timeout);
|
||||||
if let Some(rendezvous) = config.rendezvous.clone() {
|
if let Some(rendezvous) = config.rendezvous.clone() {
|
||||||
engine_builder = engine_builder.rendezvous(rendezvous);
|
engine_builder = engine_builder.rendezvous(rendezvous);
|
||||||
|
|||||||
Reference in New Issue
Block a user