diff --git a/zebrad/src/commands/seed.rs b/zebrad/src/commands/seed.rs index f4bbf0662..0ac7352a7 100644 --- a/zebrad/src/commands/seed.rs +++ b/zebrad/src/commands/seed.rs @@ -1,5 +1,11 @@ //! `seed` subcommand - test stub for talking to zcashd +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + use crate::{config::ZebradConfig, prelude::*}; use abscissa_core::{config, Command, FrameworkError, Options, Runnable}; @@ -63,21 +69,48 @@ impl Runnable for SeedCmd { impl SeedCmd { async fn seed(&self) -> Result<(), failure::Error> { use failure::Error; - use futures::stream::{FuturesUnordered, StreamExt}; - use tower::{buffer::Buffer, service_fn, Service, ServiceExt}; + use futures::stream::StreamExt; + use tower::{buffer::Buffer, Service, ServiceExt}; use zebra_network::{AddressBook, Request, Response}; info!("begin tower-based peer handling test stub"); - let node = Buffer::new( - service_fn(|req| { - async move { - info!(?req); - Ok::(Response::Ok) - } - }), - 1, - ); + struct SeedService { + address_book: Option, + } + + impl SeedService { + fn set_address_book(&mut self, address_book: AddressBook) { + self.address_book = Some(address_book); + } + } + + impl Service for SeedService { + type Response = Response; + type Error = Error; + type Future = + Pin> + Send + 'static>>; + + fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { + Ok(()).into() + } + + fn call(&mut self, req: Request) -> Self::Future { + let response = match req { + Request::GetPeers => match &self.address_book { + Some(address_book) => Ok::(Response::Peers( + address_book.peers().collect(), + )), + _ => Ok::(Response::Ok), + }, + _ => Ok::(Response::Ok), + }; + + return Box::pin(futures::future::ready(response)); + } + } + + let node = Buffer::new(SeedService { address_book: None }, 1); let config = app_config().network.clone(); @@ -92,7 +125,8 @@ impl SeedCmd { info!("peer_set became ready"); - loop {} + let eternity = tokio::future::pending::<()>(); + eternity.await; Ok(()) }