♻️ refactor: replace `u8` with PeerId
parent
fed401f622
commit
4728e7e35c
|
@ -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 <u16>,
|
||||
#[structopt (long)]
|
||||
client_id: Option <u8>,
|
||||
client_id: Option <PeerId>,
|
||||
#[structopt (long)]
|
||||
server_id: Option <u8>,
|
||||
server_id: Option <PeerId>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
@ -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 <u16>,
|
||||
#[structopt (long)]
|
||||
server_id: Option <u8>,
|
||||
server_id: Option <PeerId>,
|
||||
}
|
||||
|
||||
#[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
|
||||
|
|
|
@ -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 <HashMap <u8, P4State>>,
|
||||
p4_server_proxies: Mutex <HashMap <PeerId, P4State>>,
|
||||
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 <RelayState>,
|
||||
client_id: u8,
|
||||
server_id: u8,
|
||||
client_id: PeerId,
|
||||
server_id: PeerId,
|
||||
mut client_send: quinn::SendStream,
|
||||
client_recv: quinn::RecvStream,
|
||||
) -> anyhow::Result <()>
|
||||
|
|
|
@ -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 <quinn::NewConnection>
|
||||
{
|
||||
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 <quinn::NewConnection>
|
||||
{
|
||||
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 (())
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue