Add decentralized similarity routing
CI / check (push) Successful in 1m13s

This commit is contained in:
Aleksandr Bogomiakov
2026-08-10 19:35:35 +01:00
parent 6ceb52c5d2
commit f9a5096aea
15 changed files with 2017 additions and 14 deletions
+31 -2
View File
@@ -5,8 +5,8 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use federation_net::{
ByteStream, EndpointAddr, EndpointId, NetworkConfig, NetworkEngine, PeerTicket, SchemaId,
SecretKey, StreamAcceptor,
ByteStream, EndpointAddr, EndpointId, NetworkConfig, NetworkEngine, NetworkId, PeerTicket,
SchemaId, SecretKey, Signature, StreamAcceptor,
};
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
@@ -335,6 +335,17 @@ impl MusicDhtService {
self.node.endpoint_id
}
/// Returns the federation network this service participates in.
pub fn network_id(&self) -> NetworkId {
self.node.config.network_id
}
/// Signs a forwarded application record with this peer's persistent
/// transport identity without exposing the secret key.
pub fn sign_identity(&self, message: &[u8]) -> Signature {
self.node.engine.sign_identity(message)
}
/// Returns the DHT identifier of this peer.
pub fn node_id(&self) -> NodeId {
self.node.node_id
@@ -402,6 +413,24 @@ impl MusicDhtService {
.map_err(Into::into)
}
/// Opens a raw byte stream using a self-contained peer ticket.
///
/// This is used by schema-independent overlays whose contacts can be
/// learned independently of the main music-DHT routing table.
pub async fn open_stream_to(&self, ticket: &PeerTicket, alpn: &[u8]) -> Result<ByteStream> {
self.node.ensure_running()?;
if ticket.network_id != self.node.config.network_id {
return Err(MusicDhtError::Network(
"peer ticket belongs to another network".to_string(),
));
}
self.node
.engine
.open_stream(ticket.endpoint_addr.clone(), alpn)
.await
.map_err(Into::into)
}
/// Synchronizes the published library with `specs`: the desired set of
/// items this peer wants to share.
///