simplyfy the generics usage in warp relay

This commit is contained in:
François Michel 2023-07-15 11:46:19 +00:00
parent 2427ea09af
commit a06d273e69
3 changed files with 11 additions and 25 deletions

View File

@ -1,5 +1,4 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time; use std::time;
@ -18,7 +17,7 @@ use crate::model::{broadcast, segment, track};
use crate::source::Source; use crate::source::Source;
// TODO experiment with making this Clone, so every task can have its own copy. // TODO experiment with making this Clone, so every task can have its own copy.
pub struct Session<R: RecvStream + Send, C: Connection + Send> { pub struct Session<C: Connection + Send> {
// Used to receive objects. // Used to receive objects.
objects: RecvObjects<C>, objects: RecvObjects<C>,
@ -36,10 +35,9 @@ pub struct Session<R: RecvStream + Send, C: Connection + Send> {
// Tasks we are currently serving. // Tasks we are currently serving.
run_segments: JoinSet<anyhow::Result<()>>, // receiving objects run_segments: JoinSet<anyhow::Result<()>>, // receiving objects
_marker: PhantomData<R>,
} }
impl<R: RecvStream + Send + 'static, C: Connection<RecvStream = R> + Send> Session<R, C> { impl<R: RecvStream + Send + 'static, C: Connection<RecvStream = R> + Send> Session<C> {
pub fn new( pub fn new(
objects: RecvObjects<C>, objects: RecvObjects<C>,
control: control::Component<control::Contribute>, control: control::Component<control::Contribute>,
@ -52,7 +50,6 @@ impl<R: RecvStream + Send + 'static, C: Connection<RecvStream = R> + Send> Sessi
broadcasts: HashMap::new(), broadcasts: HashMap::new(),
publishers: Publishers::new(), publishers: Publishers::new(),
run_segments: JoinSet::new(), run_segments: JoinSet::new(),
_marker: PhantomData,
} }
} }
@ -180,7 +177,7 @@ impl<R: RecvStream + Send + 'static, C: Connection<RecvStream = R> + Send> Sessi
} }
} }
impl<R: RecvStream + Send, C: Connection + Send> Drop for Session<R, C> { impl<C: Connection + Send> Drop for Session<C> {
fn drop(&mut self) { fn drop(&mut self) {
// Unannounce all broadcasts we have announced. // Unannounce all broadcasts we have announced.
// TODO make this automatic so we can't screw up? // TODO make this automatic so we can't screw up?

View File

@ -1,5 +1,3 @@
use std::marker::PhantomData;
use anyhow::Context; use anyhow::Context;
use bytes::Buf; use bytes::Buf;
@ -11,7 +9,7 @@ use moq_transport::{Announce, AnnounceError, AnnounceOk, Object, Subscribe, Subs
use super::{broker, control}; use super::{broker, control};
use crate::model::{segment, track}; use crate::model::{segment, track};
pub struct Session<S: SendStream + Send, C: Connection + Send> { pub struct Session<C: Connection + Send> {
// Objects are sent to the client // Objects are sent to the client
objects: SendObjects<C>, objects: SendObjects<C>,
@ -23,11 +21,9 @@ pub struct Session<S: SendStream + Send, C: Connection + Send> {
// A list of tasks that are currently running. // A list of tasks that are currently running.
run_subscribes: JoinSet<SubscribeError>, // run subscriptions, sending the returned error if they fail run_subscribes: JoinSet<SubscribeError>, // run subscriptions, sending the returned error if they fail
_marker: PhantomData<S>,
} }
impl<S, C> Session<S, C> where impl<S, C> Session<C> where
S: SendStream + Send, S: SendStream + Send,
C: Connection<SendStream = S> + Send + 'static { C: Connection<SendStream = S> + Send + 'static {
pub fn new( pub fn new(
@ -40,7 +36,6 @@ impl<S, C> Session<S, C> where
control, control,
broker, broker,
run_subscribes: JoinSet::new(), run_subscribes: JoinSet::new(),
_marker: PhantomData,
} }
} }

View File

@ -1,22 +1,18 @@
use std::marker::PhantomData;
use webtransport_generic::{SendStream, Connection, RecvStream}; use webtransport_generic::{SendStream, Connection, RecvStream};
use super::{broker, contribute, control, distribute}; use super::{broker, contribute, control, distribute};
pub struct Session<R: RecvStream + Send, S: SendStream + Send, C: Connection + Send> { pub struct Session<C: Connection + Send> {
// Split logic into contribution/distribution to reduce the problem space. // Split logic into contribution/distribution to reduce the problem space.
contribute: contribute::Session<R, C>, contribute: contribute::Session<C>,
distribute: distribute::Session<S, C>, distribute: distribute::Session<C>,
// Used to receive control messages and forward to contribute/distribute. // Used to receive control messages and forward to contribute/distribute.
control: control::Main<S, R>, control: control::Main<C::SendStream, C::RecvStream>,
_marker: PhantomData<S>,
_marker_r: PhantomData<R>,
} }
impl<R, S, C> Session<R, S, C> where impl<R, S, C> Session<C> where
R: RecvStream + Send + 'static, R: RecvStream + Send + 'static,
S: SendStream + Send, S: SendStream + Send,
C: Connection<RecvStream = R, SendStream = S> + Send + 'static C: Connection<RecvStream = R, SendStream = S> + Send + 'static
@ -24,7 +20,7 @@ impl<R, S, C> Session<R, S, C> where
pub async fn from_transport_session( pub async fn from_transport_session(
session: moq_transport::Session<C>, session: moq_transport::Session<C>,
broker: broker::Broadcasts, broker: broker::Broadcasts,
) -> anyhow::Result<Session<R, S, C>> { ) -> anyhow::Result<Session<C>> {
let (control, objects) = session.split(); let (control, objects) = session.split();
let (objects_send, objects_recv) = objects.split(); let (objects_send, objects_recv) = objects.split();
@ -37,8 +33,6 @@ impl<R, S, C> Session<R, S, C> where
control, control,
contribute, contribute,
distribute, distribute,
_marker: PhantomData,
_marker_r: PhantomData,
}; };
Ok(session) Ok(session)