moving relay functionality to server

This commit is contained in:
afeiszli 2021-09-14 16:04:33 -04:00
parent cacab5c30b
commit d1d690fba8
3 changed files with 27 additions and 29 deletions

View file

@ -41,7 +41,7 @@ func GetPeersList(networkName string) ([]models.Node, error) {
peer.EgressGatewayRanges = node.EgressGatewayRanges
peer.IsEgressGateway = node.IsEgressGateway
}
if node.Network == networkName && node.IsPending != "yes" {
if node.Network == networkName && node.IsPending != "yes" && node.DoNotPropagate != "yes" {
if node.IsRelay == "yes" { // handle relay stuff
peer.RelayAddrs = node.RelayAddrs
peer.IsRelay = node.IsRelay
@ -65,13 +65,12 @@ func GetPeersList(networkName string) ([]models.Node, error) {
}
}
}
functions.PrintUserLog(models.NODE_SERVER_NAME, "adding to peer list: "+peer.MacAddress+" "+peer.Endpoint, 3)
if node.IsRelay == "yes" {
peer.AllowedIPs = append(peer.AllowedIPs,node.RelayAddrs...)
}
peers = append(peers, peer)
}
}
if err != nil {
return peers, err
}
return peers, err
}

View file

@ -132,7 +132,7 @@ func DeleteRelay(network, macaddress string) (models.Node, error) {
if err != nil {
return models.Node{}, err
}
err = SetNodesDoNotPropagate("yes", node.Network, node.RelayAddrs)
err = SetNodesDoNotPropagate("no", node.Network, node.RelayAddrs)
if err != nil {
return node, err
}

View file

@ -121,11 +121,8 @@ func RemoveNetwork(network string) error {
}
func GetPeers(macaddress string, network string, server string, dualstack bool, isIngressGateway bool) ([]wgtypes.PeerConfig, bool, []string, error) {
//need to implement checkin on server side
hasGateway := false
hasRelay := true
var gateways []string
var relayAddrs []string
var peers []wgtypes.PeerConfig
var wcclient nodepb.NodeServiceClient
cfg, err := config.ReadConfig(network)
@ -228,17 +225,33 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
}
}
// handle relay servers
/*
if node.IsRelay == "yes" {
hasRelay = true
relayAddrs = node.RelayAddrs
log.Println("found relay addresses")
log.Println(node.RelayAddrs)
for _, ipstring := range node.RelayAddrs { // go through each ip for relay server
log.Println("checking addr")
log.Println(ipstring)
_, ip, err := net.ParseCIDR(ipstring) // confirming it's a valid IP
if ip == nil || err != nil {
continue // if can't parse CIDR
if appendip := net.ParseIP(ipstring); appendip != nil {
ipnet := net.IPNet{
IP: net.ParseIP(ipstring),
Mask: net.CIDRMask(32, 32),
}
allowedips = append(allowedips, ipnet)
} else {
log.Println(err)
continue // if can't parse CIDR
}
} else {
allowedips = append(allowedips, *ip)
}
allowedips = append(allowedips, *ip)
}
}
*/
if node.Address6 != "" && dualstack {
var addr6 = net.IPNet{
IP: net.ParseIP(node.Address6),
@ -253,21 +266,6 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
ReplaceAllowedIPs: true,
AllowedIPs: allowedips,
}
} else if node.IsRelay == "yes" {
relaykeepalive, err := time.ParseDuration(RELAY_KEEPALIVE_MARKER)
if err != nil {
return nil, hasGateway, gateways, err
}
peer = wgtypes.PeerConfig{
PublicKey: pubkey,
PersistentKeepaliveInterval: &relaykeepalive,
Endpoint: &net.UDPAddr{
IP: net.ParseIP(node.Endpoint),
Port: int(node.ListenPort),
},
ReplaceAllowedIPs: true,
AllowedIPs: allowedips,
}
} else if keepalive != 0 {
peer = wgtypes.PeerConfig{
PublicKey: pubkey,
@ -300,13 +298,14 @@ func GetPeers(macaddress string, network string, server string, dualstack bool,
log.Println("ERROR RETRIEVING EXTERNAL PEERS",err)
}
}
/*
if hasRelay {
peers = RemoveRelayAddrsFromPeers(relayAddrs, peers)
}
*/
return peers, hasGateway, gateways, err
}
/*
func RemoveRelayAddrsFromPeers(relayAddrs []string, peers []wgtypes.PeerConfig)([]wgtypes.PeerConfig){
relayMarker, err := time.ParseDuration(RELAY_KEEPALIVE_MARKER)
if err != nil {
@ -332,7 +331,7 @@ func RemoveRelayAddrsFromPeers(relayAddrs []string, peers []wgtypes.PeerConfig)(
}
return peers
}
*/
func GetExtPeers(macaddress string, network string, server string, dualstack bool) ([]wgtypes.PeerConfig, error) {
var peers []wgtypes.PeerConfig
var wcclient nodepb.NodeServiceClient