p2p/identify/
p2p_identify_actions.rs

1use crate::{network::identify::P2pNetworkIdentify, ConnectionAddr, P2pState, PeerId};
2use openmina_macros::ActionEvent;
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Clone, ActionEvent)]
6#[action_event(fields(display(peer_id), display(addr), debug(info)))]
7pub enum P2pIdentifyAction {
8    /// Open a new yamux stream to the remote peer to request its identity
9    NewRequest {
10        peer_id: PeerId,
11        addr: ConnectionAddr,
12    },
13    /// Updates the P2P peer information based on the Identify message sent to us.
14    UpdatePeerInformation {
15        peer_id: PeerId,
16        addr: ConnectionAddr,
17        info: Box<P2pNetworkIdentify>,
18    },
19}
20
21impl redux::EnablingCondition<P2pState> for P2pIdentifyAction {
22    fn is_enabled(&self, state: &P2pState, _time: redux::Timestamp) -> bool {
23        match self {
24            Self::NewRequest { peer_id, .. } => state.get_ready_peer(peer_id).is_some(),
25            Self::UpdatePeerInformation { peer_id, .. } => state.get_ready_peer(peer_id).is_some(),
26        }
27    }
28}