implement uncloudd daemon that starts a WireGuard network without peer probing

This commit is contained in:
Pavel Sviderski
2024-08-26 17:09:54 +10:00
parent 222edb7647
commit e074b6855f
13 changed files with 347 additions and 145 deletions
+27
View File
@@ -0,0 +1,27 @@
package network
import (
"fmt"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"time"
"uncloud/internal/secret"
)
const (
WireGuardInterfaceName = "uncloud"
WireGuardPort = 51820
// WireGuardKeepaliveInterval is sensible interval that works with a wide variety of firewalls is 25 seconds.
WireGuardKeepaliveInterval = 25 * time.Second
)
// NewMachineKeys generates a new WireGuard private and public key pair.
func NewMachineKeys() (privKey, pubKey secret.Secret, err error) {
wgPrivKey, err := wgtypes.GeneratePrivateKey()
if err != nil {
return nil, nil, fmt.Errorf("generate WireGuard private key: %w", err)
}
privKey = wgPrivKey[:]
wgPubKey := wgPrivKey.PublicKey()
pubKey = wgPubKey[:]
return
}