use crate::{types::ProtocolName, NotificationsSink};
use bytes::Bytes;
use futures::channel::oneshot;
use libp2p::{kad::record::Key, PeerId};
use sc_network_common::{role::ObservedRole, sync::message::BlockAnnouncesHandshake};
use sp_runtime::traits::Block as BlockT;
#[derive(Debug, Clone)]
#[must_use]
pub enum DhtEvent {
ValueFound(Vec<(Key, Vec<u8>)>),
ValueNotFound(Key),
ValuePut(Key),
ValuePutFailed(Key),
}
#[derive(Debug, Clone)]
#[must_use]
pub enum Event {
Dht(DhtEvent),
NotificationStreamOpened {
remote: PeerId,
protocol: ProtocolName,
negotiated_fallback: Option<ProtocolName>,
role: ObservedRole,
received_handshake: Vec<u8>,
},
NotificationStreamClosed {
remote: PeerId,
protocol: ProtocolName,
},
NotificationsReceived {
remote: PeerId,
messages: Vec<(ProtocolName, Bytes)>,
},
}
pub enum SyncEvent<B: BlockT> {
NotificationStreamOpened {
remote: PeerId,
received_handshake: BlockAnnouncesHandshake<B>,
sink: NotificationsSink,
inbound: bool,
tx: oneshot::Sender<bool>,
},
NotificationStreamClosed {
remote: PeerId,
},
NotificationSinkReplaced {
remote: PeerId,
sink: NotificationsSink,
},
NotificationsReceived {
remote: PeerId,
messages: Vec<Bytes>,
},
}