@@ -14,7 +14,6 @@ use std::borrow::Cow;
14
14
use std:: env;
15
15
use std:: {
16
16
convert:: Infallible ,
17
- io,
18
17
net:: IpAddr ,
19
18
path:: Path ,
20
19
pin:: Pin ,
@@ -68,33 +67,6 @@ type EventCallback = Box<dyn (Fn(TunnelEvent) -> BoxFuture<'static, ()>) + Send
68
67
#[ derive( err_derive:: Error , Debug ) ]
69
68
#[ error( no_from) ]
70
69
pub enum Error {
71
- /// Failed to set up routing.
72
- #[ error( display = "Failed to setup routing" ) ]
73
- SetupRoutingError ( #[ error( source) ] talpid_routing:: Error ) ,
74
-
75
- /// Failed to set MTU
76
- #[ error( display = "Failed to detect MTU because every ping was dropped." ) ]
77
- MtuDetectionAllDropped ,
78
-
79
- /// Failed to set MTU
80
- #[ error( display = "Failed to detect MTU because of unexpected ping error." ) ]
81
- MtuDetectionPingError ( #[ error( source) ] surge_ping:: SurgeError ) ,
82
-
83
- /// Failed to set MTU
84
- #[ error(
85
- display = "Failed to detect MTU because of an IO error when setting up the ping socket."
86
- ) ]
87
- MtuDetectionSetupSocket ( #[ error( source) ] io:: Error ) ,
88
-
89
- /// Failed to set MTU
90
- #[ cfg( target_os = "macos" ) ]
91
- #[ error( display = "Failed to set buffer size" ) ]
92
- MtuSetBufferSize ( #[ error( source) ] nix:: Error ) ,
93
-
94
- /// Failed to set MTU on the active tunnel
95
- #[ error( display = "Failed to set MTU on the active tunnel" ) ]
96
- SetMtu ( #[ error( source) ] io:: Error ) ,
97
-
98
70
/// Tunnel timed out
99
71
#[ error( display = "Tunnel timed out" ) ]
100
72
TimeoutError ,
@@ -103,6 +75,10 @@ pub enum Error {
103
75
#[ error( display = "Tunnel failed" ) ]
104
76
TunnelError ( #[ error( source) ] TunnelError ) ,
105
77
78
+ /// Failed to set up routing.
79
+ #[ error( display = "Failed to setup routing" ) ]
80
+ SetupRoutingError ( #[ error( source) ] talpid_routing:: Error ) ,
81
+
106
82
/// Failed to create tunnel obfuscator
107
83
#[ error( display = "Failed to create tunnel obfuscator" ) ]
108
84
CreateObfuscatorError ( #[ error( source) ] ObfuscationError ) ,
@@ -994,15 +970,39 @@ impl WireguardMonitor {
994
970
995
971
#[ cfg( not( target_os = "android" ) ) ]
996
972
mod mtu_detection {
997
- use std:: { net:: IpAddr , time:: Duration } ;
973
+ use std:: { io , net:: IpAddr , time:: Duration } ;
998
974
999
975
use futures:: { future, stream:: FuturesUnordered , TryStreamExt } ;
1000
976
use surge_ping:: { Client , Config , PingIdentifier , PingSequence , SurgeError } ;
1001
977
use talpid_tunnel:: { ICMP_HEADER_SIZE , IPV4_HEADER_SIZE , MIN_IPV4_MTU } ;
1002
978
use tokio_stream:: StreamExt ;
1003
979
1004
- use super :: Error ;
980
+ #[ derive( err_derive:: Error , Debug ) ]
981
+ #[ error( no_from) ]
982
+ pub enum Error {
983
+ /// Failed to set MTU on the active tunnel
984
+ #[ error( display = "Failed to set MTU on the active tunnel" ) ]
985
+ SetMtu ( #[ error( source) ] io:: Error ) ,
986
+
987
+ /// Failed to set MTU
988
+ #[ error( display = "Failed to detect MTU because every ping was dropped." ) ]
989
+ MtuDetectionAllDropped ,
1005
990
991
+ /// Failed to set MTU
992
+ #[ error( display = "Failed to detect MTU because of unexpected ping error." ) ]
993
+ MtuDetectionPing ( #[ error( source) ] surge_ping:: SurgeError ) ,
994
+
995
+ /// Failed to set MTU
996
+ #[ error(
997
+ display = "Failed to detect MTU because of an IO error when setting up the ping socket."
998
+ ) ]
999
+ MtuDetectionSetupSocket ( #[ error( source) ] io:: Error ) ,
1000
+
1001
+ /// Failed to set MTU
1002
+ #[ cfg( target_os = "macos" ) ]
1003
+ #[ error( display = "Failed to set buffer size" ) ]
1004
+ MtuSetBufferSize ( #[ error( source) ] nix:: Error ) ,
1005
+ }
1006
1006
/// Verify that the current MTU doesn't cause dropped packets, otherwise lower it to the
1007
1007
/// largest value which doesn't.
1008
1008
///
@@ -1117,15 +1117,15 @@ mod mtu_detection {
1117
1117
// If the first ping we get back timed out, then all of them did
1118
1118
SurgeError :: Timeout { .. } => Error :: MtuDetectionAllDropped ,
1119
1119
// Unexpected error type
1120
- e => Error :: MtuDetectionPingError ( e) ,
1120
+ e => Error :: MtuDetectionPing ( e) ,
1121
1121
} ) ?;
1122
1122
1123
1123
ping_stream
1124
1124
. timeout ( PING_OFFSET_TIMEOUT ) // Start a new, shorter, timeout
1125
1125
. map_while ( |res| res. ok ( ) ) // Stop waiting for pings after this timeout
1126
1126
. try_fold ( first_ping_size, |acc, mtu| future:: ready ( Ok ( acc. max ( mtu) ) ) ) // Get largest ping
1127
1127
. await
1128
- . map_err ( Error :: MtuDetectionPingError )
1128
+ . map_err ( Error :: MtuDetectionPing )
1129
1129
}
1130
1130
1131
1131
/// Creates a linear spacing of MTU values with the given step size. Always includes the given
0 commit comments