♻️ refactor: move the last request-response pair into protocol mod

still need to move a couple handle pairs
main
_ 2021-07-18 19:45:19 +00:00
parent 1634f7a00d
commit 75a4515a70
3 changed files with 24 additions and 19 deletions

View File

@ -2,7 +2,6 @@ use structopt::StructOpt;
use tokio::net::TcpStream;
use quic_demo::prelude::*;
use protocol::Command;
#[derive (Debug, StructOpt)]
struct Opt {

View File

@ -314,24 +314,7 @@ async fn handle_p4_connection (
debug! ("P4 {} got a request from P2 {}", server_id, req.client_id);
let (mut server_send, mut server_recv) = connection.open_bi ().await?;
let req_buf = [
Command::CONNECT_P2_TO_P4_STEP_2.0,
client_id,
0,
0,
];
server_send.write_all (&req_buf).await?;
let mut resp_buf = [0, 0, 0, 0];
server_recv.read_exact (&mut resp_buf).await?;
assert_eq! (resp_buf, [
Command::OKAY.0,
Command::CONNECT_P2_TO_P4_STEP_2.0,
0,
0,
]);
let (server_send, server_recv) = protocol::p3_connect_p2_to_p4 (&connection, client_id).await?;
trace! ("Relaying bytes...");

View File

@ -64,6 +64,29 @@ pub async fn p2_connect_to_p5 (
Ok ((send, recv))
}
pub async fn p3_connect_p2_to_p4 (
connection: &quinn::Connection,
client_id: u8,
) -> Result <(SendStream, RecvStream)>
{
let (mut send, mut recv) = connection.open_bi ().await?;
let cmd_type = Command::CONNECT_P2_TO_P4_STEP_2.0;
let buf = [
cmd_type,
client_id,
0,
0,
];
send.write_all (&buf).await?;
expect_exact_response (&mut recv, [Command::OKAY.0, cmd_type, 0, 0]).await
.context ("P3 didn't get OK response when asking P4 to connect P2 to P4")?;
Ok ((send, recv))
}
pub async fn p4_connect_to_p3 (
endpoint: &quinn::Endpoint,
relay_addr: &std::net::SocketAddr,