-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathmod.rs
51 lines (40 loc) · 1.28 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::{io, net::SocketAddr};
use tokio::task::JoinHandle;
use tunnel_obfuscation::{create_obfuscator, udp2tcp::Settings, Settings as ObfuscationSettings};
mod ffi;
use crate::mullvad_ios_runtime;
pub struct TunnelObfuscatorRuntime {
settings: ObfuscationSettings,
}
impl TunnelObfuscatorRuntime {
pub fn new(peer: SocketAddr) -> io::Result<Self> {
let settings = ObfuscationSettings::Udp2Tcp(Settings { peer });
Ok(Self { settings })
}
pub fn run(self) -> io::Result<(SocketAddr, TunnelObfuscatorHandle)> {
let runtime = mullvad_ios_runtime().map_err(io::Error::other)?;
let obfuscator = runtime.block_on(async move {
create_obfuscator(&self.settings)
.await
.map_err(io::Error::other)
})?;
let endpoint = obfuscator.endpoint();
let join_handle = runtime.spawn(async move {
let _ = obfuscator.run().await;
});
Ok((
endpoint,
TunnelObfuscatorHandle {
obfuscator_abort_handle: join_handle,
},
))
}
}
pub struct TunnelObfuscatorHandle {
obfuscator_abort_handle: JoinHandle<()>,
}
impl TunnelObfuscatorHandle {
pub fn stop(self) {
self.obfuscator_abort_handle.abort();
}
}