diff --git a/prototypes/quic_demo/src/bin/quic_demo_client.rs b/prototypes/quic_demo/src/bin/quic_demo_client.rs index fd60706..d453acc 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_client.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_client.rs @@ -2,6 +2,7 @@ use structopt::StructOpt; use tokio::net::TcpListener; use quic_demo::prelude::*; +use protocol::PeerId; #[derive (Debug, StructOpt)] struct Opt { @@ -10,9 +11,9 @@ struct Opt { #[structopt (long)] local_tcp_port: Option , #[structopt (long)] - client_id: Option , + client_id: Option , #[structopt (long)] - server_id: Option , + server_id: Option , } #[tokio::main] diff --git a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs index 6bd0f47..40f95c9 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_end_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_end_server.rs @@ -2,6 +2,7 @@ use structopt::StructOpt; use tokio::net::TcpStream; use quic_demo::prelude::*; +use protocol::PeerId; #[derive (Debug, StructOpt)] struct Opt { @@ -10,7 +11,7 @@ struct Opt { #[structopt (long)] local_tcp_port: Option , #[structopt (long)] - server_id: Option , + server_id: Option , } #[tokio::main] @@ -62,7 +63,7 @@ async fn handle_new_ptth_connection ( mut relay_send: quinn::SendStream, mut relay_recv: quinn::RecvStream, local_tcp_port: u16, - _client_id: u8, + _client_id: PeerId, ) -> anyhow::Result <()> { // TODO: Check authorization for P2 --> P4 diff --git a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs index 00d174f..5d95519 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_relay_server.rs @@ -1,6 +1,7 @@ use structopt::StructOpt; use quic_demo::prelude::*; +use protocol::PeerId; #[derive (Debug, StructOpt)] struct Opt { @@ -45,7 +46,7 @@ async fn main () -> anyhow::Result <()> { #[derive (Default)] struct RelayState { - p4_server_proxies: Mutex >, + p4_server_proxies: Mutex >, stats: Stats, } @@ -92,7 +93,7 @@ impl RelayState { struct RequestP2ToP4 { client_send: quinn::SendStream, client_recv: quinn::RecvStream, - client_id: u8, + client_id: PeerId, } struct PtthNewConnection { @@ -227,8 +228,8 @@ async fn handle_p2_connection ( async fn handle_request_p2_to_p4 ( relay_state: Arc , - client_id: u8, - server_id: u8, + client_id: PeerId, + server_id: PeerId, mut client_send: quinn::SendStream, client_recv: quinn::RecvStream, ) -> anyhow::Result <()> diff --git a/prototypes/quic_demo/src/protocol.rs b/prototypes/quic_demo/src/protocol.rs index 1d79481..8c21f78 100644 --- a/prototypes/quic_demo/src/protocol.rs +++ b/prototypes/quic_demo/src/protocol.rs @@ -6,6 +6,8 @@ use quinn::{ use crate::prelude::*; +pub type PeerId = u8; + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Command (pub u8); @@ -21,7 +23,7 @@ impl Command { pub async fn p2_connect_to_p3 ( endpoint: &quinn::Endpoint, relay_addr: &std::net::SocketAddr, - client_id: u8, + client_id: PeerId, ) -> Result { let new_conn = endpoint.connect (relay_addr, "localhost")?.await?; @@ -38,7 +40,7 @@ pub async fn p2_connect_to_p3 ( pub async fn p2_connect_to_p5 ( connection: &quinn::Connection, - server_id: u8, + server_id: PeerId, ) -> Result <(SendStream, RecvStream)> { let (mut send, mut recv) = connection.open_bi ().await?; @@ -70,11 +72,11 @@ pub enum P3Peer { } pub struct P2ClientProxy { - pub id: u8, + pub id: PeerId, } pub struct P4ServerProxy { - pub id: u8, + pub id: PeerId, } pub async fn p3_accept_peer ( @@ -122,7 +124,7 @@ pub async fn p3_authorize_p4_peer ( pub async fn p3_connect_p2_to_p4 ( connection: &quinn::Connection, - client_id: u8, + client_id: PeerId, ) -> Result <(SendStream, RecvStream)> { let (mut send, mut recv) = connection.open_bi ().await?; @@ -145,7 +147,7 @@ pub async fn p3_connect_p2_to_p4 ( pub enum P2ToP3Stream { ConnectP2ToP4 { - server_id: u8, + server_id: PeerId, }, } @@ -177,7 +179,7 @@ pub async fn p3_authorize_p2_to_p4_connection ( pub async fn p4_connect_to_p3 ( endpoint: &quinn::Endpoint, relay_addr: &std::net::SocketAddr, - server_id: u8, + server_id: PeerId, ) -> Result { let new_conn = endpoint.connect (relay_addr, "localhost")?.await?; @@ -194,7 +196,7 @@ pub async fn p4_connect_to_p3 ( pub enum P3ToP4Stream { NewPtthConnection { - client_id: u8, + client_id: PeerId, } } @@ -271,3 +273,5 @@ async fn expect_exact_response ( Ok (()) } + +