referrerpolicy=no-referrer-when-downgrade

malus/
shared.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use futures::prelude::*;
18use sp_core::traits::SpawnNamed;
19
20pub const MALUS: &str = "MALUS";
21
22#[allow(unused)]
23pub(crate) const MALICIOUS_POV: &[u8] = "😈😈pov_looks_valid_to_me😈😈".as_bytes();
24
25/// Launch a service task for each item in the provided queue.
26#[allow(unused)]
27pub(crate) fn launch_processing_task<X, F, U, Q, S>(spawner: &S, queue: Q, action: F)
28where
29	F: Fn(X) -> U + Send + 'static,
30	U: Future<Output = ()> + Send + 'static,
31	Q: Stream<Item = X> + Send + 'static,
32	X: Send,
33	S: 'static + SpawnNamed + Clone + Unpin,
34{
35	let spawner2: S = spawner.clone();
36	spawner.spawn(
37		"nemesis-queue-processor",
38		Some("malus"),
39		Box::pin(async move {
40			let spawner3 = spawner2.clone();
41			queue
42				.for_each(move |input| {
43					spawner3.spawn("nemesis-task", Some("malus"), Box::pin(action(input)));
44					async move { () }
45				})
46				.await;
47		}),
48	);
49}