Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f9ef6b9
initial impl zombienet backchannel
pepoviola Nov 25, 2021
ce50d2f
clean code
pepoviola Nov 25, 2021
46c25b3
changes from feedback
pepoviola Nov 28, 2021
6a3b7c6
fmt and typo
pepoviola Nov 28, 2021
e6f73a1
remove default comment
pepoviola Nov 28, 2021
b3be116
refactor to use ws tx/rx
pepoviola Dec 7, 2021
b3eed29
fmt
pepoviola Dec 7, 2021
91b6975
Merge branch 'master' into javier-zombienet-backchannel
pepoviola Dec 7, 2021
5953051
derive Clone for ZombienetBackchannel
pepoviola Dec 7, 2021
e340d32
Revert "derive Clone for ZombienetBackchannel"
pepoviola Dec 7, 2021
0ccb705
change tracing prefix value
pepoviola Dec 9, 2021
39dae39
Merge branch 'master' into javier-zombienet-backchannel
pepoviola Dec 14, 2021
f3014e7
refactor backchannel
pepoviola Dec 14, 2021
1558d42
Update node/zombienet-backchannel/Cargo.toml
pepoviola Dec 14, 2021
bd729ae
add docs to broadcaster methods
pepoviola Dec 14, 2021
486794f
add more docs
pepoviola Dec 14, 2021
ed47fee
Merge branch 'master' into javier-zombienet-backchannel
pepoviola Dec 23, 2021
16a7b99
fmt
pepoviola Dec 23, 2021
c83269d
Merge branch 'master' into javier-zombienet-backchannel
pepoviola Jan 6, 2022
1e001cd
fix spellcheck
pepoviola Jan 6, 2022
d1e4223
update lock file
pepoviola Jan 6, 2022
1a38285
remove unused
pepoviola Jan 6, 2022
e4d9dbc
fmt
pepoviola Jan 6, 2022
c5a0791
Merge branch 'master' into javier-zombienet-backchannel
pepoviola Jan 7, 2022
9cda227
changes from feedback
pepoviola Jan 7, 2022
d14b7c8
fmt
pepoviola Jan 7, 2022
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
Next Next commit
initial impl zombienet backchannel
  • Loading branch information
pepoviola committed Nov 25, 2021
commit f9ef6b978ebd0caaa2c62dbbbec149576be0ae1b
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ members = [
"node/test/polkadot-simnet/common",
"node/test/polkadot-simnet/node",
"node/test/polkadot-simnet/test",
"node/zombienet-backchannel",
"parachain/test-parachains",
"parachain/test-parachains/adder",
"parachain/test-parachains/adder/collator",
Expand Down
27 changes: 27 additions & 0 deletions node/zombienet-backchannel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "backchannel-cli"
version = "0.1.0"
edition = "2021"

[package]
name = "zombienet-backchannel"
description = "Zombienet backchannel to notify test runner and coordinate with malus actors."
license = "GPL-3.0-only"
version = "0.9.13"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
readme = "README.md"
publish = false


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
# futures-channel = "0.3"
tokio = { version = "1.0.0", default-features = false, features = ["macros", "net", "rt-multi-thread"] }
url = "2.0.0"
tokio-tungstenite = "0.16"
futures-util = "0.3.18"
parity-scale-codec = { version = "2.3.1", features = ["derive"] }
reqwest = "0.11"
thiserror = "1.0.30"
log = "0.4.13"
57 changes: 57 additions & 0 deletions node/zombienet-backchannel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/// Provides a backchannel to zombienet test runner.

use std::env;

use futures_util::{StreamExt, stream::SplitStream};
use tokio::net::TcpStream;
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async};
use parity_scale_codec as scale_codec;

mod errors;
use errors::BackchannelError;

#[derive(Debug)]
pub struct ZombienetBackchannel {
pub inner: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>
}

const BACKCHANNEL_HOST: &str = "backchannel";
const BACKCHANNEL_PORT: &str = "3000";

impl ZombienetBackchannel {
pub async fn connect() -> Result<ZombienetBackchannel,BackchannelError> {
let backchannel_host = env::var("BACKCHANNEL_HOST").unwrap_or_else(|_| BACKCHANNEL_HOST.to_string());
let backchannel_port = env::var("BACKCHANNEL_PORT").unwrap_or_else(|_| BACKCHANNEL_PORT.to_string());

let ws_url = format!("ws://{}:{}/ws", backchannel_host, backchannel_port);
log::debug!("Connecting to : {}",&ws_url);
let (ws_stream, _) = connect_async(ws_url).await.map_err(|_| BackchannelError::CantConnectToWS)?;
let (_write, read) = ws_stream.split();

Ok( ZombienetBackchannel {
inner: read
})
}

pub async fn send(key: &'static str, val: impl scale_codec::Encode) -> Result<(),BackchannelError> {
let backchannel_host = env::var("BACKCHANNEL_HOST").unwrap_or_else(|_| BACKCHANNEL_HOST.to_string());
let backchannel_port = env::var("BACKCHANNEL_PORT").unwrap_or_else(|_| BACKCHANNEL_PORT.to_string());

let client = reqwest::Client::new();
let encoded = val.encode();
let body = String::from_utf8_lossy(&encoded);
let zombienet_endpoint = format!("http://{}:{}/{}",backchannel_host, backchannel_port, key);

log::debug!("Sending to : {}",&zombienet_endpoint);
let _res = client.post(zombienet_endpoint)
.body(body.to_string())
.send()
.await.map_err(|e| {
log::error!("Error sending new item: {}",e);
BackchannelError::SendItemFail
})?;

Ok(())
}
}