♻️ refactor: reduced maximum indentation
parent
67fc89e640
commit
82e2aae3d2
|
@ -157,7 +157,7 @@ async fn handle_p2_connection (
|
|||
} = conn;
|
||||
|
||||
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);
|
||||
|
||||
tokio::spawn (async move {
|
||||
|
@ -168,27 +168,7 @@ async fn handle_p2_connection (
|
|||
match cmd_type {
|
||||
1 => {
|
||||
let server_id = req_buf [1];
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
handle_request_p2_to_p4 (relay_state, client_id, server_id, client_send, client_recv).await?;
|
||||
},
|
||||
_ => bail! ("Unknown command type from P2"),
|
||||
}
|
||||
|
@ -203,6 +183,38 @@ async fn handle_p2_connection (
|
|||
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 (
|
||||
relay_state: Arc <Mutex <RelayState>>,
|
||||
server_id: u8,
|
||||
|
|
Loading…
Reference in New Issue