Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement congestion controller trait over enum #2092

Open
camshaft opened this issue Jan 11, 2024 · 0 comments
Open

Implement congestion controller trait over enum #2092

camshaft opened this issue Jan 11, 2024 · 0 comments

Comments

@camshaft
Copy link
Contributor

camshaft commented Jan 11, 2024

#2078

Problem:

Due to the endpoint builder preferring completely static types, it makes it difficult to swap implementations of providers based on config:

let builder = if use_bbr {
    build.with_congestion_controller(congestion_controller::Bbr::default())?
} else {
    build.with_congestion_controller(congestion_controller::Cubic::default())?
};

Solution:

To make this pattern easier, we can provide an enum impl that is implemented generically for two different CCAs and dispatches at runtime:

enum Either<A, B> {
    Left(A),
    Right(B),
}

impl<A, B> CongestionController for Either<A, B>
where
    A: CongestionController,
    B: CongestionController,
{
    type PacketInfo = Either<A::PacketInfo, B::PacketInfo>;

    #[inline]
    fn congestion_window(&self) -> u32 {
        match self {
            Self::Left(cca) => cca.congestion_window(),
            Self::Right(cca) => cca.congestion_window(),
        }
    }

    ...
}

The application would then be able to switch at runtime:

let builder = if use_bbr {
    build.with_congestion_controller(Either::Left(congestion_controller::Bbr::default()))?
} else {
    build.with_congestion_controller(Either::Right(congestion_controller::Cubic::default()))?
};

It might make sense to use the either crate, or just define our own in s2n-quic-core to avoid the dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants