Skip to content

Commit

Permalink
address code review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed Oct 11, 2024
1 parent 681fd98 commit 885af26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions crates/tx5/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl BackendModule {
url: &str,
listener: bool,
config: &Arc<Config>,
) -> Result<(DynBackEp, DynBackEpRecv)> {
) -> Result<(DynBackEp, DynBackEpRecvCon)> {
match self {
#[cfg(feature = "backend-go-pion")]
Self::GoPion => go_pion::connect(config, url, listener).await,
Expand Down Expand Up @@ -87,13 +87,13 @@ pub trait BackCon: 'static + Send + Sync {
pub type DynBackCon = Arc<dyn BackCon + 'static + Send + Sync>;

/// Backend connection receiver.
pub trait BackConRecv: 'static + Send {
pub trait BackConRecvData: 'static + Send {
/// Receive data from this backend connection.
fn recv(&mut self) -> BoxFuture<'_, Option<Vec<u8>>>;
}

/// Trait-object version of backend connection receiver.
pub type DynBackConRecv = Box<dyn BackConRecv + 'static + Send>;
pub type DynBackConRecvData = Box<dyn BackConRecvData + 'static + Send>;

/// Pending connection.
pub trait BackWaitCon: 'static + Send {
Expand All @@ -102,7 +102,7 @@ pub trait BackWaitCon: 'static + Send {
&mut self,
// TODO - this isn't good encapsulation
recv_limit: Arc<tokio::sync::Semaphore>,
) -> BoxFuture<'static, Result<(DynBackCon, DynBackConRecv)>>;
) -> BoxFuture<'static, Result<(DynBackCon, DynBackConRecvData)>>;

/// Get the pub_key identifying this connection.
fn pub_key(&self) -> &PubKey;
Expand All @@ -125,10 +125,10 @@ pub trait BackEp: 'static + Send + Sync {
pub type DynBackEp = Arc<dyn BackEp + 'static + Send + Sync>;

/// Backend endpoint receiver.
pub trait BackEpRecv: 'static + Send {
pub trait BackEpRecvCon: 'static + Send {
/// Receive incoming connection from this backend endpoint.
fn recv(&mut self) -> BoxFuture<'_, Option<DynBackWaitCon>>;
}

/// Trait-object version of backend endpoint receiver.
pub type DynBackEpRecv = Box<dyn BackEpRecv + 'static + Send>;
pub type DynBackEpRecvCon = Box<dyn BackEpRecvCon + 'static + Send>;
17 changes: 9 additions & 8 deletions crates/tx5/src/backend/go_pion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ impl BackCon for GoCon {
}
}

struct GoConRecv(tx5_connection::FramedConnRecv);
struct GoConRecvData(tx5_connection::FramedConnRecv);

impl BackConRecv for GoConRecv {
impl BackConRecvData for GoConRecvData {
fn recv(&mut self) -> BoxFuture<'_, Option<Vec<u8>>> {
Box::pin(async { self.0.recv().await })
}
Expand All @@ -41,7 +41,7 @@ impl BackWaitCon for GoWaitCon {
fn wait(
&mut self,
recv_limit: Arc<tokio::sync::Semaphore>,
) -> BoxFuture<'static, Result<(DynBackCon, DynBackConRecv)>> {
) -> BoxFuture<'static, Result<(DynBackCon, DynBackConRecvData)>> {
let con = self.con.take();
let con_recv = self.con_recv.take();
Box::pin(async move {
Expand All @@ -57,7 +57,8 @@ impl BackWaitCon for GoWaitCon {
.await?;

let con: DynBackCon = Arc::new(GoCon(con));
let con_recv: DynBackConRecv = Box::new(GoConRecv(con_recv));
let con_recv: DynBackConRecvData =
Box::new(GoConRecvData(con_recv));

Ok((con, con_recv))
})
Expand Down Expand Up @@ -92,9 +93,9 @@ impl BackEp for GoEp {
}
}

struct GoEpRecv(tx5_connection::HubRecv);
struct GoEpRecvCon(tx5_connection::HubRecv);

impl BackEpRecv for GoEpRecv {
impl BackEpRecvCon for GoEpRecvCon {
fn recv(&mut self) -> BoxFuture<'_, Option<DynBackWaitCon>> {
Box::pin(async {
let (con, con_recv) = self.0.accept().await?;
Expand All @@ -119,7 +120,7 @@ pub async fn connect(
config: &Arc<Config>,
url: &str,
listener: bool,
) -> Result<(DynBackEp, DynBackEpRecv)> {
) -> Result<(DynBackEp, DynBackEpRecvCon)> {
let webrtc_config = config.initial_webrtc_config.clone().into_bytes();
let sig_config = tx5_connection::tx5_signal::SignalConfig {
listener,
Expand All @@ -132,6 +133,6 @@ pub async fn connect(
tx5_connection::Hub::new(webrtc_config, url, Arc::new(sig_config))
.await?;
let ep: DynBackEp = Arc::new(GoEp(hub));
let ep_recv: DynBackEpRecv = Box::new(GoEpRecv(hub_recv));
let ep_recv: DynBackEpRecvCon = Box::new(GoEpRecvCon(hub_recv));
Ok((ep, ep_recv))
}
2 changes: 1 addition & 1 deletion crates/tx5/src/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn connect_loop(
sig_url: SigUrl,
listener: bool,
mut resp_url: Option<tokio::sync::oneshot::Sender<PeerUrl>>,
) -> (DynBackEp, DynBackEpRecv) {
) -> (DynBackEp, DynBackEpRecvCon) {
tracing::debug!(
target: "NETAUDIT",
?config,
Expand Down

0 comments on commit 885af26

Please sign in to comment.