Connection filter (#6359)
This commit is contained in:
committed by
Gav Wood
parent
96e9a73a1b
commit
d520aa2633
@@ -69,6 +69,7 @@ extern crate parity_updater as updater;
|
||||
extern crate parity_whisper;
|
||||
extern crate path;
|
||||
extern crate rpc_cli;
|
||||
extern crate node_filter;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log as rlog;
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::path::Path;
|
||||
|
||||
use ethcore::client::BlockChainClient;
|
||||
use hypervisor::Hypervisor;
|
||||
use ethsync::{AttachedProtocol, SyncConfig, NetworkConfiguration, NetworkError, Params};
|
||||
use ethsync::{AttachedProtocol, SyncConfig, NetworkConfiguration, NetworkError, Params, ConnectionFilter};
|
||||
use ethcore::snapshot::SnapshotService;
|
||||
use light::Provider;
|
||||
|
||||
@@ -183,6 +183,7 @@ pub fn sync(
|
||||
provider: Arc<Provider>,
|
||||
_log_settings: &LogConfig,
|
||||
attached_protos: Vec<AttachedProtocol>,
|
||||
connection_filter: Option<Arc<ConnectionFilter>>,
|
||||
) -> Result<SyncModules, NetworkError> {
|
||||
let eth_sync = EthSync::new(Params {
|
||||
config: sync_cfg,
|
||||
@@ -191,7 +192,8 @@ pub fn sync(
|
||||
snapshot_service: snapshot_service,
|
||||
network_config: net_cfg,
|
||||
attached_protos: attached_protos,
|
||||
})?;
|
||||
},
|
||||
connection_filter)?;
|
||||
|
||||
Ok((eth_sync.clone() as Arc<SyncProvider>, eth_sync.clone() as Arc<ManageNetwork>, eth_sync.clone() as Arc<ChainNotify>))
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::net::{TcpListener};
|
||||
|
||||
use ctrlc::CtrlC;
|
||||
@@ -38,6 +38,7 @@ use parity_reactor::EventLoop;
|
||||
use parity_rpc::{NetworkSettings, informant, is_major_importing};
|
||||
use updater::{UpdatePolicy, Updater};
|
||||
use util::{Colour, version, Mutex, Condvar};
|
||||
use node_filter::NodeFilter;
|
||||
|
||||
use params::{
|
||||
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,
|
||||
@@ -569,11 +570,13 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
miner.clone(),
|
||||
).map_err(|e| format!("Client service error: {:?}", e))?;
|
||||
|
||||
let connection_filter_address = spec.params().node_permission_contract;
|
||||
// drop the spec to free up genesis state.
|
||||
drop(spec);
|
||||
|
||||
// take handle to client
|
||||
let client = service.client();
|
||||
let connection_filter = connection_filter_address.map(|a| Arc::new(NodeFilter::new(Arc::downgrade(&client) as Weak<BlockChainClient>, a)));
|
||||
let snapshot_service = service.snapshot_service();
|
||||
|
||||
// initialize the local node information store.
|
||||
@@ -645,9 +648,13 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
|
||||
client.clone(),
|
||||
&cmd.logger_config,
|
||||
attached_protos,
|
||||
connection_filter.clone().map(|f| f as Arc<::ethsync::ConnectionFilter + 'static>),
|
||||
).map_err(|e| format!("Sync error: {}", e))?;
|
||||
|
||||
service.add_notify(chain_notify.clone());
|
||||
if let Some(filter) = connection_filter {
|
||||
service.add_notify(filter);
|
||||
}
|
||||
|
||||
// start network
|
||||
if network_enabled {
|
||||
|
||||
Reference in New Issue
Block a user