Skip to main content

running_process/
backend_identity.rs

1//! Narrow direct-daemon identity substrate.
2//!
3//! A daemon that already owns its endpoint and legacy/application payloads can
4//! persist its launch identity, answer the frozen v1 nonce probe on that same
5//! endpoint, and later verify it without adopting the running-process broker.
6//! Endpoint spelling, product naming, payload decoding, and lifecycle policy
7//! deliberately remain caller-owned.
8
9// These implementation modules deliberately live under the direct identity
10// facade. The legacy v1/v2 broker namespaces below re-export their items, so
11// a consumer can move to this surface without forking `TypeId`s.
12#[path = "broker/backend_handle.rs"]
13pub(crate) mod handle;
14#[path = "broker/backend_lifecycle/identity.rs"]
15pub(crate) mod identity;
16
17pub use self::handle::BackendHandle;
18#[cfg(feature = "client")]
19pub use self::handle::{BackendHandleError, Connection};
20pub use self::identity::{DaemonIdentityHashPolicy, DaemonProcess, IdentityError};
21pub use crate::broker::backend_lifecycle::probe::{
22    endpoint_probe_request_from_frame, endpoint_probe_response_frame, handle_endpoint_probe,
23    read_endpoint_probe_request, write_endpoint_probe_response, EndpointProbeRequest,
24    EndpointProbeServerError,
25};
26pub use crate::broker::backend_sdk::{
27    read_daemon_identity_file, remove_daemon_identity_file, try_read_daemon_identity_file,
28    write_daemon_identity_file, BackendEndpointMux, LegacyClassification, MuxError, MuxPoll,
29};
30pub use crate::broker::protocol::{Endpoint, EndpointNameError};
31pub use crate::frame_v1::{
32    encode_framed, read_frame, read_frame_with_cap, try_decode_framed, write_frame, DecodedFramed,
33    Frame, FrameKind, FramingError, PayloadEncoding, BACKEND_HANDLE_PROBE_PAYLOAD_PROTOCOL,
34    ENVELOPE_VERSION, FRAME_HEADER_BYTES, MAX_FRAME_BYTES, MAX_HELLO_BYTES, PROTOCOL_VERSION,
35};
36
37#[cfg(all(test, feature = "client"))]
38mod type_identity_tests {
39    use std::any::TypeId;
40
41    #[test]
42    fn legacy_broker_paths_are_literal_direct_identity_aliases() {
43        assert_eq!(
44            TypeId::of::<super::BackendHandle>(),
45            TypeId::of::<crate::broker::backend_handle::BackendHandle>(),
46        );
47        assert_eq!(
48            TypeId::of::<super::DaemonProcess>(),
49            TypeId::of::<crate::broker::backend_handle::DaemonProcess>(),
50        );
51        assert_eq!(
52            TypeId::of::<super::Connection>(),
53            TypeId::of::<crate::broker::backend_handle::Connection>(),
54        );
55        assert_eq!(
56            TypeId::of::<super::BackendHandleError>(),
57            TypeId::of::<crate::broker::backend_handle::BackendHandleError>(),
58        );
59    }
60}
61
62#[cfg(test)]
63mod direct_probe_e2e_tests {
64    use std::thread;
65
66    use super::{handle_endpoint_probe, BackendHandle, DaemonProcess, Endpoint};
67
68    #[test]
69    fn direct_identity_probe_round_trips_over_the_existing_endpoint() {
70        let transport_endpoint = crate::platform::ipc::Endpoint::test("backend-identity-e2e")
71            .expect("allocate test endpoint");
72        let endpoint = Endpoint {
73            namespace_id: "backend-identity-e2e".to_owned(),
74            path: transport_endpoint.display().to_owned(),
75        };
76        let daemon = DaemonProcess::current_process(endpoint.clone(), Some(30))
77            .expect("current daemon identity");
78        let listener = crate::platform::ipc::Listener::bind(&transport_endpoint)
79            .expect("bind existing daemon endpoint");
80        let responder_identity = daemon.clone();
81        let responder = thread::spawn(move || {
82            let mut stream = listener.accept().expect("accept identity probe");
83            handle_endpoint_probe(&mut stream, &responder_identity)
84                .expect("answer nonce identity probe");
85        });
86
87        let handle = BackendHandle::probe(&endpoint, &daemon)
88            .expect("current daemon must verify over its existing endpoint");
89        assert_eq!(handle.daemon_process, daemon);
90        responder.join().expect("identity responder exits");
91    }
92}