♻️ refactor
parent
b64042043b
commit
4820722ec2
|
@ -27,31 +27,12 @@ async fn main () -> anyhow::Result <()> {
|
|||
|
||||
trace! ("Connecting to relay server");
|
||||
|
||||
let server_id = opt.server_id.unwrap_or (43);
|
||||
|
||||
let quinn::NewConnection {
|
||||
connection,
|
||||
mut bi_streams,
|
||||
..
|
||||
} = endpoint.connect (&relay_addr, "localhost")?.await?;
|
||||
|
||||
let (mut send, mut recv) = connection.open_bi ().await?;
|
||||
|
||||
let our_id = opt.server_id.unwrap_or (43);
|
||||
let req_buf = [
|
||||
Command::CONNECT_P4_TO_P3.0,
|
||||
our_id,
|
||||
0,
|
||||
0,
|
||||
];
|
||||
send.write_all (&req_buf).await?;
|
||||
|
||||
let mut resp_buf = [0, 0, 0, 0];
|
||||
recv.read_exact (&mut resp_buf).await?;
|
||||
assert_eq! (resp_buf, [
|
||||
Command::OKAY.0,
|
||||
Command::CONNECT_P4_TO_P3.0,
|
||||
0,
|
||||
0,
|
||||
]);
|
||||
} = protocol::p4_connect_to_p3 (&endpoint, &relay_addr, server_id).await?;
|
||||
|
||||
trace! ("Accepting bi streams from P3");
|
||||
|
||||
|
|
|
@ -103,3 +103,36 @@ pub async fn p2_connect_to_p5 (
|
|||
|
||||
Ok ((relay_send, relay_recv))
|
||||
}
|
||||
|
||||
pub async fn p4_connect_to_p3 (
|
||||
endpoint: &quinn::Endpoint,
|
||||
relay_addr: &std::net::SocketAddr,
|
||||
server_id: u8,
|
||||
) -> anyhow::Result <quinn::NewConnection>
|
||||
{
|
||||
let new_conn = endpoint.connect (relay_addr, "localhost")?.await?;
|
||||
|
||||
let (mut send, mut recv) = new_conn.connection.open_bi ().await?;
|
||||
|
||||
let req_buf = [
|
||||
Command::CONNECT_P4_TO_P3.0,
|
||||
server_id,
|
||||
0,
|
||||
0,
|
||||
];
|
||||
send.write_all (&req_buf).await?;
|
||||
|
||||
let mut resp_buf = [0, 0, 0, 0];
|
||||
recv.read_exact (&mut resp_buf).await?;
|
||||
let expected = [
|
||||
Command::OKAY.0,
|
||||
Command::CONNECT_P4_TO_P3.0,
|
||||
0,
|
||||
0,
|
||||
];
|
||||
if resp_buf != expected {
|
||||
bail! ("P4 didn't get OK response when connecting to P3");
|
||||
}
|
||||
|
||||
Ok (new_conn)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue