Skip to content

Commit

Permalink
add mtu to device trait
Browse files Browse the repository at this point in the history
  • Loading branch information
lazytiger committed Feb 18, 2024
1 parent f439243 commit bddc2d6
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 170 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ringbuf = "0.3"
httparse = "1.8"
async_smoltcp = { path = "async_smoltcp" }
tokio-rustls = "0.25"
rustls-pki-types = "1.1"
rustls-pki-types = "1.2"
futures = "0.3"

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion async_smoltcp/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ fn is_private_v4(addr: IpAddress) -> bool {
}

impl<'a, T: Tun + Clone> TunDevice<'a, T> {
pub fn new(mtu: usize, tun: T) -> Self {
pub fn new(tun: T) -> Self {
let channel_buffer = 1024;
let mtu = tun.mtu();
let (tcp_sender, tcp_receiver) = channel(channel_buffer);
let (udp_sender, udp_receiver) = channel(channel_buffer);
let mut device = Self {
Expand Down
6 changes: 6 additions & 0 deletions async_smoltcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub trait Tun {

/// Allocate a packet which can hold len bytes data.
fn allocate_packet(&self, len: usize) -> std::io::Result<Self::Packet>;

/// Get the MTU of the tun device.
fn mtu(&self) -> usize;
}

impl<T> Tun for Arc<T>
Expand All @@ -41,6 +44,9 @@ where
fn allocate_packet(&self, len: usize) -> std::io::Result<Self::Packet> {
self.deref().allocate_packet(len)
}
fn mtu(&self) -> usize {
self.deref().mtu()
}
}

pub trait Packet {
Expand Down
69 changes: 7 additions & 62 deletions mobile2/backend/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 mobile2/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ serde_json = "1.0"
serde = "1.0"
lazy_static = "1.4"
derive_more = "0.99"
smoltcp = "0.10"
smoltcp = "0.11.0"
rustls = { version = "0.22", features = [] }
rustls-pki-types = "1.2"
itertools = "0.12.0"
bytes = "1.5"
crossbeam = "0.8"
Expand Down
1 change: 0 additions & 1 deletion mobile2/backend/gen/android/.idea/vcs.xml

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

Loading

0 comments on commit bddc2d6

Please sign in to comment.