assign ipv6 address to each machine derived from their public keys

This commit is contained in:
Pavel Sviderski
2024-08-29 22:37:49 +10:00
parent eed2c8809c
commit 41098d00b8
8 changed files with 77 additions and 43 deletions
+3 -5
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"net/netip"
"uncloud/internal/machine/network"
"uncloud/internal/secret"
)
@@ -43,9 +44,6 @@ func (u *User) PublicKey() secret.Secret {
return pubKey[:]
}
func (u *User) Address() netip.Addr {
pubKey := u.PublicKey()
bytes := [16]byte{0xfd, 0xcc}
copy(bytes[2:], pubKey[:14])
return netip.AddrFrom16(bytes)
func (u *User) IPv6() netip.Addr {
return network.PeerIPv6(u.PublicKey())
}