Skip to content

Commit

Permalink
Merge pull request #7 from b-m-f/fix-persistent-keepalive
Browse files Browse the repository at this point in the history
Fix persistent keepalive
  • Loading branch information
b-m-f authored Mar 2, 2023
2 parents 511e962 + cbfa93a commit 83d71cc
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ All configs will be inside an output directory called `CONFIG_FILE`.
In order to keep the Keys and IPs the same over consecutive executions make sure that the `CONFIG_FILE.toml` and output directory stay together.

# Config file
```
[global]
cidr = "10.0.0.0/24"
[servers]
[servers.gateway]
endpoint = "mydomain.tld"
ip = "10.0.0.1"
port = 22222
persistent_keepalive = 25
[clients]
[clients.laptop]
dns = "10.0.0.1"
[clients.phone]
dns = "10.0.0.1"
```

## [global]
|What|Type|Description|Required|
Expand Down
3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
mod wired;

use std::fs::create_dir_all;

use clap::Parser;


#[derive(Parser, Debug)]
#[command(name = "wired")]
#[command(author = "b-m-f <[email protected]>")]
Expand Down
2 changes: 1 addition & 1 deletion src/wired/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ClientConfig {
Some(ka) => {
peers = format!(
"{}\n\
PersistentKeepalive= {}",
PersistentKeepalive = {}",
peers, ka,
)
}
Expand Down
23 changes: 23 additions & 0 deletions tests/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ client_configs=( "desktop.conf" "laptop.conf" "phone.conf" "server2.conf" "serve
# Expect the configs not to change between runs
[ "$result_first_run" = "$result_second_run" ]
done
run cat configs/test-basic/gateway.conf

assert_line --regexp 'Address = 10.0.0.1'
assert_line --regexp 'PrivateKey =.*'
assert_line --regexp 'DNS = 1.1.1.1'
assert_line --regexp 'ListenPort = 10101'

run cat configs/test-basic/laptop.conf

assert_line --regexp 'DNS = 10.0.0.1'

for file in "${client_configs[@]}"
do
run cat configs/test-basic/$file

assert_line --regexp 'Address = .*'
assert_line --regexp 'PrivateKey =.*'
assert_line --regexp 'PersistentKeepalive = 25'
assert_line --regexp 'PublicKey = .*'
assert_line --regexp 'AllowedIPs = 10.0.0.1'
assert_line --regexp 'Endpoint = test.test:10101'

done
}

@test "IPs are changed correctly" {
Expand Down
4 changes: 2 additions & 2 deletions tests/configs/test-basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ cidr = "10.0.0.0/24"
endpoint = "test.test"
ip = "10.0.0.1"
port = 10101
dns = "1.1.1.1"
persistent_keepalive = 25

[clients]
[clients.laptop]
dns = "10.0.0.1"
[clients.desktop]
dns = "10.0.0.1"
[clients.phone]
qr = true
dns = "10.0.0.1"
[clients.server2]
[clients.server]
2 changes: 0 additions & 2 deletions tests/configs/test-rotate-ips-reorder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ port = 10101
[clients]
[clients.server]
[clients.desktop]
dns = "10.0.0.1"
[clients.server2]
[clients.laptop]
dns = "10.0.0.1"
[clients.phone]
qr = true
dns = "10.0.0.1"
2 changes: 0 additions & 2 deletions tests/configs/test-rotate-ips.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ port = 10101
[clients.laptop]
dns = "10.0.0.1"
[clients.desktop]
dns = "10.0.0.1"
[clients.phone]
qr = true
dns = "10.0.0.1"
[clients.server2]
[clients.server]
2 changes: 0 additions & 2 deletions tests/configs/test-rotate-keys-and-ips-reorder.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ port = 10101
[clients]
[clients.server]
[clients.desktop]
dns = "10.0.0.1"
[clients.server2]
[clients.phone]
qr = true
dns = "10.0.0.1"
[clients.laptop]
dns = "10.0.0.1"
2 changes: 0 additions & 2 deletions tests/configs/test-rotate-keys-and-ips.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ port = 10101
[clients.laptop]
dns = "10.0.0.1"
[clients.desktop]
dns = "10.0.0.1"
[clients.phone]
qr = true
dns = "10.0.0.1"
[clients.server2]
[clients.server]
2 changes: 0 additions & 2 deletions tests/configs/test-rotate-keys.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ port = 10101
[clients.laptop]
dns = "10.0.0.1"
[clients.desktop]
dns = "10.0.0.1"
[clients.phone]
qr = true
dns = "10.0.0.1"
[clients.server2]
[clients.server]

0 comments on commit 83d71cc

Please sign in to comment.