From 027ee6870b515525ba8ba28c025d2a517b154671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Tue, 3 Oct 2023 15:18:14 +0200 Subject: [PATCH 1/5] update server example --- examples/server.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/server.rs b/examples/server.rs index e599d8a..c2a2cc9 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -13,8 +13,13 @@ fn main() -> Result<(), Box> { "utun3".into() }; let wgapi = WGApi::new(ifname.clone(), false)?; + + // create interface + wgapi.create_interface()?; + + // read current interface data let host = wgapi.read_interface_data()?; - log::debug!("{host:#?}"); + println!("WireGuard interface: {host:#?}"); // host let secret = EphemeralSecret::random(); @@ -44,5 +49,11 @@ fn main() -> Result<(), Box> { wgapi.remove_peer(&peer.public_key)?; } + // read current interface data + let host = wgapi.read_interface_data()?; + println!("WireGuard interface: {host:#?}"); + + wgapi.remove_interface()?; + Ok(()) } From d01907be98e5c155a36a764f0a77d44ea49cbd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Tue, 3 Oct 2023 15:22:40 +0200 Subject: [PATCH 2/5] update examples --- examples/client.rs | 7 +++++-- examples/server.rs | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index a6cf5bd..b1c2943 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -14,6 +14,9 @@ fn main() -> Result<(), Box> { }; let wgapi = WGApi::new(ifname.clone(), false)?; + // create interface + wgapi.create_interface()?; + // Peer configuration let secret = EphemeralSecret::random(); let key = PublicKey::from(&secret); @@ -22,8 +25,8 @@ fn main() -> Result<(), Box> { let mut peer = Peer::new(peer_key.clone()); log::info!("endpoint"); - // Your wireguard server endpoint which peer connects too - let endpoint: SocketAddr = ":".parse().unwrap(); + // Your wireguard server endpoint which client connects too + let endpoint: SocketAddr = "10.10.10.10:55001".parse().unwrap(); // Peer endpoint and interval peer.endpoint = Some(endpoint); peer.persistent_keepalive_interval = Some(25); diff --git a/examples/server.rs b/examples/server.rs index c2a2cc9..2c99327 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -21,7 +21,7 @@ fn main() -> Result<(), Box> { let host = wgapi.read_interface_data()?; println!("WireGuard interface: {host:#?}"); - // host + // prepare peer configuration let secret = EphemeralSecret::random(); let key = PublicKey::from(&secret); let peer_key: Key = key.as_ref().try_into().unwrap(); @@ -29,7 +29,7 @@ fn main() -> Result<(), Box> { let addr = IpAddrMask::from_str("10.20.30.40/24").unwrap(); peer.allowed_ips.push(addr); - // Create host interfaces + // Configure host interface let interface_config = InterfaceConfiguration { name: ifname.clone(), prvkey: "AAECAwQFBgcICQoLDA0OD/Dh0sO0pZaHeGlaSzwtHg8=".to_string(), @@ -37,7 +37,6 @@ fn main() -> Result<(), Box> { port: 12345, peers: vec![peer], }; - wgapi.configure_interface(&interface_config)?; // Create peers @@ -53,6 +52,7 @@ fn main() -> Result<(), Box> { let host = wgapi.read_interface_data()?; println!("WireGuard interface: {host:#?}"); + // remove interface wgapi.remove_interface()?; Ok(()) From ea881120a91bc3536a4a04b1d37bbb07b218b51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Tue, 3 Oct 2023 15:23:04 +0200 Subject: [PATCH 3/5] bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5da0d38..6fa9c26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "defguard_wireguard_rs" -version = "0.2.0" +version = "0.2.1" dependencies = [ "base64", "log", diff --git a/Cargo.toml b/Cargo.toml index 8b5ecea..7658653 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "defguard_wireguard_rs" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "A unified multi-platform high-level API for managing WireGuard interfaces" license = "Apache-2.0" From 23bf4cc533af8a3946c447ad6eb291324ed685b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Tue, 3 Oct 2023 15:25:57 +0200 Subject: [PATCH 4/5] update userspace example --- examples/userspace.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/userspace.rs b/examples/userspace.rs index 5844c7a..9c5d6b3 100644 --- a/examples/userspace.rs +++ b/examples/userspace.rs @@ -25,6 +25,9 @@ fn main() -> Result<(), Box> { }; let api = WireguardApiUserspace::new(ifname.clone())?; + // create interface + api.create_interface()?; + // Peer configuration let secret = EphemeralSecret::random(); let key = PublicKey::from(&secret); From 5c9ccae746eba2fde4e75b120c9a7037ab20ceb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20W=C3=B3jcik?= Date: Tue, 3 Oct 2023 15:27:24 +0200 Subject: [PATCH 5/5] update runner selectors --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8fff26..13772d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ env: jobs: test: - runs-on: self-hosted + runs-on: [self-hosted, Linux] container: rust:1.72 steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 10f00ef..f9e2fb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: jobs: create-release: - runs-on: self-hosted + runs-on: [self-hosted, Linux] steps: - name: Checkout uses: actions/checkout@v3