Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Peers RPC + UI displaying active/connected/max peers (#1915)
Browse files Browse the repository at this point in the history
* Peers API

* Bumping Parity-UI

* Fixing tests
  • Loading branch information
tomusdrw authored and arkpar committed Aug 12, 2016
1 parent 1ed11b8 commit 50535d3
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 81 deletions.
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dapps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ serde_json = "0.7.0"
serde_macros = { version = "0.7.0", optional = true }
ethcore-rpc = { path = "../rpc" }
ethcore-util = { path = "../util" }
parity-dapps = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6" }
parity-dapps = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4" }
# List of apps
parity-dapps-status = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6" }
parity-dapps-home = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6" }
parity-dapps-wallet = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6", optional = true }
parity-dapps-status = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4" }
parity-dapps-home = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4" }
parity-dapps-wallet = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4", optional = true }
mime_guess = { version = "1.6.1" }
clippy = { version = "0.0.80", optional = true}

Expand Down
4 changes: 0 additions & 4 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,6 @@ impl Configuration {
NetworkSettings {
name: self.args.flag_identity.clone(),
chain: self.chain(),
max_peers: self.max_peers(),
min_peers: self.min_peers(),
network_port: self.args.flag_port,
rpc_enabled: !self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc,
rpc_interface: self.args.flag_rpcaddr.clone().unwrap_or(self.args.flag_jsonrpc_interface.clone()),
Expand Down Expand Up @@ -779,8 +777,6 @@ mod tests {
assert_eq!(conf.network_settings(), NetworkSettings {
name: "testname".to_owned(),
chain: "morden".to_owned(),
max_peers: 50,
min_peers: 25,
network_port: 30303,
rpc_enabled: true,
rpc_interface: "local".to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Informant {
},
paint(Cyan.bold(), format!("{:2}", sync_info.num_active_peers)),
paint(Cyan.bold(), format!("{:2}", sync_info.num_peers)),
paint(Cyan.bold(), format!("{:2}", if sync_info.num_peers as u32 > net_config.min_peers { net_config.max_peers} else { net_config.min_peers} ))
paint(Cyan.bold(), format!("{:2}", sync_info.current_max_peers(net_config.min_peers, net_config.max_peers))),
),
_ => String::new(),
},
Expand Down
2 changes: 1 addition & 1 deletion parity/rpc_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: ApiSet
},
Api::Ethcore => {
let queue = deps.signer_port.map(|_| deps.signer_queue.clone());
server.add_delegate(EthcoreClient::new(&deps.client, &deps.miner, deps.logger.clone(), deps.settings.clone(), queue).to_delegate())
server.add_delegate(EthcoreClient::new(&deps.client, &deps.miner, &deps.sync, &deps.net_service, deps.logger.clone(), deps.settings.clone(), queue).to_delegate())
},
Api::EthcoreSet => {
server.add_delegate(EthcoreSetClient::new(&deps.client, &deps.miner, &deps.net_service).to_delegate())
Expand Down
6 changes: 0 additions & 6 deletions rpc/src/v1/helpers/network_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub struct NetworkSettings {
pub name: String,
/// Name of the chain we are connected to
pub chain: String,
/// Min number of peers
pub min_peers: u32,
/// Max number of peers
pub max_peers: u32,
/// Networking port
pub network_port: u16,
/// Is JSON-RPC server enabled?
Expand All @@ -41,8 +37,6 @@ impl Default for NetworkSettings {
NetworkSettings {
name: "".into(),
chain: "homestead".into(),
min_peers: 25,
max_peers: 50,
network_port: 30303,
rpc_enabled: true,
rpc_interface: "local".into(),
Expand Down
41 changes: 32 additions & 9 deletions rpc/src/v1/impls/ethcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,47 @@ use util::{RotatingLogger};
use util::misc::version_data;
use std::sync::{Arc, Weak};
use std::collections::{BTreeMap};
use ethsync::{SyncProvider, ManageNetwork};
use ethcore::miner::MinerService;
use ethcore::client::{MiningBlockChainClient};

use jsonrpc_core::*;
use ethcore::miner::MinerService;
use v1::traits::Ethcore;
use v1::types::{Bytes, U256};
use v1::types::{Bytes, U256, Peers};
use v1::helpers::{errors, SigningQueue, ConfirmationsQueue, NetworkSettings};
use v1::helpers::params::expect_no_params;

/// Ethcore implementation.
pub struct EthcoreClient<C, M> where
pub struct EthcoreClient<C, M, S: ?Sized> where
C: MiningBlockChainClient,
M: MinerService {
M: MinerService,
S: SyncProvider {

client: Weak<C>,
miner: Weak<M>,
sync: Weak<S>,
net: Weak<ManageNetwork>,
logger: Arc<RotatingLogger>,
settings: Arc<NetworkSettings>,
confirmations_queue: Option<Arc<ConfirmationsQueue>>,
}

impl<C, M> EthcoreClient<C, M> where C: MiningBlockChainClient, M: MinerService {
impl<C, M, S: ?Sized> EthcoreClient<C, M, S> where C: MiningBlockChainClient, M: MinerService, S: SyncProvider {
/// Creates new `EthcoreClient`.
pub fn new(client: &Arc<C>, miner: &Arc<M>, logger: Arc<RotatingLogger>, settings: Arc<NetworkSettings>, queue: Option<Arc<ConfirmationsQueue>>) -> Self {
pub fn new(
client: &Arc<C>,
miner: &Arc<M>,
sync: &Arc<S>,
net: &Arc<ManageNetwork>,
logger: Arc<RotatingLogger>,
settings: Arc<NetworkSettings>,
queue: Option<Arc<ConfirmationsQueue>>
) -> Self {
EthcoreClient {
client: Arc::downgrade(client),
miner: Arc::downgrade(miner),
sync: Arc::downgrade(sync),
net: Arc::downgrade(net),
logger: logger,
settings: settings,
confirmations_queue: queue,
Expand All @@ -58,7 +73,7 @@ impl<C, M> EthcoreClient<C, M> where C: MiningBlockChainClient, M: MinerService
}
}

impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: MiningBlockChainClient + 'static {
impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService + 'static, C: MiningBlockChainClient + 'static, S: SyncProvider + 'static {

fn transactions_limit(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
Expand Down Expand Up @@ -109,10 +124,18 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
to_value(&self.settings.chain)
}

fn net_max_peers(&self, params: Params) -> Result<Value, Error> {
fn net_peers(&self, params: Params) -> Result<Value, Error> {
try!(self.active());
try!(expect_no_params(params));
to_value(&self.settings.max_peers)

let sync_status = take_weak!(self.sync).status();
let net_config = take_weak!(self.net).network_config();

to_value(&Peers {
active: sync_status.num_active_peers,
connected: sync_status.num_peers,
max: sync_status.current_max_peers(net_config.min_peers, net_config.max_peers),
})
}

fn net_port(&self, params: Params) -> Result<Value, Error> {
Expand Down
Loading

0 comments on commit 50535d3

Please sign in to comment.