Skip to content

Commit 20e80c0

Browse files
committed
Add sized ping
1 parent 6614096 commit 20e80c0

File tree

8 files changed

+152
-89
lines changed

8 files changed

+152
-89
lines changed

test/Cargo.lock

+71-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Cargo.toml

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ rust-version = "1.75.0"
77

88
[workspace]
99
resolver = "2"
10-
members = [
11-
"test-manager",
12-
"test-runner",
13-
"test-rpc",
14-
"socks-server",
15-
]
10+
members = ["test-manager", "test-runner", "test-rpc", "socks-server"]
1611

1712
[workspace.lints.rust]
1813
rust_2018_idioms = "deny"
@@ -22,7 +17,15 @@ unused_async = "deny"
2217

2318
[workspace.dependencies]
2419
futures = "0.3"
25-
tokio = { version = "1.8", features = ["macros", "rt", "process", "time", "fs", "io-util", "rt-multi-thread"] }
20+
tokio = { version = "1.8", features = [
21+
"macros",
22+
"rt",
23+
"process",
24+
"time",
25+
"fs",
26+
"io-util",
27+
"rt-multi-thread",
28+
] }
2629
tokio-serial = "5.4.1"
2730
# Serde and related crates
2831
serde = "1.0"
@@ -46,8 +49,9 @@ shadowsocks-service = { version = "1.16" }
4649

4750
windows-sys = "0.48.0"
4851

49-
chrono = { version = "0.4.26", default-features = false}
52+
chrono = { version = "0.4.26", default-features = false }
5053
clap = { version = "4.2.7", features = ["cargo", "derive"] }
5154
once_cell = "1.16.0"
5255
bytes = "1.3.0"
5356
async-trait = "0.1.58"
57+
surge-ping = "0.8"

test/test-manager/src/tests/helpers.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,23 @@ pub async fn ping_with_timeout(
181181
dest: IpAddr,
182182
interface: Option<String>,
183183
) -> Result<(), Error> {
184-
timeout(PING_TIMEOUT, rpc.send_ping(interface, dest))
184+
const DEFAULT_PING_SIZE: usize = 64;
185+
timeout(
186+
PING_TIMEOUT,
187+
rpc.send_ping(dest, interface, DEFAULT_PING_SIZE),
188+
)
189+
.await
190+
.map_err(|_| Error::PingTimeout)?
191+
.map_err(Error::Rpc)
192+
}
193+
194+
pub async fn ping_sized_with_timeout(
195+
rpc: &ServiceClient,
196+
dest: IpAddr,
197+
interface: Option<String>,
198+
size: usize,
199+
) -> Result<(), Error> {
200+
timeout(PING_TIMEOUT, rpc.send_ping(dest, interface, size))
185201
.await
186202
.map_err(|_| Error::PingTimeout)?
187203
.map_err(Error::Rpc)

test/test-rpc/src/client.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ impl ServiceClient {
178178
/// Send ICMP
179179
pub async fn send_ping(
180180
&self,
181-
interface: Option<String>,
182181
destination: IpAddr,
182+
interface: Option<String>,
183+
size: usize,
183184
) -> Result<(), Error> {
184185
self.client
185-
.send_ping(tarpc::context::current(), interface, destination)
186+
.send_ping(tarpc::context::current(), destination, interface, size)
186187
.await?
187188
}
188189

test/test-rpc/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub enum Error {
3838
#[error(display = "Failed to send TCP segment")]
3939
SendTcp,
4040
#[error(display = "Failed to send ping")]
41-
Ping,
41+
Ping(String),
4242
#[error(display = "Failed to get or set registry value")]
4343
Registry(String),
4444
#[error(display = "Failed to change the service")]
@@ -136,7 +136,11 @@ mod service {
136136
) -> Result<(), Error>;
137137

138138
/// Send ICMP
139-
async fn send_ping(interface: Option<String>, destination: IpAddr) -> Result<(), Error>;
139+
async fn send_ping(
140+
destination: IpAddr,
141+
interface: Option<String>,
142+
size: usize,
143+
) -> Result<(), Error>;
140144

141145
/// Fetch the current location.
142146
async fn geoip_lookup(mullvad_host: String) -> Result<AmIMullvad, Error>;
@@ -175,7 +179,8 @@ mod service {
175179
verbosity_level: mullvad_daemon::Verbosity,
176180
) -> Result<(), Error>;
177181

178-
/// Set environment variables for the daemon service. This will restart the daemon system service.
182+
/// Set environment variables for the daemon service. This will restart the daemon system
183+
/// service.
179184
async fn set_daemon_environment(env: HashMap<String, String>) -> Result<(), Error>;
180185

181186
/// Copy a file from `src` to `dest` on the test runner.

test/test-runner/Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ bytes = { workspace = true }
2323
serde = { workspace = true }
2424
serde_json = { workspace = true }
2525
tokio-serde = { workspace = true }
26+
surge-ping = { workspace = true }
27+
rand = "0.8"
2628

2729
libc = "0.2"
2830
chrono = { workspace = true, features = ["serde"] }
@@ -42,12 +44,12 @@ winreg = "0.50"
4244
[target.'cfg(windows)'.dependencies.windows-sys]
4345
version = "0.45.0"
4446
features = [
45-
"Win32_Foundation",
46-
"Win32_Security",
47-
"Win32_System_Shutdown",
48-
"Win32_System_SystemServices",
49-
"Win32_System_Threading",
50-
"Win32_UI_WindowsAndMessaging",
47+
"Win32_Foundation",
48+
"Win32_Security",
49+
"Win32_System_Shutdown",
50+
"Win32_System_SystemServices",
51+
"Win32_System_Threading",
52+
"Win32_UI_WindowsAndMessaging",
5153
]
5254

5355
[dependencies.tokio-util]

test/test-runner/src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ use std::{
66
path::{Path, PathBuf},
77
};
88

9-
use tarpc::context;
10-
use tarpc::server::Channel;
9+
use tarpc::{context, server::Channel};
1110
use test_rpc::{
1211
mullvad_daemon::{ServiceStatus, SOCKET_PATH},
1312
net::SockHandleId,
1413
package::Package,
1514
transport::GrpcForwarder,
1615
AppTrace, Service,
1716
};
18-
use tokio::sync::broadcast::error::TryRecvError;
1917
use tokio::{
2018
io::{AsyncReadExt, AsyncWriteExt},
2119
process::Command,
20+
sync::broadcast::error::TryRecvError,
2221
};
2322
use tokio_util::codec::{Decoder, LengthDelimitedCodec};
2423

@@ -141,10 +140,13 @@ impl Service for TestServer {
141140
async fn send_ping(
142141
self,
143142
_: context::Context,
144-
interface: Option<String>,
145143
destination: IpAddr,
144+
interface: Option<String>,
145+
size: usize,
146146
) -> Result<(), test_rpc::Error> {
147-
net::send_ping(interface.as_deref(), destination).await
147+
net::send_ping(destination, interface.as_deref(), size)
148+
.await
149+
.map_err(|e| test_rpc::Error::Ping(e.to_string()))
148150
}
149151

150152
async fn geoip_lookup(

0 commit comments

Comments
 (0)