mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-12 19:11:01 +00:00
Merge pull request #315 from paritytech/dp-add-denylist-for-unwanted-networks
Add --denylist ChainIDontWant OtherChainIDontWant
This commit is contained in:
@@ -15,6 +15,8 @@ pub struct Aggregator {
|
||||
chains: DenseMap<ChainEntry>,
|
||||
feeds: DenseMap<Addr<FeedConnector>>,
|
||||
serializer: FeedMessageSerializer,
|
||||
/// Denylist for networks we do not want to allow connecting.
|
||||
denylist: HashSet<String>
|
||||
}
|
||||
|
||||
pub struct ChainEntry {
|
||||
@@ -43,13 +45,14 @@ lazy_static! {
|
||||
const THIRD_PARTY_NETWORKS_MAX_NODES: usize = 500;
|
||||
|
||||
impl Aggregator {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(denylist: HashSet<String>) -> Self {
|
||||
Aggregator {
|
||||
labels: HashMap::new(),
|
||||
networks: HashMap::new(),
|
||||
chains: DenseMap::new(),
|
||||
feeds: DenseMap::new(),
|
||||
serializer: FeedMessageSerializer::new(),
|
||||
denylist,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +195,10 @@ impl Handler<AddNode> for Aggregator {
|
||||
type Result = ();
|
||||
|
||||
fn handle(&mut self, msg: AddNode, ctx: &mut Self::Context) {
|
||||
if self.denylist.contains(&*msg.node.chain) {
|
||||
log::debug!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain);
|
||||
return;
|
||||
}
|
||||
let AddNode { node, conn_id, rec } = msg;
|
||||
log::trace!(target: "Aggregator::AddNode", "New node connected. Chain '{}'", node.chain);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ pub type Label = Arc<str>;
|
||||
|
||||
pub struct Chain {
|
||||
cid: ChainId,
|
||||
/// Who to inform if we Chain drops itself
|
||||
/// Who to inform if the Chain drops itself
|
||||
aggregator: Addr<Aggregator>,
|
||||
/// Label of this chain, along with count of nodes that use this label
|
||||
label: (Label, usize),
|
||||
|
||||
+13
-3
@@ -1,4 +1,6 @@
|
||||
use std::net::Ipv4Addr;
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use actix::prelude::*;
|
||||
use actix_http::ws::Codec;
|
||||
@@ -25,16 +27,23 @@ const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
||||
const NAME: &str = "Substrate Telemetry Backend";
|
||||
const ABOUT: &str = "This is the Telemetry Backend that injects and provide the data sent by Substrate/Polkadot nodes";
|
||||
|
||||
#[derive(Clap)]
|
||||
#[derive(Clap, Debug)]
|
||||
#[clap(name = NAME, version = VERSION, author = AUTHORS, about = ABOUT)]
|
||||
struct Opts {
|
||||
#[clap(
|
||||
short = 'l',
|
||||
long = "listen",
|
||||
default_value = "127.0.0.1:8000",
|
||||
about = "This is the socket address Telemetry is listening to. This is restricted localhost (127.0.0.1) by default and should be fine for most use cases. If you are using Telemetry in a container, you likely want to set this to '0.0.0.0:8000'"
|
||||
about = "This is the socket address Telemetry is listening to. This is restricted to localhost (127.0.0.1) by default and should be fine for most use cases. If you are using Telemetry in a container, you likely want to set this to '0.0.0.0:8000'"
|
||||
)]
|
||||
socket: std::net::SocketAddr,
|
||||
#[clap(
|
||||
required = false,
|
||||
long = "denylist",
|
||||
default_value = "Earth",
|
||||
about = "Space delimited list of chains that are not allowed to connect to telemetry. Case sensitive."
|
||||
)]
|
||||
denylist: Vec<String>,
|
||||
#[clap(
|
||||
arg_enum,
|
||||
required = false,
|
||||
@@ -160,7 +169,8 @@ async fn main() -> std::io::Result<()> {
|
||||
let log_level = &opts.log_level;
|
||||
SimpleLogger::new().with_level(log_level.into()).init().expect("Must be able to start a logger");
|
||||
|
||||
let aggregator = Aggregator::new().start();
|
||||
let denylist = HashSet::from_iter(opts.denylist);
|
||||
let aggregator = Aggregator::new(denylist).start();
|
||||
let factory = LocatorFactory::new();
|
||||
let locator = SyncArbiter::start(4, move || factory.create());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user