From 158a7512d6be21c495f1f153128f96831c6de2a6 Mon Sep 17 00:00:00 2001 From: Nontawat Numor Date: Thu, 16 Jun 2022 23:19:32 +0700 Subject: [PATCH] Add SUBSPACE_PERSISTENT_KEEPALIVE variable :tea: (#213) * Add SUBSPACE_PERSISTENT_KEEPALIVE variable :tea: * Remove manual Contributors :tea: --- README.md | 4 ++++ cmd/subspace/handlers.go | 35 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c28bf8ff..09951b7f 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ $ subspace --http-host subspace.example.com | `SUBSPACE_THEME` | `green` | The theme to use, please refer to [semantic-ui](https://semantic-ui.com/usage/theming.html) for accepted colors | | `SUBSPACE_BACKLINK` | `/` | The page to set the home button to | | `SUBSPACE_DISABLE_DNS` | `false` | Whether to disable DNS so the client uses their own configured DNS server(s). Consider disabling DNS server, if supporting international VPN clients | +| `SUBSPACE_PERSISTENT_KEEPALIVE` | `0` | Whether PersistentKeepalive should be enabled for clients (seconds) | ### Run as a Docker container @@ -211,6 +212,8 @@ docker create \ # Optional variable to disable DNS server. Enabled by default. # consider disabling DNS server, if supporting international VPN clients --env SUBSPACE_DISABLE_DNS=0 \ + # Optional variable to change PersistentKeepalive + --env SUBSPACE_PERSISTENT_KEEPALIVE=20 \ subspacecommunity/subspace:latest $ sudo docker start subspace @@ -246,6 +249,7 @@ services: - SUBSPACE_IPV6_GW=fd00::10:97:1 - SUBSPACE_IPV6_NAT_ENABLED=1 - SUBSPACE_DISABLE_DNS=0 + - SUBSPACE_PERSISTENT_KEEPALIVE=20 cap_add: - NET_ADMIN network_mode: "host" diff --git a/cmd/subspace/handlers.go b/cmd/subspace/handlers.go index 229417be..ae7ff25e 100644 --- a/cmd/subspace/handlers.go +++ b/cmd/subspace/handlers.go @@ -462,6 +462,10 @@ func profileAddHandler(w *Web) { if shouldDisableDNS := getEnv("SUBSPACE_DISABLE_DNS", "0"); shouldDisableDNS == "1" { disableDNS = true } + persistentKeepalive := "0" + if keepalive := getEnv("SUBSPACE_PERSISTENT_KEEPALIVE", "nil"); keepalive != "nil" { + persistentKeepalive = keepalive + } script := ` cd {{$.Datadir}}/wireguard @@ -489,23 +493,25 @@ PublicKey = $(cat server.public) Endpoint = {{$.EndpointHost}}:{{$.Listenport}} AllowedIPs = {{$.AllowedIPS}} +PersistentKeepalive = {{$.PersistentKeepalive}} WGCLIENT ` _, err = bash(script, struct { - Profile Profile - EndpointHost string - Datadir string - IPv4Gw string - IPv6Gw string - IPv4Pref string - IPv6Pref string - IPv4Cidr string - IPv6Cidr string - Listenport string - AllowedIPS string - Ipv4Enabled bool - Ipv6Enabled bool - DisableDNS bool + Profile Profile + EndpointHost string + Datadir string + IPv4Gw string + IPv6Gw string + IPv4Pref string + IPv6Pref string + IPv4Cidr string + IPv6Cidr string + Listenport string + AllowedIPS string + Ipv4Enabled bool + Ipv6Enabled bool + DisableDNS bool + PersistentKeepalive string }{ profile, endpointHost, @@ -521,6 +527,7 @@ WGCLIENT ipv4Enabled, ipv6Enabled, disableDNS, + persistentKeepalive, }) if err != nil { logger.Warn(err)