more testing

This commit is contained in:
Evan
2025-12-02 09:00:00 +00:00
parent 8242744136
commit c8a9794b0f
5 changed files with 76 additions and 41 deletions

View File

@@ -2,7 +2,9 @@
resolver = "3"
members = [
"exo_pyo3_bindings",
"util", "iroh_networking",
"util",
"iroh_networking",
"iroh_dnssd",
]
[workspace.package]

39
flake.lock generated
View File

@@ -1,26 +1,5 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1761893049,
"narHash": "sha256-1TtFDPhC+ZsrOOtBnry1EZC+WipTTvsOVjIEVugqji8=",
"owner": "nix-community",
"repo": "fenix",
"rev": "c2ac9a5c0d6d16630c3b225b874bd14528d1abe6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
@@ -57,29 +36,11 @@
},
"root": {
"inputs": {
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1761849405,
"narHash": "sha256-igXdvC+WCUN+3gnfk+ptT7rMmxQuY6WbIg1rXMUN1DM=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "f7de8ae045a5fe80f1203c5a1c3015b05f7c3550",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,

View File

@@ -38,7 +38,7 @@
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ inputs.fenix.overlays.default ];
overlays = [ ];
};
treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";

View File

@@ -0,0 +1,15 @@
[package]
name = "iroh_dnssd"
version.workspace = true
edition.workspace = true
[dependencies]
astro-dnssd = "0.3.6"
iroh = "0.95.1"
n0-future.workspace = true
rand = "0.9.2"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
[lints]
workspace = true

View File

@@ -0,0 +1,57 @@
use std::{net::SocketAddr, sync::Mutex};
use serde::{Serialize, Deserialize};
use astro_dnssd::{DNSServiceBuilder, RegisteredDnsService};
use iroh::{
Endpoint, EndpointId,
discovery::{Discovery, DiscoveryError, DiscoveryItem, EndpointData},
};
use n0_future::boxed::BoxStream;
use rand::Rng;
#[derive(Debug)]
pub struct DnssdDiscovery {
id: EndpointId,
current_service: Mutex<RegisteredDnsService>,
}
impl DnssdDiscovery {
pub fn spawn(endpoint: Endpoint) -> Self {
Self {
id: endpoint.id(),
current_service: Mutex::new(build_from(endpoint.id(), endpoint.addr().ip_addrs())),
}
}
}
impl Discovery for DnssdDiscovery {
fn publish(&self, _data: &EndpointData) {
*self.current_service.lock().expect("mutex poison") = build_from(self.id, _data.ip_addrs())
}
fn resolve(
&self,
_endpoint_id: EndpointId,
) -> Option<BoxStream<Result<DiscoveryItem, DiscoveryError>>> {
None
}
}
fn build_from<'a, I: Iterator<Item = &'a SocketAddr>>(id: EndpointId, addrs: I) -> RegisteredDnsService {
DNSServiceBuilder::new("_exo._iroh._udp", rand::rng().random_range(49152..65535))
.with_key_value(
"payload".to_owned(),
serde_json::to_string(&Payload {
id,
addrs: addrs.cloned().collect()
}).expect("serialization failed"),
)
.register()
.expect("mdns register failed")
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Payload {
addrs: Vec<SocketAddr>,
id: EndpointId,
}