Collect into an AddressBook in connect.
This commit is contained in:
parent
ecd57f43ed
commit
5e9ac87f57
|
@ -51,7 +51,7 @@ impl Runnable for ConnectCmd {
|
||||||
|
|
||||||
impl ConnectCmd {
|
impl ConnectCmd {
|
||||||
async fn connect(&self) -> Result<(), failure::Error> {
|
async fn connect(&self) -> Result<(), failure::Error> {
|
||||||
use zebra_network::{Request, Response};
|
use zebra_network::{AddressBook, Request, Response};
|
||||||
|
|
||||||
info!("begin tower-based peer handling test stub");
|
info!("begin tower-based peer handling test stub");
|
||||||
use tower::{buffer::Buffer, service_fn, Service, ServiceExt};
|
use tower::{buffer::Buffer, service_fn, Service, ServiceExt};
|
||||||
|
@ -126,16 +126,23 @@ impl ConnectCmd {
|
||||||
addr_reqs.push(peer_set.call(Request::GetPeers));
|
addr_reqs.push(peer_set.call(Request::GetPeers));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut all_addrs = Vec::new();
|
let mut all_addrs = AddressBook::default();
|
||||||
while let Some(Ok(Response::Peers(addrs))) = addr_reqs.next().await {
|
while let Some(Ok(Response::Peers(addrs))) = addr_reqs.next().await {
|
||||||
|
info!(addrs.len = addrs.len(), "got address response");
|
||||||
|
|
||||||
|
let prev_count = all_addrs.peers().count();
|
||||||
|
all_addrs.extend(addrs.into_iter());
|
||||||
|
let count = all_addrs.peers().count();
|
||||||
info!(
|
info!(
|
||||||
all_addrs.len = all_addrs.len(),
|
new_addrs = count - prev_count,
|
||||||
addrs.len = addrs.len(),
|
count, "added addrs to addressbook"
|
||||||
"got address response"
|
|
||||||
);
|
);
|
||||||
all_addrs.extend(addrs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let addrs = all_addrs.drain_recent().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
info!(addrs.len = addrs.len(), ab.len = all_addrs.peers().count());
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// empty loop ensures we don't exit the application,
|
// empty loop ensures we don't exit the application,
|
||||||
// and this is throwaway code
|
// and this is throwaway code
|
||||||
|
|
Loading…
Reference in New Issue