Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible peer filtering #3458

Merged
merged 8 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions api/src/handlers/peers_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct PeersAllHandler {

impl Handler for PeersAllHandler {
fn get(&self, _req: Request<Body>) -> ResponseFuture {
let peers = &w_fut!(&self.peers).all_peers();
let peers = &w_fut!(&self.peers).all_peer_data();
json_response_pretty(&peers)
}
}
Expand All @@ -40,8 +40,9 @@ pub struct PeersConnectedHandler {
impl PeersConnectedHandler {
pub fn get_connected_peers(&self) -> Result<Vec<PeerInfoDisplay>, Error> {
let peers = w(&self.peers)?
.connected_peers()
.iter()
.connected()
.into_iter()
.map(|p| p.info.clone().into())
.collect::<Vec<PeerInfoDisplay>>();
Ok(peers)
Expand All @@ -51,8 +52,9 @@ impl PeersConnectedHandler {
impl Handler for PeersConnectedHandler {
fn get(&self, _req: Request<Body>) -> ResponseFuture {
let peers: Vec<PeerInfoDisplay> = w_fut!(&self.peers)
.connected_peers()
.iter()
.connected()
.into_iter()
.map(|p| p.info.clone().into())
.collect();
json_response(&peers)
Expand All @@ -77,7 +79,7 @@ impl PeerHandler {
})?;
return Ok(vec![peer_data]);
}
let peers = w(&self.peers)?.all_peers();
let peers = w(&self.peers)?.all_peer_data();
Ok(peers)
}

Expand Down
8 changes: 7 additions & 1 deletion api/src/handlers/server_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::types::*;
use crate::web::*;
use hyper::{Body, Request};
use serde_json::json;
use std::convert::TryInto;
use std::sync::Weak;

// RESTful index of available api endpoints
Expand Down Expand Up @@ -54,7 +55,12 @@ impl StatusHandler {
let (api_sync_status, api_sync_info) = sync_status_to_api(sync_status);
Ok(Status::from_tip_and_peers(
head,
w(&self.peers)?.peer_count(),
w(&self.peers)?
.iter()
.connected()
.count()
.try_into()
.unwrap(),
jaspervdm marked this conversation as resolved.
Show resolved Hide resolved
api_sync_status,
api_sync_info,
))
Expand Down
Loading