Skip to content

Commit

Permalink
feat: rtp
Browse files Browse the repository at this point in the history
  • Loading branch information
Banyc committed Apr 23, 2024
1 parent 5fdc56b commit 9f463e4
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 40 deletions.
98 changes: 68 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ once_cell = "1"
pin-project-lite = "0.2"
rand = "0.8"
regex = "1"
rtp = { git = "https://github.com/Banyc/rtp.git", tag = "v0.0.4" }
scopeguard = "1"
serde = "1"
serde_json = "1"
Expand All @@ -59,7 +60,7 @@ tokio_throughput = { git = "https://github.com/Banyc/tokio_throughput.git", rev
toml = "0.8"
tracing = "0.1"
tracing-subscriber = "0.3"
udp_listener = { git = "https://github.com/Banyc/udp_listener.git", tag = "v0.0.6" }
udp_listener = { git = "https://github.com/Banyc/udp_listener.git", tag = "v0.0.7" }

[profile.profiling]
inherits = "release"
Expand Down
1 change: 1 addition & 0 deletions protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ metrics = { workspace = true }
mptcp = { workspace = true }
once_cell = { workspace = true }
rand = { workspace = true }
rtp = { workspace = true }
serde = { workspace = true }
swap = { workspace = true }
thiserror = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions protocol/src/stream/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum ConcreteStreamType {
Tcp,
Kcp,
Mptcp,
Rtp,
}
impl StreamType for ConcreteStreamType {}
impl fmt::Display for ConcreteStreamType {
Expand All @@ -24,6 +25,7 @@ impl fmt::Display for ConcreteStreamType {
ConcreteStreamType::Tcp => write!(f, "tcp"),
ConcreteStreamType::Kcp => write!(f, "kcp"),
ConcreteStreamType::Mptcp => write!(f, "mptcp"),
ConcreteStreamType::Rtp => write!(f, "rtp"),
}
}
}
Expand All @@ -35,6 +37,7 @@ impl FromStr for ConcreteStreamType {
"tcp" => Ok(Self::Tcp),
"kcp" => Ok(Self::Kcp),
"mptcp" => Ok(Self::Mptcp),
"rtp" => Ok(Self::Rtp),
_ => Err(ParseInternetAddrError),
}
}
Expand Down
6 changes: 5 additions & 1 deletion protocol/src/stream/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use common::stream::connect::{StreamConnect, StreamConnectExt, StreamConnectorTa
use super::{
addr::ConcreteStreamType,
connection::Connection,
streams::{kcp::KcpConnector, mptcp::MptcpConnector, tcp::TcpConnector},
streams::{kcp::KcpConnector, mptcp::MptcpConnector, rtp::RtpConnector, tcp::TcpConnector},
};

#[derive(Debug, Clone)]
pub struct ConcreteStreamConnectorTable {
tcp: TcpConnector,
kcp: KcpConnector,
mptcp: MptcpConnector,
rtp: RtpConnector,
}

impl ConcreteStreamConnectorTable {
Expand All @@ -21,6 +22,7 @@ impl ConcreteStreamConnectorTable {
tcp: TcpConnector,
kcp: KcpConnector,
mptcp: MptcpConnector,
rtp: RtpConnector,
}
}
}
Expand All @@ -38,6 +40,7 @@ impl StreamConnectorTable for ConcreteStreamConnectorTable {
ConcreteStreamType::Tcp => self.tcp.connect(addr).await,
ConcreteStreamType::Kcp => self.kcp.connect(addr).await,
ConcreteStreamType::Mptcp => self.mptcp.connect(addr).await,
ConcreteStreamType::Rtp => self.rtp.connect(addr).await,
}
}

Expand All @@ -51,6 +54,7 @@ impl StreamConnectorTable for ConcreteStreamConnectorTable {
ConcreteStreamType::Tcp => self.tcp.timed_connect(addr, timeout).await,
ConcreteStreamType::Kcp => self.kcp.timed_connect(addr, timeout).await,
ConcreteStreamType::Mptcp => self.mptcp.timed_connect(addr, timeout).await,
ConcreteStreamType::Rtp => self.rtp.timed_connect(addr, timeout).await,
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion protocol/src/stream/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use common::stream::{IoAddr, IoStream};

use super::{
addr::ConcreteStreamAddr,
streams::{kcp::AddressedKcpStream, mptcp::IoMptcpStream, tcp::IoTcpStream},
streams::{
kcp::AddressedKcpStream, mptcp::IoMptcpStream, rtp::AddressedRtpStream, tcp::IoTcpStream,
},
};

#[derive(Debug)]
Expand All @@ -15,6 +17,7 @@ pub enum Connection {
Tcp(IoTcpStream),
Kcp(AddressedKcpStream),
Mptcp(IoMptcpStream),
Rtp(AddressedRtpStream),
}

impl IoStream for Connection {}
Expand All @@ -25,6 +28,7 @@ impl IoAddr for Connection {
Connection::Tcp(x) => x.peer_addr(),
Connection::Kcp(x) => x.peer_addr(),
Connection::Mptcp(x) => IoAddr::peer_addr(x),
Connection::Rtp(x) => IoAddr::peer_addr(x),
}
}

Expand All @@ -34,6 +38,7 @@ impl IoAddr for Connection {
Connection::Tcp(x) => x.local_addr(),
Connection::Kcp(x) => x.local_addr(),
Connection::Mptcp(x) => IoAddr::local_addr(x),
Connection::Rtp(x) => IoAddr::local_addr(x),
}
}
}
Expand All @@ -49,6 +54,7 @@ impl AsyncWrite for Connection {
Connection::Tcp(x) => Pin::new(x).poll_write(cx, buf),
Connection::Kcp(x) => Pin::new(x).poll_write(cx, buf),
Connection::Mptcp(x) => Pin::new(x).poll_write(cx, buf),
Connection::Rtp(x) => Pin::new(x).poll_write(cx, buf),
}
}

Expand All @@ -61,6 +67,7 @@ impl AsyncWrite for Connection {
Connection::Tcp(x) => Pin::new(x).poll_flush(cx),
Connection::Kcp(x) => Pin::new(x).poll_flush(cx),
Connection::Mptcp(x) => Pin::new(x).poll_flush(cx),
Connection::Rtp(x) => Pin::new(x).poll_flush(cx),
}
}

Expand All @@ -73,6 +80,7 @@ impl AsyncWrite for Connection {
Connection::Tcp(x) => Pin::new(x).poll_shutdown(cx),
Connection::Kcp(x) => Pin::new(x).poll_shutdown(cx),
Connection::Mptcp(x) => Pin::new(x).poll_shutdown(cx),
Connection::Rtp(x) => Pin::new(x).poll_shutdown(cx),
}
}
}
Expand All @@ -88,6 +96,7 @@ impl AsyncRead for Connection {
Connection::Tcp(x) => Pin::new(x).poll_read(cx, buf),
Connection::Kcp(x) => Pin::new(x).poll_read(cx, buf),
Connection::Mptcp(x) => Pin::new(x).poll_read(cx, buf),
Connection::Rtp(x) => Pin::new(x).poll_read(cx, buf),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions protocol/src/stream/streams/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod kcp;
// pub mod quic;
pub mod mptcp;
pub mod rtp;
pub mod tcp;
Loading

0 comments on commit 9f463e4

Please sign in to comment.