update: both the downstream POCs work, with the bogus downstream.

main
_ 2021-01-12 00:36:13 +00:00
parent 0cb24695d0
commit 8d62b29319
3 changed files with 31 additions and 2 deletions

1
Cargo.lock generated
View File

@ -1662,6 +1662,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.12.3", "base64 0.12.3",
"clap",
"futures", "futures",
"reqwest", "reqwest",
"rmp-serde", "rmp-serde",

View File

@ -9,6 +9,7 @@ edition = "2018"
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
base64 = "0.12.3" base64 = "0.12.3"
clap = "2.33.3"
futures = "0.3.7" futures = "0.3.7"
reqwest = { version = "0.10.8", features = ["stream"] } reqwest = { version = "0.10.8", features = ["stream"] }
rmp-serde = "0.14.4" rmp-serde = "0.14.4"

View File

@ -1,16 +1,43 @@
use clap::{App, SubCommand};
use reqwest::Client; use reqwest::Client;
use tokio::{ use tokio::{
io::AsyncWriteExt, io::AsyncWriteExt,
net::TcpStream, net::{
TcpStream,
TcpListener,
},
stream::StreamExt, stream::StreamExt,
}; };
#[tokio::main] #[tokio::main]
async fn main () -> anyhow::Result <()> { async fn main () -> anyhow::Result <()> {
let matches = App::new ("ptth_forwarding")
.author ("Trish")
.about ("Terminator for PTTH port forwarding")
.subcommand (
SubCommand::with_name ("server")
.about ("Run this on the host with the TCP server")
)
.subcommand (
SubCommand::with_name ("client")
.about ("Run this on the host with the TCP client")
)
.get_matches ();
let client = Client::builder () let client = Client::builder ()
.build ()?; .build ()?;
let mut tcp_stream = TcpStream::connect ("127.0.0.1:4010").await?; let mut tcp_stream = if let Some (matches) = matches.subcommand_matches ("server") {
TcpStream::connect ("127.0.0.1:4010").await?
}
else if let Some (matches) = matches.subcommand_matches ("client") {
let mut listener = TcpListener::bind ("127.0.0.1:4020").await?;
let (stream, _addr) = listener.accept ().await?;
stream
}
else {
panic! ("Must use server or client subcommand.");
};
let resp = client.get ("http://127.0.0.1:4003/").send ().await?; let resp = client.get ("http://127.0.0.1:4003/").send ().await?;
let mut downstream = resp.bytes_stream (); let mut downstream = resp.bytes_stream ();