♻️ refactor
parent
d5431b5c62
commit
ca3145669d
|
@ -40,53 +40,27 @@ pub async fn p2_connect_to_p5 (
|
||||||
server_id: u8,
|
server_id: u8,
|
||||||
) -> anyhow::Result <(SendStream, RecvStream)>
|
) -> anyhow::Result <(SendStream, RecvStream)>
|
||||||
{
|
{
|
||||||
let (mut relay_send, mut relay_recv) = connection.open_bi ().await?;
|
let (mut send, mut recv) = connection.open_bi ().await?;
|
||||||
|
|
||||||
// Ask P3 if we can connect to P4
|
// Ask P3 if we can connect to P4
|
||||||
|
|
||||||
let req_buf = [
|
let cmd_type = Command::CONNECT_P2_TO_P4.0;
|
||||||
Command::CONNECT_P2_TO_P4.0,
|
|
||||||
server_id,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
relay_send.write_all (&req_buf).await?;
|
|
||||||
|
|
||||||
let mut resp_buf = [0; 4];
|
send.write_all (&[cmd_type, server_id, 0, 0]).await?;
|
||||||
relay_recv.read_exact (&mut resp_buf).await?;
|
|
||||||
let expected = [
|
expect_exact_response (&mut recv, [Command::OKAY.0, cmd_type, 0, 0]).await
|
||||||
Command::OKAY.0,
|
.context ("P2 didn't get OK response when asking P3 to connect P2 to P4")?;
|
||||||
Command::CONNECT_P2_TO_P4.0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
if resp_buf != expected {
|
|
||||||
bail! ("P2 didn't get OK response when asking P3 to connect P2 to P4");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask P4 if we can connect to P5
|
// Ask P4 if we can connect to P5
|
||||||
|
|
||||||
let req_buf = [
|
let cmd_type = Command::CONNECT_P2_TO_P5.0;
|
||||||
Command::CONNECT_P2_TO_P5.0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
relay_send.write_all (&req_buf).await?;
|
|
||||||
|
|
||||||
let mut resp_buf = [0; 4];
|
send.write_all (&[cmd_type, 0, 0, 0]).await?;
|
||||||
relay_recv.read_exact (&mut resp_buf).await?;
|
|
||||||
let expected = [
|
|
||||||
Command::OKAY.0,
|
|
||||||
Command::CONNECT_P2_TO_P5.0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
];
|
|
||||||
if resp_buf != expected {
|
|
||||||
bail! ("P2 didn't get OK response when asking P4 to connect P2 to P5");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok ((relay_send, relay_recv))
|
expect_exact_response (&mut recv, [Command::OKAY.0, cmd_type, 0, 0]).await
|
||||||
|
.context ("P2 didn't get OK response when asking P4 to connect P2 to P5")?;
|
||||||
|
|
||||||
|
Ok ((send, recv))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn p4_connect_to_p3 (
|
pub async fn p4_connect_to_p3 (
|
||||||
|
|
Loading…
Reference in New Issue