Skip to content

Commit 3d8318c

Browse files
committed
add idle call (WIP)
1 parent d8bd40d commit 3d8318c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

network-cardano/src/blockfetch.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,32 @@ impl BlockFetchServer {
8181
{
8282
self.0.read_one_match(f).await
8383
}
84+
85+
// TODO in-progress API
86+
pub async fn idle<F, Fut, R>(
87+
&mut self,
88+
f: F,
89+
) -> Result<Option<R>, MessageError<blockfetch::State>>
90+
where
91+
F: FnOnce(blockfetch::Point, blockfetch::Point) -> Fut,
92+
Fut: Future<Output = Option<R>>,
93+
{
94+
match self
95+
.0
96+
.read_one_match(blockfetch::server_idle_message_filter)
97+
.await?
98+
{
99+
blockfetch::OnIdleMsg::RequestRange(point_start, point_end) => {
100+
let r = f(point_start, point_end).await;
101+
let reply_msg = if r.is_some() {
102+
blockfetch::Message::StartBatch
103+
} else {
104+
blockfetch::Message::NoBlocks
105+
};
106+
self.0.write_one(reply_msg).await;
107+
Ok(r)
108+
}
109+
blockfetch::OnIdleMsg::ClientDone => Ok(None),
110+
}
111+
}
84112
}

0 commit comments

Comments
 (0)