Skip to main content

huddle_core/network/
events.rs

1use libp2p::{Multiaddr, PeerId};
2
3use crate::network::protocol::RoomAnnouncement;
4
5#[derive(Debug, Clone)]
6pub enum NetworkEvent {
7    /// A peer was discovered on the LAN (mDNS).
8    PeerDiscovered { peer_id: PeerId },
9    /// A peer's mDNS record expired.
10    PeerExpired { peer_id: PeerId },
11    /// A room was announced on the global rooms topic.
12    RoomAnnouncementReceived(RoomAnnouncement),
13    /// A raw message arrived on a per-room topic. Payload is the
14    /// JSON-encoded `RoomMessage` — decoded by the app layer.
15    RoomMessageReceived {
16        room_id: String,
17        payload: Vec<u8>,
18        from_peer: PeerId,
19    },
20    ListeningOn { address: Multiaddr },
21    /// A user-initiated dial to `address` succeeded — the remote peer
22    /// is `peer_id` and the swarm now has an open connection.
23    DialSucceeded { peer_id: PeerId, address: Multiaddr },
24    /// A user-initiated dial failed before establishing a connection.
25    DialFailed { address: Multiaddr, error: String },
26    /// Phase A: Identify has completed for `peer_id` and we've decoded
27    /// their Ed25519 fingerprint. Fired for every peer (inbound or
28    /// outbound) so the app layer can populate `known_peers.fingerprint`
29    /// and mark previously-dialed peers as `trusted=1`.
30    PeerIdentified { peer_id: PeerId, fingerprint: String },
31    /// Phase A: an unknown peer has dialed us (listener side) and their
32    /// Identify just landed. The peer is NOT yet in our gossipsub
33    /// explicit-peers set — the app layer must respond with either
34    /// `AcceptInbound` or `RejectInbound` (or let the 15s TUI timeout
35    /// auto-reject).
36    InboundDial {
37        peer_id: PeerId,
38        fingerprint: String,
39        address: Multiaddr,
40    },
41    /// Phase D: a `/p2p-circuit` reservation on a configured relay
42    /// succeeded — peers across the internet can now dial us via this
43    /// circuit address. Fires when libp2p emits `NewListenAddr` for an
44    /// address with `/p2p-circuit/` in its path.
45    RelayReservationEstablished { address: Multiaddr },
46    /// Phase D follow-up: AutoNAT v2 client finished a reachability
47    /// probe for one of our candidate external addresses. `reachable`
48    /// is true if a remote AutoNAT server successfully dialed us back.
49    /// One probe per address candidate; the app layer aggregates these
50    /// into the overall reachability badge shown in the lobby.
51    NatProbeResult {
52        tested_addr: Multiaddr,
53        reachable: bool,
54    },
55    /// Phase D follow-up: a Direct-Connection-Upgrade-through-Relay
56    /// attempt completed. `success` is true if a direct connection was
57    /// established (the relay hop is dropped at that point). The TUI
58    /// shows transient status when this fires.
59    DcutrUpgrade {
60        remote_peer: PeerId,
61        success: bool,
62    },
63    /// huddle 0.7.11: a connection to `peer_id` closed (last connection
64    /// to that peer). Fires once per (peer disappears) regardless of how
65    /// many underlying connections there were. The app layer uses this
66    /// to clean `connected_dial_addrs` and update the lobby's online
67    /// dots — pre-0.7.11 only mDNS PeerExpired was wired, so relay /
68    /// internet peers stayed "online" in the lobby long after they
69    /// dropped.
70    PeerDisconnected { peer_id: PeerId },
71    // huddle 0.7.11 declared `RelayReservationLost { relay_peer }`
72    // here but no producer in libp2p 0.56 actually emits it; we
73    // removed the variant in 0.7.12 rather than ship dead code.
74    // A future health-check timer can re-introduce it.
75}