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
Prev Previous commit
Next Next commit
changes from feedback
  • Loading branch information
pepoviola committed Nov 28, 2021
commit 46c25b30bd320a593d7d9f1d0b4e262a2c3c93bc
2 changes: 1 addition & 1 deletion node/zombienet-backchannel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ 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"
lazy_static = "1.4.0"
tracing = "0.1.26"
21 changes: 12 additions & 9 deletions node/zombienet-backchannel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

/// Provides a backchannel to zombienet test runner.
/// Provides the possibility to coordination between malicious actors and
/// the zombienet test-runner, allowing to reference runtime's generated
/// values in the test specifications, through a bidirectional message passing
/// implemented as a `backchannel`.
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;

#[macro_use]
extern crate lazy_static;
use parity_scale_codec as codec;
use lazy_static::lazy_static;

mod errors;
use errors::BackchannelError;
Expand All @@ -32,6 +33,8 @@ pub struct ZombienetBackchannel {
pub inner: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>
}

pub const ZOMBIENET: &str = "ZOMBIENET_BACKCHANNEL🧟🧟🧟";

lazy_static! {
static ref BACKCHANNEL_HOST: String = env::var("BACKCHANNEL_HOST").unwrap_or_else(|_| "backchannel".to_string());
static ref BACKCHANNEL_PORT: String = env::var("BACKCHANNEL_PORT").unwrap_or_else(|_| "3000".to_string());
Expand All @@ -41,7 +44,7 @@ lazy_static! {
impl ZombienetBackchannel {
pub async fn connect() -> Result<ZombienetBackchannel,BackchannelError> {
let ws_url = format!("ws://{}:{}/ws", *BACKCHANNEL_HOST, *BACKCHANNEL_PORT);
log::debug!("Connecting to : {}",&ws_url);
tracing::debug!(target = ZOMBIENET, "Connecting to : {}", &ws_url);
let (ws_stream, _) = connect_async(ws_url).await.map_err(|_| BackchannelError::CantConnectToWS)?;
let (_write, read) = ws_stream.split();

Expand All @@ -50,18 +53,18 @@ impl ZombienetBackchannel {
})
}

pub async fn send(key: &'static str, val: impl scale_codec::Encode) -> Result<(),BackchannelError> {
pub async fn send(key: &'static str, val: impl codec::Encode) -> Result<(),BackchannelError> {
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);
tracing::debug!(target = ZOMBIENET, "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);
tracing::error!(target = ZOMBIENET, "Error sending new item: {}",e);
BackchannelError::SendItemFail
})?;

Expand Down