Unwrap address_book in call(), which relies on poll_ready giving a positive response first, otherwise panic

Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
This commit is contained in:
Deirdre Connolly 2019-11-12 16:36:56 -05:00 committed by Deirdre Connolly
parent fb19febe26
commit bdba52936e
1 changed files with 8 additions and 2 deletions

View File

@ -63,8 +63,14 @@ impl Service<Request> for SeedService {
fn call(&mut self, req: Request) -> Self::Future {
info!("SeedService handling a request: {:?}", req);
let response = match (req, &self.state) {
(Request::GetPeers, SeederState::Ready(address_book)) => {
let address_book = if let SeederState::Ready(address_book) = &self.state {
address_book
} else {
panic!("SeedService::call without SeedService::poll_ready");
};
let response = match req {
Request::GetPeers => {
debug!(address_book.len = address_book.lock().unwrap().len());
info!("SeedService responding to GetPeers");
Ok::<Response, Self::Error>(Response::Peers(