watch for peer endpoint changes and preserve in machine state

This commit is contained in:
Pavel Sviderski
2024-10-08 16:51:40 +10:00
parent 2eff7d1e22
commit 3a644771ca
4 changed files with 95 additions and 15 deletions
+7
View File
@@ -3,6 +3,7 @@ package network
import (
"fmt"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"net/netip"
"time"
"uncloud/internal/secret"
)
@@ -14,6 +15,12 @@ const (
WireGuardKeepaliveInterval = 25 * time.Second
)
type EndpointChangeEvent struct {
PublicKey secret.Secret
// Endpoint is the new endpoint of the peer.
Endpoint netip.AddrPort
}
// NewMachineKeys generates a new WireGuard private and public key pair.
func NewMachineKeys() (privKey, pubKey secret.Secret, err error) {
wgPrivKey, err := wgtypes.GeneratePrivateKey()