Files
quicproquo/crates/quicprochat-p2p/tests/meshservice_tcp_transport.rs
Christian Nennemann 8eba12170e feat: integrate meshservice crate into workspace
- Add meshservice to workspace members
- Fix quicprochat-client: add MeshTrace/MeshStats slash commands
- Add integration test: meshservice_tcp_transport
- Document integration points in README and docs/status.md
- Verify shared identity (IdentityKeypair → MeshAddress)
2026-04-01 18:56:25 +02:00

74 lines
2.6 KiB
Rust

//! Integration: [`meshservice`] wire payloads over [`quicprochat_p2p::transport_tcp::TcpTransport`].
//!
//! Demonstrates that the same Ed25519 seed backs both [`MeshIdentity`] (P2P) and
//! [`meshservice::identity::ServiceIdentity`], so service-layer signatures verify after
//! hop-across-TCP. Production mesh would use [`MeshEnvelope`] / iroh; this test keeps
//! the transport boundary explicit.
use meshservice::capabilities;
use meshservice::identity::ServiceIdentity;
use meshservice::router::ServiceRouter;
use meshservice::services::fapp::{create_announce, FappService, Modality, SlotAnnounce, Specialism};
use meshservice::wire;
use quicprochat_p2p::address::MeshAddress;
use quicprochat_p2p::identity::MeshIdentity;
use quicprochat_p2p::transport::MeshTransport;
use quicprochat_p2p::transport_tcp::TcpTransport;
#[tokio::test]
async fn meshservice_fapp_over_tcp_roundtrip() {
let seed = [0x5eu8; 32];
let mesh = MeshIdentity::from_seed(seed);
let service = ServiceIdentity::from_secret(&seed);
assert_eq!(mesh.public_key(), service.public_key());
assert_eq!(
*MeshAddress::from_public_key(&mesh.public_key()).as_bytes(),
service.address()
);
let announce = SlotAnnounce::new(
&[Specialism::CognitiveBehavioral],
Modality::VideoCall,
"803",
)
.with_slots(2);
let msg = create_announce(&service, &announce, 1).expect("create_announce");
let frame = wire::encode(&msg).expect("wire encode");
let transport = TcpTransport::bind("127.0.0.1:0")
.await
.expect("bind tcp");
let dest = transport.transport_addr();
let recv = tokio::spawn(async move { transport.recv().await.expect("recv") });
let send_transport = TcpTransport::bind("127.0.0.1:0")
.await
.expect("bind sender");
send_transport
.send(&dest, &frame)
.await
.expect("send");
let packet = recv.await.expect("join recv");
let decoded = wire::decode(&packet.data).expect("wire decode");
assert!(decoded.verify(&service.public_key()));
assert_eq!(decoded.service_id, meshservice::service_ids::FAPP);
let mut router = ServiceRouter::new(capabilities::RELAY);
router.register(Box::new(FappService::relay()));
let action = router
.handle(decoded, Some(service.public_key()))
.expect("router handle");
assert!(
matches!(
action,
meshservice::router::ServiceAction::Store
| meshservice::router::ServiceAction::StoreAndForward
),
"unexpected action: {action:?}"
);
assert!(!router.store().is_empty());
}