gateway now appears to be fully functional

This commit is contained in:
afeiszli 2021-04-19 10:02:30 -04:00
parent 62ace03f5e
commit c6714bcb8e
2 changed files with 31 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package controller
import (
"context"
"fmt"
"strconv"
nodepb "github.com/gravitl/netmaker/grpc"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/functions"
@ -91,7 +92,16 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
//Check to see if key is valid
//TODO: Triple inefficient!!! This is the third call to the DB we make for networks
validKey := functions.IsKeyValid(node.Network, node.AccessKey)
network, _ := functions.GetParentNetwork(node.Network)
network, err := functions.GetParentNetwork(node.Network)
if err != nil {
return nil, status.Errorf(codes.NotFound, fmt.Sprintf("Could not find network: %v", err))
} else {
fmt.Println("Creating node in network " + network.NetID)
fmt.Println("Network is local? " + strconv.FormatBool(*network.IsLocal))
fmt.Println("Range if local: " + network.LocalRange)
}
if !validKey {
//Check to see if network will allow manual sign up

View file

@ -255,16 +255,21 @@ func Install(accesskey string, password string, server string, network string, n
if nodecfg.Endpoint == "" {
if islocal && localaddress != "" {
endpoint = localaddress
fmt.Println("Endpoint is local. Setting to address: " + endpoint)
} else {
endpoint, err = getPublicIP()
if err != nil {
fmt.Println("Error setting endpoint.")
return err
}
fmt.Println("Endpoint is public. Setting to address: " + endpoint)
}
} else {
endpoint = nodecfg.Endpoint
fmt.Println("Endpoint set in config. Setting to address: " + endpoint)
}
fmt.Println(" Public Endpoint: " + endpoint)
fmt.Println(" Endpoint: " + endpoint)
if nodecfg.Name != "" {
@ -414,6 +419,7 @@ func Install(accesskey string, password string, server string, network string, n
fmt.Println(" Local Range: " + node.Localrange)
if !islocal && node.Islocal && node.Localrange != "" {
fmt.Println("Resetting local settings for local network.")
node.Localaddress, err = getLocalIP(node.Localrange)
if err != nil {
return err
@ -948,7 +954,7 @@ func CheckIn(network string) error {
if !nodecfg.RoamingOff {
if !nodecfg.IsLocal {
fmt.Println("Checking to see if addresses have changed")
fmt.Println("Checking to see if public addresses have changed")
extIP, err := getPublicIP()
if err != nil {
fmt.Printf("Error encountered checking ip addresses: %v", err)
@ -978,7 +984,7 @@ func CheckIn(network string) error {
ipchange = true
}
} else {
fmt.Println("Checking to see if address has changed")
fmt.Println("Checking to see if local addresses have changed")
localIP, err := getLocalIP(nodecfg.LocalRange)
if err != nil {
fmt.Printf("Error encountered checking ip addresses: %v", err)
@ -1413,14 +1419,13 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
res, err := stream.Recv()
// If end of stream, break the loop
if err == io.EOF {
break
}
// if err, return an error
if err != nil {
if strings.Contains(err.Error(), "mongo: no documents in result") {
break
continue
} else {
fmt.Println("ERROR ENCOUNTERED WITH RESPONSE")
fmt.Println(res)
@ -1432,6 +1437,16 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
fmt.Println("error parsing key")
return peers, hasGateway, gateways, err
}
if nodecfg.PublicKey == res.Peers.Publickey {
fmt.Println("Peer is self. Skipping")
continue
}
if nodecfg.Endpoint == res.Peers.Endpoint {
fmt.Println("Peer is self. Skipping")
continue
}
var peer wgtypes.PeerConfig
var peeraddr = net.IPNet{
IP: net.ParseIP(res.Peers.Address),
@ -1439,7 +1454,6 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
}
var allowedips []net.IPNet
allowedips = append(allowedips, peeraddr)
if res.Peers.Isgateway {
hasGateway = true
gateways = append(gateways,res.Peers.Gatewayrange)