mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
fud/event: add Ready event
This commit is contained in:
@@ -94,6 +94,7 @@ pub struct SeedersFound {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum FudEvent {
|
||||
Ready,
|
||||
DownloadStarted(DownloadStarted),
|
||||
ChunkDownloadCompleted(ChunkDownloadCompleted),
|
||||
MetadataDownloadCompleted(MetadataDownloadCompleted),
|
||||
@@ -217,6 +218,7 @@ impl From<SeedersFound> for JsonValue {
|
||||
impl From<FudEvent> for JsonValue {
|
||||
fn from(event: FudEvent) -> JsonValue {
|
||||
match event {
|
||||
FudEvent::Ready => json_map([("event", json_str("ready"))]),
|
||||
FudEvent::DownloadStarted(info) => {
|
||||
json_map([("event", json_str("download_started")), ("info", info.into())])
|
||||
}
|
||||
@@ -282,5 +284,12 @@ macro_rules! notify_event {
|
||||
}))
|
||||
.await;
|
||||
};
|
||||
// This is for `FudEvent`s with no fields
|
||||
($fud:expr, $event:ident) => {
|
||||
$fud
|
||||
.event_publisher
|
||||
.notify(FudEvent::$event)
|
||||
.await;
|
||||
};
|
||||
}
|
||||
pub(crate) use notify_event;
|
||||
|
||||
@@ -50,6 +50,7 @@ pub async fn handle_dht_events(fud: Arc<Fud>) -> Result<()> {
|
||||
}
|
||||
DhtEvent::BootstrapCompleted => {
|
||||
let _ = fud.init().await;
|
||||
notify_event!(fud, Ready);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user