Add a stub connector future.

Running zcashd with -debug=net -logips=1 shows

Added connection to 127.0.0.1:58476 peer=1
connection from 127.0.0.1:58476 accepted
disconnecting peer=1
This commit is contained in:
Henry de Valence 2019-09-11 23:21:15 -07:00
parent f63651c7dc
commit fe11989fa5
2 changed files with 48 additions and 1 deletions

View File

@ -21,6 +21,9 @@ hyper = { git = "https://github.com/hyperium/hyper" }
futures-core-preview = { version = "=0.3.0-alpha.18" }
futures-util-preview = { version = "=0.3.0-alpha.18" }
zebra-chain = { path = "../zebra-chain" }
zebra-network = { path = "../zebra-network" }
[dev-dependencies.abscissa_core]
version = "0.3.0"
features = ["testing"]

View File

@ -22,12 +22,56 @@ impl Runnable for ConnectCmd {
use crate::components::tokio::TokioComponent;
let wait = tokio::future::pending::<()>();
// Combine the connect future with an infinite wait
// so that the program has to be explicitly killed and
// won't die before all tracing messages are written.
let fut = futures_util::future::join(self.connect(), wait);
app_reader()
.state()
.components
.get_downcast_ref::<TokioComponent>()
.expect("TokioComponent should be available")
.rt
.block_on(tokio::future::pending::<()>());
.block_on(fut);
}
}
impl ConnectCmd {
async fn connect(&self) {
use std::net::Shutdown;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
info!("connecting");
let mut stream = TcpStream::connect(self.addr)
.await
.expect("connection should succeed");
/*
use chrono::{DateTime, Utc};
use zebra_network::message;
use zebra_chain::types::BlockHeight;
let version = message::Message::Version {
version: message::ZCASH_VERSION,
services: message::Services(1),
timestamp: DateTime::<Utc>::now(),
address_receiving: (pub self.addr,
address_from: "127.0.0.1:9000".parse().unwrap(),
nonce: message::Nonce(1),
user_agent: "Zebra Connect".to_owned(),
start_height: BlockHeight(0),
};
*/
stream
.write_all(b"hello zcashd -- this is a bogus message, will you accept it or close the connection?")
.await
.expect("bytes should be written into stream");
stream
.shutdown(Shutdown::Both)
.expect("stream should shut down cleanly");
}
}