apply suggestions from code review
Remove wireguard.Enpoint struct and use net.UDPAddr for the resolved endpoint and addr string (dnsanme:port) if a DN was supplied. Signed-off-by: leonnicolas <leonloechner@gmx.de>
This commit is contained in:
@@ -56,8 +56,8 @@ const (
|
||||
|
||||
// Node represents a node in the network.
|
||||
type Node struct {
|
||||
KiloEndpoint *wireguard.Endpoint
|
||||
Endpoint *net.UDPAddr
|
||||
Addr string // eg. dnsname:port
|
||||
Key wgtypes.Key
|
||||
NoInternalIP bool
|
||||
InternalIP *net.IPNet
|
||||
@@ -82,9 +82,7 @@ type Node struct {
|
||||
func (n *Node) Ready() bool {
|
||||
// Nodes that are not leaders will not have WireGuardIPs, so it is not required.
|
||||
return n != nil &&
|
||||
n.KiloEndpoint != nil &&
|
||||
!(n.KiloEndpoint.IP == nil && n.KiloEndpoint.DNS == "") &&
|
||||
n.KiloEndpoint.Port != 0 &&
|
||||
(n.Endpoint != nil || n.Addr != "") &&
|
||||
n.Key != wgtypes.Key{} &&
|
||||
n.Subnet != nil &&
|
||||
time.Now().Unix()-n.LastSeen < int64(checkInPeriod)*2/int64(time.Second)
|
||||
|
@@ -20,7 +20,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/awalterschulze/gographviz"
|
||||
"github.com/squat/kilo/pkg/wireguard"
|
||||
)
|
||||
|
||||
// Dot generates a Graphviz graph of the Topology in DOT fomat.
|
||||
@@ -62,10 +61,10 @@ func (t *Topology) Dot() (string, error) {
|
||||
return "", fmt.Errorf("failed to add node to subgraph")
|
||||
}
|
||||
var wg net.IP
|
||||
var endpoint *wireguard.Endpoint
|
||||
var endpoint *net.UDPAddr
|
||||
if j == s.leader {
|
||||
wg = s.wireGuardIP
|
||||
endpoint = s.kiloEndpoint
|
||||
endpoint = s.endpoint
|
||||
if err := g.Nodes.Lookup[graphEscape(s.hostnames[j])].Attrs.Add(string(gographviz.Rank), "1"); err != nil {
|
||||
return "", fmt.Errorf("failed to add rank to node")
|
||||
}
|
||||
@@ -74,7 +73,7 @@ func (t *Topology) Dot() (string, error) {
|
||||
if s.privateIPs != nil {
|
||||
priv = s.privateIPs[j]
|
||||
}
|
||||
if err := g.Nodes.Lookup[graphEscape(s.hostnames[j])].Attrs.Add(string(gographviz.Label), nodeLabel(s.location, s.hostnames[j], s.cidrs[j], priv, wg, endpoint)); err != nil {
|
||||
if err := g.Nodes.Lookup[graphEscape(s.hostnames[j])].Attrs.Add(string(gographviz.Label), nodeLabel(s.location, s.hostnames[j], s.cidrs[j], priv, wg, endpoint, s.addr)); err != nil {
|
||||
return "", fmt.Errorf("failed to add label to node")
|
||||
}
|
||||
}
|
||||
@@ -154,7 +153,7 @@ func subGraphName(name string) string {
|
||||
return graphEscape(fmt.Sprintf("cluster_location_%s", name))
|
||||
}
|
||||
|
||||
func nodeLabel(location, name string, cidr *net.IPNet, priv, wgIP net.IP, endpoint *wireguard.Endpoint) string {
|
||||
func nodeLabel(location, name string, cidr *net.IPNet, priv, wgIP net.IP, endpoint *net.UDPAddr, addr string) string {
|
||||
label := []string{
|
||||
location,
|
||||
name,
|
||||
@@ -166,8 +165,14 @@ func nodeLabel(location, name string, cidr *net.IPNet, priv, wgIP net.IP, endpoi
|
||||
if wgIP != nil {
|
||||
label = append(label, wgIP.String())
|
||||
}
|
||||
if endpoint != nil {
|
||||
label = append(label, endpoint.String())
|
||||
var str string
|
||||
if addr != "" {
|
||||
str = addr
|
||||
} else if endpoint != nil {
|
||||
str = endpoint.String()
|
||||
}
|
||||
if str != "" {
|
||||
label = append(label, str)
|
||||
}
|
||||
return graphEscape(strings.Join(label, "\\n"))
|
||||
}
|
||||
|
@@ -370,8 +370,8 @@ func (m *Mesh) checkIn() {
|
||||
|
||||
func (m *Mesh) handleLocal(n *Node) {
|
||||
// Allow the IPs to be overridden.
|
||||
if n.KiloEndpoint == nil || (n.KiloEndpoint.DNS == "" && n.KiloEndpoint.IP == nil) {
|
||||
n.KiloEndpoint = &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: m.externalIP.IP}, Port: m.port}
|
||||
if n.Endpoint == nil || n.Addr == "" {
|
||||
n.Endpoint = &net.UDPAddr{IP: m.externalIP.IP, Port: m.port}
|
||||
}
|
||||
if n.InternalIP == nil && !n.NoInternalIP {
|
||||
n.InternalIP = m.internalIP
|
||||
@@ -380,7 +380,7 @@ func (m *Mesh) handleLocal(n *Node) {
|
||||
// Take leader, location, and subnet from the argument, as these
|
||||
// are not determined by kilo.
|
||||
local := &Node{
|
||||
KiloEndpoint: n.KiloEndpoint,
|
||||
Endpoint: n.Endpoint,
|
||||
Key: m.pub,
|
||||
NoInternalIP: n.NoInternalIP,
|
||||
InternalIP: n.InternalIP,
|
||||
@@ -484,7 +484,7 @@ func (m *Mesh) applyTopology() {
|
||||
|
||||
natEndpoints := discoverNATEndpoints(nodes, peers, wgDevice, m.logger)
|
||||
nodes[m.hostname].DiscoveredEndpoints = natEndpoints
|
||||
t, err := NewTopology(nodes, peers, m.granularity, m.hostname, nodes[m.hostname].KiloEndpoint.Port, m.priv, m.subnet, nodes[m.hostname].PersistentKeepalive, m.logger)
|
||||
t, err := NewTopology(nodes, peers, m.granularity, m.hostname, nodes[m.hostname].Endpoint.Port, m.priv, m.subnet, nodes[m.hostname].PersistentKeepalive, m.logger)
|
||||
if err != nil {
|
||||
level.Error(m.logger).Log("error", err)
|
||||
m.errorCounter.WithLabelValues("apply").Inc()
|
||||
@@ -625,12 +625,12 @@ func (m *Mesh) resolveEndpoints() error {
|
||||
}
|
||||
// If the node is ready, then the endpoint is not nil
|
||||
// but it may not have a DNS name.
|
||||
if m.nodes[k].KiloEndpoint.DNS == "" {
|
||||
if m.nodes[k].Addr == "" {
|
||||
continue
|
||||
}
|
||||
if u, err := net.ResolveUDPAddr("udp", m.nodes[k].KiloEndpoint.String()); err == nil {
|
||||
if u, err := net.ResolveUDPAddr("udp", m.nodes[k].Addr); err == nil {
|
||||
m.nodes[k].Endpoint = u
|
||||
m.nodes[k].KiloEndpoint.IP = u.IP
|
||||
m.nodes[k].Endpoint.IP = u.IP
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
@@ -642,12 +642,11 @@ func (m *Mesh) resolveEndpoints() error {
|
||||
continue
|
||||
}
|
||||
// Peers may have nil endpoints.
|
||||
if m.peers[k].KiloEndpoint == nil || m.peers[k].KiloEndpoint.DNS == "" {
|
||||
if m.peers[k].Addr == "" {
|
||||
continue
|
||||
}
|
||||
if u, err := net.ResolveUDPAddr("udp", m.peers[k].KiloEndpoint.String()); err == nil {
|
||||
if u, err := net.ResolveUDPAddr("udp", m.peers[k].Addr); err == nil {
|
||||
m.peers[k].Endpoint = u
|
||||
m.peers[k].KiloEndpoint.IP = u.IP
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
@@ -668,7 +667,7 @@ func nodesAreEqual(a, b *Node) bool {
|
||||
}
|
||||
// Check the DNS name first since this package
|
||||
// is doing the DNS resolution.
|
||||
if !a.KiloEndpoint.Equal(b.KiloEndpoint, true) {
|
||||
if a.Addr != b.Addr || a.Endpoint.String() != b.Endpoint.String() {
|
||||
return false
|
||||
}
|
||||
// Ignore LastSeen when comparing equality we want to check if the nodes are
|
||||
@@ -697,7 +696,7 @@ func peersAreEqual(a, b *Peer) bool {
|
||||
}
|
||||
// Check the DNS name first since this package
|
||||
// is doing the DNS resolution.
|
||||
if !a.KiloEndpoint.Equal(b.KiloEndpoint, true) {
|
||||
if a.Addr != b.Addr || a.Endpoint.String() != b.Endpoint.String() {
|
||||
return false
|
||||
}
|
||||
if len(a.AllowedIPs) != len(b.AllowedIPs) {
|
||||
|
@@ -19,7 +19,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/squat/kilo/pkg/wireguard"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
|
||||
@@ -63,58 +62,58 @@ func TestReady(t *testing.T) {
|
||||
{
|
||||
name: "empty endpoint IP",
|
||||
node: &Node{
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{}, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Key: wgtypes.Key{},
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
Endpoint: &net.UDPAddr{Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Key: wgtypes.Key{},
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
},
|
||||
ready: false,
|
||||
},
|
||||
{
|
||||
name: "empty endpoint port",
|
||||
node: &Node{
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: externalIP.IP}},
|
||||
InternalIP: internalIP,
|
||||
Key: wgtypes.Key{},
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
Endpoint: &net.UDPAddr{IP: externalIP.IP},
|
||||
InternalIP: internalIP,
|
||||
Key: wgtypes.Key{},
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
},
|
||||
ready: false,
|
||||
},
|
||||
{
|
||||
name: "empty internal IP",
|
||||
node: &Node{
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: externalIP.IP}, Port: DefaultKiloPort},
|
||||
Key: wgtypes.Key{},
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
Endpoint: &net.UDPAddr{IP: externalIP.IP, Port: DefaultKiloPort},
|
||||
Key: wgtypes.Key{},
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
},
|
||||
ready: false,
|
||||
},
|
||||
{
|
||||
name: "empty key",
|
||||
node: &Node{
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: externalIP.IP}, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
Endpoint: &net.UDPAddr{IP: externalIP.IP, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
},
|
||||
ready: false,
|
||||
},
|
||||
{
|
||||
name: "empty subnet",
|
||||
node: &Node{
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: externalIP.IP}, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Key: wgtypes.Key{},
|
||||
Endpoint: &net.UDPAddr{IP: externalIP.IP, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Key: wgtypes.Key{},
|
||||
},
|
||||
ready: false,
|
||||
},
|
||||
{
|
||||
name: "valid",
|
||||
node: &Node{
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: externalIP.IP}, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Key: key,
|
||||
LastSeen: time.Now().Unix(),
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
Endpoint: &net.UDPAddr{IP: externalIP.IP, Port: DefaultKiloPort},
|
||||
InternalIP: internalIP,
|
||||
Key: key,
|
||||
LastSeen: time.Now().Unix(),
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.0.0"), Mask: net.CIDRMask(16, 32)},
|
||||
},
|
||||
ready: true,
|
||||
},
|
||||
|
@@ -40,7 +40,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
||||
var gw net.IP
|
||||
for _, segment := range t.segments {
|
||||
if segment.location == t.location {
|
||||
gw = enc.Gw(segment.kiloEndpoint.IP, segment.privateIPs[segment.leader], segment.cidrs[segment.leader])
|
||||
gw = enc.Gw(segment.endpoint.IP, segment.privateIPs[segment.leader], segment.cidrs[segment.leader])
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
||||
// equals the external IP. This means that the node
|
||||
// is only accessible through an external IP and we
|
||||
// cannot encapsulate traffic to an IP through the IP.
|
||||
if segment.privateIPs == nil || segment.privateIPs[i].Equal(segment.kiloEndpoint.IP) {
|
||||
if segment.privateIPs == nil || segment.privateIPs[i].Equal(segment.endpoint.IP) {
|
||||
continue
|
||||
}
|
||||
// Add routes to the private IPs of nodes in other segments.
|
||||
|
@@ -67,7 +67,7 @@ type Topology struct {
|
||||
|
||||
type segment struct {
|
||||
allowedIPs []net.IPNet
|
||||
kiloEndpoint *wireguard.Endpoint
|
||||
addr string
|
||||
endpoint *net.UDPAddr
|
||||
key wgtypes.Key
|
||||
persistentKeepalive time.Duration
|
||||
@@ -178,7 +178,7 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
||||
})
|
||||
t.segments = append(t.segments, &segment{
|
||||
allowedIPs: allowedIPs,
|
||||
kiloEndpoint: topoMap[location][leader].KiloEndpoint,
|
||||
addr: topoMap[location][leader].Addr,
|
||||
endpoint: topoMap[location][leader].Endpoint,
|
||||
key: topoMap[location][leader].Key,
|
||||
persistentKeepalive: topoMap[location][leader].PersistentKeepalive,
|
||||
@@ -287,10 +287,10 @@ CheckIPs:
|
||||
return
|
||||
}
|
||||
|
||||
func (t *Topology) updateEndpoint(kiloEndpoint *wireguard.Endpoint, key wgtypes.Key, persistentKeepalive *time.Duration) *net.UDPAddr {
|
||||
func (t *Topology) updateEndpoint(endpoint *net.UDPAddr, key wgtypes.Key, persistentKeepalive *time.Duration) *net.UDPAddr {
|
||||
// Do not update non-nat peers
|
||||
if persistentKeepalive == nil || *persistentKeepalive == time.Duration(0) {
|
||||
return kiloEndpoint.UDPAddr()
|
||||
return endpoint
|
||||
}
|
||||
e, ok := t.discoveredEndpoints[key.String()]
|
||||
if ok {
|
||||
@@ -315,12 +315,12 @@ func (t *Topology) Conf() *wireguard.Conf {
|
||||
peer := wireguard.Peer{
|
||||
PeerConfig: wgtypes.PeerConfig{
|
||||
AllowedIPs: append(s.allowedIPs, s.allowedLocationIPs...),
|
||||
Endpoint: t.updateEndpoint(s.kiloEndpoint, s.key, &s.persistentKeepalive),
|
||||
Endpoint: t.updateEndpoint(s.endpoint, s.key, &s.persistentKeepalive),
|
||||
PersistentKeepaliveInterval: &t.persistentKeepalive,
|
||||
PublicKey: s.key,
|
||||
ReplaceAllowedIPs: true,
|
||||
},
|
||||
KiloEndpoint: s.kiloEndpoint,
|
||||
Addr: s.addr,
|
||||
}
|
||||
c.Peers = append(c.Peers, peer)
|
||||
}
|
||||
@@ -328,13 +328,13 @@ func (t *Topology) Conf() *wireguard.Conf {
|
||||
peer := wireguard.Peer{
|
||||
PeerConfig: wgtypes.PeerConfig{
|
||||
AllowedIPs: p.AllowedIPs,
|
||||
Endpoint: t.updateEndpoint(p.KiloEndpoint, p.PublicKey, p.PersistentKeepaliveInterval),
|
||||
Endpoint: t.updateEndpoint(p.Endpoint, p.PublicKey, p.PersistentKeepaliveInterval),
|
||||
PersistentKeepaliveInterval: &t.persistentKeepalive,
|
||||
PresharedKey: p.PresharedKey,
|
||||
PublicKey: p.PublicKey,
|
||||
ReplaceAllowedIPs: true,
|
||||
},
|
||||
KiloEndpoint: p.KiloEndpoint,
|
||||
Addr: p.Addr,
|
||||
}
|
||||
c.Peers = append(c.Peers, peer)
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func (t *Topology) AsPeer() wireguard.Peer {
|
||||
PublicKey: s.key,
|
||||
Endpoint: s.endpoint,
|
||||
},
|
||||
KiloEndpoint: s.kiloEndpoint,
|
||||
Addr: s.addr,
|
||||
}
|
||||
return p
|
||||
}
|
||||
@@ -377,12 +377,12 @@ func (t *Topology) PeerConf(name string) wireguard.Conf {
|
||||
peer := wireguard.Peer{
|
||||
PeerConfig: wgtypes.PeerConfig{
|
||||
AllowedIPs: s.allowedIPs,
|
||||
Endpoint: s.kiloEndpoint.UDPAddr(),
|
||||
Endpoint: s.endpoint,
|
||||
PersistentKeepaliveInterval: pka,
|
||||
PresharedKey: psk,
|
||||
PublicKey: s.key,
|
||||
},
|
||||
KiloEndpoint: s.kiloEndpoint,
|
||||
Addr: s.addr,
|
||||
}
|
||||
c.Peers = append(c.Peers, peer)
|
||||
}
|
||||
@@ -417,13 +417,13 @@ func findLeader(nodes []*Node) int {
|
||||
var leaders, public []int
|
||||
for i := range nodes {
|
||||
if nodes[i].Leader {
|
||||
if isPublic(nodes[i].KiloEndpoint.IP) {
|
||||
if isPublic(nodes[i].Endpoint.IP) {
|
||||
return i
|
||||
}
|
||||
leaders = append(leaders, i)
|
||||
|
||||
}
|
||||
if isPublic(nodes[i].KiloEndpoint.IP) {
|
||||
if nodes[i].Endpoint != nil && isPublic(nodes[i].Endpoint.IP) {
|
||||
public = append(public, i)
|
||||
}
|
||||
}
|
||||
@@ -449,7 +449,7 @@ func deduplicatePeerIPs(peers []*Peer) []*Peer {
|
||||
PresharedKey: peer.PresharedKey,
|
||||
PublicKey: peer.PublicKey,
|
||||
},
|
||||
KiloEndpoint: peer.KiloEndpoint,
|
||||
Addr: peer.Addr,
|
||||
},
|
||||
}
|
||||
for _, ip := range peer.AllowedIPs {
|
||||
|
@@ -60,7 +60,7 @@ func setup(t *testing.T) (map[string]*Node, map[string]*Peer, wgtypes.Key, int)
|
||||
nodes := map[string]*Node{
|
||||
"a": {
|
||||
Name: "a",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e1.IP}, Port: DefaultKiloPort},
|
||||
Endpoint: &net.UDPAddr{IP: e1.IP, Port: DefaultKiloPort},
|
||||
InternalIP: i1,
|
||||
Location: "1",
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.1.0"), Mask: net.CIDRMask(24, 32)},
|
||||
@@ -69,7 +69,7 @@ func setup(t *testing.T) (map[string]*Node, map[string]*Peer, wgtypes.Key, int)
|
||||
},
|
||||
"b": {
|
||||
Name: "b",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
||||
Endpoint: &net.UDPAddr{IP: e2.IP, Port: DefaultKiloPort},
|
||||
InternalIP: i1,
|
||||
Location: "2",
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.2.0"), Mask: net.CIDRMask(24, 32)},
|
||||
@@ -77,17 +77,17 @@ func setup(t *testing.T) (map[string]*Node, map[string]*Peer, wgtypes.Key, int)
|
||||
AllowedLocationIPs: []net.IPNet{*i3},
|
||||
},
|
||||
"c": {
|
||||
Name: "c",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e3.IP}, Port: DefaultKiloPort},
|
||||
InternalIP: i2,
|
||||
Name: "c",
|
||||
Endpoint: &net.UDPAddr{IP: e3.IP, Port: DefaultKiloPort},
|
||||
InternalIP: i2,
|
||||
// Same location as node b.
|
||||
Location: "2",
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.3.0"), Mask: net.CIDRMask(24, 32)},
|
||||
Key: key3,
|
||||
},
|
||||
"d": {
|
||||
Name: "d",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e4.IP}, Port: DefaultKiloPort},
|
||||
Name: "d",
|
||||
Endpoint: &net.UDPAddr{IP: e4.IP, Port: DefaultKiloPort},
|
||||
// Same location as node a, but without private IP
|
||||
Location: "1",
|
||||
Subnet: &net.IPNet{IP: net.ParseIP("10.2.4.0"), Mask: net.CIDRMask(24, 32)},
|
||||
@@ -115,10 +115,10 @@ func setup(t *testing.T) (map[string]*Node, map[string]*Peer, wgtypes.Key, int)
|
||||
{IP: net.ParseIP("10.5.0.3"), Mask: net.CIDRMask(24, 32)},
|
||||
},
|
||||
PublicKey: key5,
|
||||
},
|
||||
KiloEndpoint: &wireguard.Endpoint{
|
||||
DNSOrIP: wireguard.DNSOrIP{IP: net.ParseIP("192.168.0.1")},
|
||||
Port: DefaultKiloPort,
|
||||
Endpoint: &net.UDPAddr{
|
||||
IP: net.ParseIP("192.168.0.1"),
|
||||
Port: DefaultKiloPort,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -153,7 +153,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: logicalLocationPrefix + nodes["a"].Location,
|
||||
@@ -164,7 +164,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, *nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: logicalLocationPrefix + nodes["b"].Location,
|
||||
@@ -176,7 +176,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -204,7 +204,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: logicalLocationPrefix + nodes["a"].Location,
|
||||
@@ -215,7 +215,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, *nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: logicalLocationPrefix + nodes["b"].Location,
|
||||
@@ -227,7 +227,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -255,7 +255,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: logicalLocationPrefix + nodes["a"].Location,
|
||||
@@ -266,7 +266,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, *nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: logicalLocationPrefix + nodes["b"].Location,
|
||||
@@ -278,7 +278,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -306,7 +306,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["a"].Name,
|
||||
@@ -317,7 +317,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["b"].Name,
|
||||
@@ -329,7 +329,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["c"].KiloEndpoint,
|
||||
endpoint: nodes["c"].Endpoint,
|
||||
key: nodes["c"].Key,
|
||||
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["c"].Name,
|
||||
@@ -340,7 +340,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -368,7 +368,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["a"].Name,
|
||||
@@ -379,7 +379,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["b"].Name,
|
||||
@@ -391,7 +391,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["c"].KiloEndpoint,
|
||||
endpoint: nodes["c"].Endpoint,
|
||||
key: nodes["c"].Key,
|
||||
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["c"].Name,
|
||||
@@ -402,7 +402,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -430,7 +430,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["a"].Name,
|
||||
@@ -441,7 +441,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["b"].Name,
|
||||
@@ -453,7 +453,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["c"].KiloEndpoint,
|
||||
endpoint: nodes["c"].Endpoint,
|
||||
key: nodes["c"].Key,
|
||||
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["c"].Name,
|
||||
@@ -464,7 +464,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -492,7 +492,7 @@ func TestNewTopology(t *testing.T) {
|
||||
segments: []*segment{
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["a"].KiloEndpoint,
|
||||
endpoint: nodes["a"].Endpoint,
|
||||
key: nodes["a"].Key,
|
||||
persistentKeepalive: nodes["a"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["a"].Name,
|
||||
@@ -503,7 +503,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["b"].Subnet, *nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["b"].KiloEndpoint,
|
||||
endpoint: nodes["b"].Endpoint,
|
||||
key: nodes["b"].Key,
|
||||
persistentKeepalive: nodes["b"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["b"].Name,
|
||||
@@ -515,7 +515,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["c"].Subnet, *nodes["c"].InternalIP, {IP: w3, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["c"].KiloEndpoint,
|
||||
endpoint: nodes["c"].Endpoint,
|
||||
key: nodes["c"].Key,
|
||||
persistentKeepalive: nodes["c"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["c"].Name,
|
||||
@@ -526,7 +526,7 @@ func TestNewTopology(t *testing.T) {
|
||||
},
|
||||
{
|
||||
allowedIPs: []net.IPNet{*nodes["d"].Subnet, {IP: w4, Mask: net.CIDRMask(32, 32)}},
|
||||
kiloEndpoint: nodes["d"].KiloEndpoint,
|
||||
endpoint: nodes["d"].Endpoint,
|
||||
key: nodes["d"].Key,
|
||||
persistentKeepalive: nodes["d"].PersistentKeepalive,
|
||||
location: nodeLocationPrefix + nodes["d"].Name,
|
||||
@@ -575,26 +575,26 @@ func TestFindLeader(t *testing.T) {
|
||||
|
||||
nodes := []*Node{
|
||||
{
|
||||
Name: "a",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e1.IP}, Port: DefaultKiloPort},
|
||||
Name: "a",
|
||||
Endpoint: &net.UDPAddr{IP: e1.IP, Port: DefaultKiloPort},
|
||||
},
|
||||
{
|
||||
Name: "b",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
||||
Name: "b",
|
||||
Endpoint: &net.UDPAddr{IP: e2.IP, Port: DefaultKiloPort},
|
||||
},
|
||||
{
|
||||
Name: "c",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
||||
Name: "c",
|
||||
Endpoint: &net.UDPAddr{IP: e2.IP, Port: DefaultKiloPort},
|
||||
},
|
||||
{
|
||||
Name: "d",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e1.IP}, Port: DefaultKiloPort},
|
||||
Leader: true,
|
||||
Name: "d",
|
||||
Endpoint: &net.UDPAddr{IP: e1.IP, Port: DefaultKiloPort},
|
||||
Leader: true,
|
||||
},
|
||||
{
|
||||
Name: "2",
|
||||
KiloEndpoint: &wireguard.Endpoint{DNSOrIP: wireguard.DNSOrIP{IP: e2.IP}, Port: DefaultKiloPort},
|
||||
Leader: true,
|
||||
Name: "2",
|
||||
Endpoint: &net.UDPAddr{IP: e2.IP, Port: DefaultKiloPort},
|
||||
Leader: true,
|
||||
},
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
|
Reference in New Issue
Block a user