aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSascha Grunert <mail@saschagrunert.de>2017-02-22 12:33:12 +0100
committerSascha Grunert <mail@saschagrunert.de>2017-02-22 12:33:12 +0100
commita6c890dae7f902e46e7b39f5733bd91cf407ca39 (patch)
tree5e3512d4481f487392994d1fe48409458d926a1e /src
parentAdded support for custom addresses (diff)
downloadwireguard-rs-a6c890dae7f902e46e7b39f5733bd91cf407ca39.tar.xz
wireguard-rs-a6c890dae7f902e46e7b39f5733bd91cf407ca39.zip
Added dummy support
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index af104d8..37a9075 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,11 +37,21 @@ pub struct WireGuard {
impl WireGuard {
/// Creates a new `WireGuard` instance
pub fn new(addr: &str) -> WgResult<Self> {
+ WireGuard::create(addr, false)
+ }
+
+ /// Create a new dummy `WireGuard` instance listening on "127.0.0.1:8080"
+ pub fn dummy() -> WgResult<Self> {
+ WireGuard::create("127.0.0.1:8080", true)
+ }
+
+ /// Internal `WireGuard` creation method
+ fn create(addr: &str, dummy: bool) -> WgResult<Self> {
// Create a new tokio core
let core = Core::new()?;
/// Create a tunnel instance
- let tunnel = WireGuardFuture::new(&core.handle(), addr)?;
+ let tunnel = WireGuardFuture::new(&core.handle(), addr, dummy)?;
/// Return the `WireGuard` instance
Ok(WireGuard {
@@ -83,9 +93,14 @@ pub struct WireGuardFuture {
impl WireGuardFuture {
/// Creates a new `WireGuardFuture`
- pub fn new(handle: &Handle, addr: &str) -> WgResult<Self> {
+ pub fn new(handle: &Handle, addr: &str, dummy: bool) -> WgResult<Self> {
// Create a tunneling device
- let device = Device::new("wg")?;
+ let device_name = "wg";
+ let device = if dummy {
+ Device::dummy(device_name)?
+ } else {
+ Device::new(device_name)?
+ };
// Create a server for the tunnel
let sock_addr = SocketAddr::from_str(addr)?;