File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments