feat(app): directory protocol types, behaviour, relay_discoverable setting
- protocol/directory.rs: DirectoryRequest/Response/ProfileEntry + DIRECTORY_PROTOCOL - node/behaviour.rs: directory_service field on DuskBehaviour - node/swarm.rs: outbound directory_service cbor behaviour - storage/disk.rs: relay_discoverable bool in UserSettings (default true) - types.ts: relay_discoverable added to UserSettings interface Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
parent
31cdd4932b
commit
c01dc94338
|
|
@ -1,3 +1,4 @@
|
|||
use crate::protocol::directory::{DirectoryRequest, DirectoryResponse};
|
||||
use crate::protocol::gif::{GifRequest, GifResponse};
|
||||
use libp2p::{
|
||||
gossipsub, identify, kad, mdns, ping, relay, rendezvous, request_response::cbor,
|
||||
|
|
@ -15,4 +16,6 @@ pub struct DuskBehaviour {
|
|||
pub ping: ping::Behaviour,
|
||||
// gif search: sends requests to the relay, receives responses
|
||||
pub gif_service: cbor::Behaviour<GifRequest, GifResponse>,
|
||||
// directory search: register/search/remove profiles on the relay
|
||||
pub directory_service: cbor::Behaviour<DirectoryRequest, DirectoryResponse>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use libp2p::{
|
|||
};
|
||||
|
||||
use super::behaviour::DuskBehaviour;
|
||||
use crate::protocol::directory::{DirectoryRequest, DirectoryResponse, DIRECTORY_PROTOCOL};
|
||||
use crate::protocol::gif::{GifRequest, GifResponse, GIF_PROTOCOL};
|
||||
|
||||
pub fn build_swarm(
|
||||
|
|
@ -85,6 +86,12 @@ pub fn build_swarm(
|
|||
request_response::Config::default()
|
||||
.with_request_timeout(Duration::from_secs(15)),
|
||||
),
|
||||
// directory search via request-response to the relay (outbound only)
|
||||
directory_service: cbor::Behaviour::<DirectoryRequest, DirectoryResponse>::new(
|
||||
[(DIRECTORY_PROTOCOL, ProtocolSupport::Outbound)],
|
||||
request_response::Config::default()
|
||||
.with_request_timeout(Duration::from_secs(15)),
|
||||
),
|
||||
}
|
||||
})?
|
||||
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(300)))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
// directory protocol types for the relay-backed peer discovery service.
|
||||
// the client sends DirectoryRequests to the relay and receives DirectoryResponses.
|
||||
|
||||
use libp2p::StreamProtocol;
|
||||
|
||||
pub const DIRECTORY_PROTOCOL: StreamProtocol =
|
||||
StreamProtocol::new("/dusk/directory/1.0.0");
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum DirectoryRequest {
|
||||
Register { display_name: String },
|
||||
Search { query: String },
|
||||
Remove,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum DirectoryResponse {
|
||||
Ok,
|
||||
Results(Vec<DirectoryProfileEntry>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct DirectoryProfileEntry {
|
||||
pub peer_id: String,
|
||||
pub display_name: String,
|
||||
pub last_seen: u64,
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
pub mod community;
|
||||
pub mod directory;
|
||||
pub mod gif;
|
||||
pub mod identity;
|
||||
pub mod messages;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,12 @@ pub struct UserSettings {
|
|||
pub font_size: String,
|
||||
#[serde(default)]
|
||||
pub custom_relay_addr: Option<String>,
|
||||
#[serde(default = "default_true")]
|
||||
pub relay_discoverable: bool,
|
||||
}
|
||||
|
||||
fn default_true() -> bool { true }
|
||||
|
||||
impl Default for UserSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -43,6 +47,7 @@ impl Default for UserSettings {
|
|||
message_display: "cozy".to_string(),
|
||||
custom_relay_addr: None,
|
||||
font_size: "default".to_string(),
|
||||
relay_discoverable: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ export interface UserSettings {
|
|||
|
||||
// network
|
||||
custom_relay_addr?: string;
|
||||
|
||||
// discovery
|
||||
relay_discoverable: boolean;
|
||||
}
|
||||
|
||||
export interface CommunityMeta {
|
||||
|
|
|
|||
Loading…
Reference in New Issue