swactor/crates/iroh-driver/tests/endpoint_advertisement.rs
Zachery Aaron Shores-Chmielewski c257dde02f refactor: fold driver pumps into iroh-driver and codecs into transport
Consolidate the duplicated JSON codec into `transport` and relocate the iroh edge-transport pieces into `iroh-driver`, dissolving the `mvp-system` transport shim.

- `transport`: add a canonical `json_codec::JsonCodec<M>` (re-exported from the crate root) as the single JSON codec for serde message types
- `distribution`/`datastream`: drop the per-crate `JsonCodec` copies and the `impl_json_codec!` macro; register SWIM/gossip and publisher messages against the shared `swactor_transport::JsonCodec`
- `iroh-driver`: move `driver_pumps` and `endpoint_advertisement` out of `mvp-system/src/transport/`, re-exporting `EndpointAddrMask`/`advertised_endpoint`/`MVP_IROH_ENDPOINT_ADDR_MASK_ENV`, and relocate the endpoint guarantee test to `iroh-driver/tests/endpoint_advertisement.rs`
- `mvp-system`: delete the `transport/` module and keep codec aggregation in a new `codecs.rs` (`register_mvp_actor_codecs`)
- `mvp-system/node`: shrink `worker_node_runtime.rs` (~260 lines) by adopting the relocated modules and collapsing verbose `emit_stdio_node_event` calls into local `boot()`/`worker_evt()` closures

Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-07-30 12:18:02 +04:00

38 lines
1.3 KiB
Rust

//! Behavior guarantees for endpoint advertisement masking.
use std::net::{Ipv4Addr, SocketAddr};
use iroh_driver::{EndpointAddrMask, advertised_endpoint};
#[test]
fn relay_only_mask_preserves_relay_urls_and_removes_direct_addresses() {
let relay = "http://relay.example.com"
.parse::<iroh::RelayUrl>()
.expect("relay URL parses");
let endpoint = iroh::EndpointAddr::new(iroh::SecretKey::from_bytes(&[9; 32]).public())
.with_relay_url(relay.clone())
.with_ip_addr(SocketAddr::from((Ipv4Addr::LOCALHOST, 7777)));
let masked = advertised_endpoint(endpoint, EndpointAddrMask::RelayOnly)
.expect("relay-only endpoint builds");
assert_eq!(masked.ip_addrs().count(), 0);
assert_eq!(
masked.relay_urls().next().map(ToString::to_string),
Some(relay.to_string())
);
}
#[test]
fn relay_only_mask_rejects_endpoint_without_relay_url() {
let endpoint = iroh::EndpointAddr::new(iroh::SecretKey::from_bytes(&[7; 32]).public())
.with_ip_addr(SocketAddr::from((Ipv4Addr::LOCALHOST, 7777)));
let error = advertised_endpoint(endpoint, EndpointAddrMask::RelayOnly)
.expect_err("missing relay URL fails");
assert!(
error.contains("requires an endpoint relay URL"),
"unexpected error: {error}"
);
}