♻️ refactor: reduced maximum indentation

main
_ 2021-07-17 08:02:53 +00:00
parent 67fc89e640
commit 82e2aae3d2
1 changed files with 34 additions and 22 deletions

View File

@ -157,7 +157,7 @@ async fn handle_p2_connection (
} = conn; } = conn;
while let Some (bi_stream) = bi_streams.next ().await { while let Some (bi_stream) = bi_streams.next ().await {
let (mut client_send, mut client_recv) = bi_stream?; let (client_send, mut client_recv) = bi_stream?;
let relay_state = Arc::clone (&relay_state); let relay_state = Arc::clone (&relay_state);
tokio::spawn (async move { tokio::spawn (async move {
@ -168,27 +168,7 @@ async fn handle_p2_connection (
match cmd_type { match cmd_type {
1 => { 1 => {
let server_id = req_buf [1]; let server_id = req_buf [1];
handle_request_p2_to_p4 (relay_state, client_id, server_id, client_send, client_recv).await?;
debug! ("P2 {} wants to connect to P4 {}", client_id, server_id);
// TODO: Auth checks
let resp_buf = [0, 0, 0, 0];
client_send.write_all (&resp_buf).await?;
{
let relay_state = relay_state.lock ().await;
match relay_state.p4_server_proxies.get (&server_id) {
Some (p4_state) => {
p4_state.req_channel.send (RequestP2ToP4 {
client_send,
client_recv,
client_id,
}).await.map_err (|_| anyhow::anyhow! ("Can't send request to P4 server"))?;
},
None => warn! ("That server isn't connected"),
}
}
}, },
_ => bail! ("Unknown command type from P2"), _ => bail! ("Unknown command type from P2"),
} }
@ -203,6 +183,38 @@ async fn handle_p2_connection (
Ok (()) Ok (())
} }
async fn handle_request_p2_to_p4 (
relay_state: Arc <Mutex <RelayState>>,
client_id: u8,
server_id: u8,
mut client_send: quinn::SendStream,
client_recv: quinn::RecvStream,
) -> anyhow::Result <()>
{
debug! ("P2 {} wants to connect to P4 {}", client_id, server_id);
// TODO: Auth checks
let resp_buf = [0, 0, 0, 0];
client_send.write_all (&resp_buf).await?;
{
let relay_state = relay_state.lock ().await;
match relay_state.p4_server_proxies.get (&server_id) {
Some (p4_state) => {
p4_state.req_channel.send (RequestP2ToP4 {
client_send,
client_recv,
client_id,
}).await.map_err (|_| anyhow::anyhow! ("Can't send request to P4 server"))?;
},
None => warn! ("That server isn't connected"),
}
}
Ok (())
}
async fn handle_p4_connection ( async fn handle_p4_connection (
relay_state: Arc <Mutex <RelayState>>, relay_state: Arc <Mutex <RelayState>>,
server_id: u8, server_id: u8,