♻️ refactor: move the last request-response pair into protocol mod
still need to move a couple handle pairsmain
parent
1634f7a00d
commit
75a4515a70
|
@ -2,7 +2,6 @@ use structopt::StructOpt;
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
|
|
||||||
use quic_demo::prelude::*;
|
use quic_demo::prelude::*;
|
||||||
use protocol::Command;
|
|
||||||
|
|
||||||
#[derive (Debug, StructOpt)]
|
#[derive (Debug, StructOpt)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
|
|
@ -314,24 +314,7 @@ async fn handle_p4_connection (
|
||||||
|
|
||||||
debug! ("P4 {} got a request from P2 {}", server_id, req.client_id);
|
debug! ("P4 {} got a request from P2 {}", server_id, req.client_id);
|
||||||
|
|
||||||
let (mut server_send, mut server_recv) = connection.open_bi ().await?;
|
let (server_send, server_recv) = protocol::p3_connect_p2_to_p4 (&connection, client_id).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,
|
|
||||||
]);
|
|
||||||
|
|
||||||
trace! ("Relaying bytes...");
|
trace! ("Relaying bytes...");
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,29 @@ pub async fn p2_connect_to_p5 (
|
||||||
Ok ((send, recv))
|
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 (
|
pub async fn p4_connect_to_p3 (
|
||||||
endpoint: &quinn::Endpoint,
|
endpoint: &quinn::Endpoint,
|
||||||
relay_addr: &std::net::SocketAddr,
|
relay_addr: &std::net::SocketAddr,
|
||||||
|
|
Loading…
Reference in New Issue