| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040 | //TODO: Consider restructuring  this file/folder    "github.com/gorilla/handlers"//It may make more sense to split into different files and not call it "helpers"package functionsimport (	"context"	"encoding/base64"	"errors"	"fmt"	"log"	"math/rand"	"net"	"strings"	"time"	"github.com/gravitl/netmaker/models"	"github.com/gravitl/netmaker/mongoconn"	"github.com/gravitl/netmaker/servercfg"	"go.mongodb.org/mongo-driver/bson"	"go.mongodb.org/mongo-driver/bson/primitive"	"go.mongodb.org/mongo-driver/mongo"	"go.mongodb.org/mongo-driver/mongo/options")//Takes in an arbitrary field and value for field and checks to see if any other//node has that value for the same field within the networkfunc CreateServerToken(netID string) (string, error) {	fmt.Println("Creating token.")	var network models.Network	var accesskey models.AccessKey	network, err := GetParentNetwork(netID)	if err != nil {		return "", err	}	accesskey.Name = GenKeyName()	accesskey.Value = GenKey()	accesskey.Uses = 1	address := "127.0.0.1:" + servercfg.GetGRPCPort()	privAddr := ""	if *network.IsLocal {		privAddr = network.LocalRange	}	accessstringdec := address + "|" + netID + "|" + accesskey.Value + "|" + privAddr	accesskey.AccessString = base64.StdEncoding.EncodeToString([]byte(accessstringdec))	fmt.Println("          access string: " + accesskey.AccessString)	network.AccessKeys = append(network.AccessKeys, accesskey)	collection := mongoconn.Client.Database("netmaker").Collection("networks")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	// Create filter	filter := bson.M{"netid": netID}	// Read update model from body request	fmt.Println("Adding key to " + network.NetID)	// prepare update model.	update := bson.D{		{"$set", bson.D{			{"accesskeys", network.AccessKeys},		}},	}	errN := collection.FindOneAndUpdate(ctx, filter, update).Decode(&network)	defer cancel()	if errN != nil {		return "", errN	}	return accesskey.AccessString, nil}func GetPeersList(networkName string) ([]models.PeersResponse, error) {        var peers []models.PeersResponse        //Connection mongoDB with mongoconn class        collection := mongoconn.Client.Database("netmaker").Collection("nodes")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        //Get all nodes in the relevant network which are NOT in pending state        filter := bson.M{"network": networkName, "ispending": false}        cur, err := collection.Find(ctx, filter)        if err != nil {                return peers, err        }        // Close the cursor once finished and cancel if it takes too long        defer cancel()        for cur.Next(context.TODO()) {                var peer models.PeersResponse                err := cur.Decode(&peer)                if err != nil {                        log.Fatal(err)                }                // add the node to our node array                //maybe better to just return this? But then that's just GetNodes...                peers = append(peers, peer)        }        //Uh oh, fatal error! This needs some better error handling        //TODO: needs appropriate error handling so the server doesnt shut down.        if err := cur.Err(); err != nil {                log.Fatal(err)        }        return peers, err}func GetIntPeersList() ([]models.PeersResponse, error) {        var peers []models.PeersResponse        collection := mongoconn.Client.Database("netmaker").Collection("intclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        filter := bson.M{"isserver": ""}        cur, err := collection.Find(ctx, filter)        if err != nil {                return peers, err        }        // Close the cursor once finished and cancel if it takes too long        defer cancel()        for cur.Next(context.TODO()) {                var peer models.PeersResponse                err := cur.Decode(&peer)                if err != nil {                        log.Fatal(err)                }                // add the node to our node array                //maybe better to just return this? But then that's just GetNodes...                peers = append(peers, peer)        }        //Uh oh, fatal error! This needs some better error handling        //TODO: needs appropriate error handling so the server doesnt shut down.        if err := cur.Err(); err != nil {                log.Fatal(err)        }        return peers, err}func IsFieldUnique(network string, field string, value string) bool {	var node models.Node	isunique := true	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{field: value, "network": network}	err := collection.FindOne(ctx, filter).Decode(&node)	defer cancel()	if err != nil {		return isunique	}	if node.Name != "" {		isunique = false	}	return isunique}func ServerIntClientExists() (bool, error) {        collection := mongoconn.Client.Database("netmaker").Collection("intclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        filter := bson.M{"isserver": "yes"}        var result bson.M        err := collection.FindOne(ctx, filter).Decode(&result)        defer cancel()        if err != nil {                if err == mongo.ErrNoDocuments {                        return false, nil                }        }        return true, err}func NetworkExists(name string) (bool, error) {	collection := mongoconn.Client.Database("netmaker").Collection("networks")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"netid": name}	var result bson.M	err := collection.FindOne(ctx, filter).Decode(&result)	defer cancel()	if err != nil {		if err == mongo.ErrNoDocuments {			return false, nil		}	}	return true, err}//TODO: This is  very inefficient (N-squared). Need to find a better way.//Takes a list of  nodes in a network and iterates through//for each node, it gets a unique address. That requires checking against all other nodes once morefunc UpdateNetworkNodeAddresses(networkName string) error {	//Connection mongoDB with mongoconn class	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"network": networkName}	cur, err := collection.Find(ctx, filter)	if err != nil {		return err	}	defer cancel()	for cur.Next(context.TODO()) {		var node models.Node		err := cur.Decode(&node)		if err != nil {			fmt.Println("error in node address assignment!")			return err		}		ipaddr, iperr := UniqueAddress(networkName)		if iperr != nil {			fmt.Println("error in node  address assignment!")			return iperr		}		filter := bson.M{"macaddress": node.MacAddress}		update := bson.D{{"$set", bson.D{{"address", ipaddr}}}}		errN := collection.FindOneAndUpdate(ctx, filter, update).Decode(&node)		defer cancel()		if errN != nil {			return errN		}	}	return err}//TODO TODO TODO!!!!!func UpdateNetworkPrivateAddresses(networkName string) error {	//Connection mongoDB with mongoconn class	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"network": networkName}	cur, err := collection.Find(ctx, filter)	if err != nil {		return err	}	defer cancel()	for cur.Next(context.TODO()) {		var node models.Node		err := cur.Decode(&node)		if err != nil {			fmt.Println("error in node address assignment!")			return err		}		ipaddr, iperr := UniqueAddress(networkName)		if iperr != nil {			fmt.Println("error in node  address assignment!")			return iperr		}		filter := bson.M{"macaddress": node.MacAddress}		update := bson.D{{"$set", bson.D{{"address", ipaddr}}}}		errN := collection.FindOneAndUpdate(ctx, filter, update).Decode(&node)		defer cancel()		if errN != nil {			return errN		}	}	return err}//Checks to see if any other networks have the same name (id)func IsNetworkNameUnique(name string) (bool, error) {	isunique := true	dbs, err := ListNetworks()	if err != nil {		return false, err	}	for i := 0; i < len(dbs); i++ {		if name == dbs[i].NetID {			isunique = false		}	}	return isunique, nil}func IsNetworkDisplayNameUnique(name string) (bool, error) {	isunique := true	dbs, err := ListNetworks()	if err != nil {		return false, err	}	for i := 0; i < len(dbs); i++ {		if name == dbs[i].DisplayName {			isunique = false		}	}	return isunique, nil}func GetNetworkNodeNumber(networkName string) (int, error) {	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"network": networkName}	count, err := collection.CountDocuments(ctx, filter)	returncount := int(count)	//not sure if this is the right way of handling this error...	if err != nil {		return 9999, err	}	defer cancel()	return returncount, err}//Kind  of a weird name. Should just be GetNetworks I think. Consider changing.//Anyway, returns all the networksfunc ListNetworks() ([]models.Network, error) {	var networks []models.Network	collection := mongoconn.Client.Database("netmaker").Collection("networks")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	cur, err := collection.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 0}))	if err != nil {		return networks, err	}	defer cancel()	for cur.Next(context.TODO()) {		var network models.Network		err := cur.Decode(&network)		if err != nil {			return networks, err		}		// add network our array		networks = append(networks, network)	}	if err := cur.Err(); err != nil {		return networks, err	}	return networks, err}//Checks to see if access key is valid//Does so by checking against all keys and seeing if any have the same value//may want to hash values before comparing...consider this//TODO: No error handling!!!!func IsKeyValid(networkname string, keyvalue string) bool {	network, _ := GetParentNetwork(networkname)	var key models.AccessKey	foundkey := false	isvalid := false	for i := len(network.AccessKeys) - 1; i >= 0; i-- {		currentkey := network.AccessKeys[i]		if currentkey.Value == keyvalue {			key = currentkey			foundkey = true		}	}	if foundkey {		if key.Uses > 0 {			isvalid = true		}	}	return isvalid}func IsKeyValidGlobal(keyvalue string) bool {        networks, _ := ListNetworks()        var key models.AccessKey        foundkey := false        isvalid := false	for _, network := range networks {		for i := len(network.AccessKeys) - 1; i >= 0; i-- {	                currentkey := network.AccessKeys[i]	                if currentkey.Value == keyvalue {	                        key = currentkey	                        foundkey = true				break	                }	        }		if foundkey { break }	}        if foundkey {                if key.Uses > 0 {                        isvalid = true                }        }        return isvalid}//TODO: Contains a fatal error return. Need to change//This just gets a network object from a network name//Should probably just be GetNetwork. kind of a dumb name.//Used in contexts where it's not the Parent network.func GetParentNetwork(networkname string) (models.Network, error) {	var network models.Network	collection := mongoconn.Client.Database("netmaker").Collection("networks")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"netid": networkname}	err := collection.FindOne(ctx, filter).Decode(&network)	defer cancel()	if err != nil {		return network, err	}	return network, nil}func IsIpNet(host string) bool {	return net.ParseIP(host) != nil}//Similar to above but checks if Cidr range is valid//At least this guy's got some print statements//still not good error handlingfunc IsIpCIDR(host string) bool {	ip, ipnet, err := net.ParseCIDR(host)	if err != nil {		fmt.Println(err)		fmt.Println("Address Range is not valid!")		return false	}	return ip != nil && ipnet != nil}//This is used to validate public keys (make sure they're base64 encoded like all public keys should be).func IsBase64(s string) bool {	_, err := base64.StdEncoding.DecodeString(s)	return err == nil}//This should probably just be called GetNode//It returns a node based on the ID of the node.//Why do we need this?//TODO: Check references. This seems unnecessary.func GetNodeObj(id primitive.ObjectID) models.Node {	var node models.Node	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"_id": id}	err := collection.FindOne(ctx, filter).Decode(&node)	defer cancel()	if err != nil {		fmt.Println(err)		fmt.Println("Did not get the node...")		return node	}	fmt.Println("Got node " + node.Name)	return node}//This  checks to  make sure a network name is valid.//Switch to REGEX?func NameInNetworkCharSet(name string) bool {	charset := "abcdefghijklmnopqrstuvwxyz1234567890-_"	for _, char := range name {		if !strings.Contains(charset, strings.ToLower(string(char))) {			return false		}	}	return true}func NameInDNSCharSet(name string) bool {	charset := "abcdefghijklmnopqrstuvwxyz1234567890-."	for _, char := range name {		if !strings.Contains(charset, strings.ToLower(string(char))) {			return false		}	}	return true}func NameInNodeCharSet(name string) bool {	charset := "abcdefghijklmnopqrstuvwxyz1234567890-"	for _, char := range name {		if !strings.Contains(charset, strings.ToLower(string(char))) {			return false		}	}	return true}//This returns a node based on its mac address.//The mac address acts as the Unique ID for nodes.//Is this a dumb thing to do? I thought it was cool but maybe it's dumb.//It doesn't really provide a tangible benefit over a random IDfunc GetNodeByMacAddress(network string, macaddress string) (models.Node, error) {	var node models.Node	filter := bson.M{"macaddress": macaddress, "network": network}	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	err := collection.FindOne(ctx, filter).Decode(&node)	defer cancel()	if err != nil {		return node, err	}	return node, nil}func DeleteAllIntClients() error {        collection := mongoconn.Client.Database("netmaker").Collection("intclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        // Filter out them ID's again        err := collection.Drop(ctx)        if err != nil {                return err        }        defer cancel()        return nil}func GetAllIntClients() ([]models.IntClient, error) {        var client models.IntClient        var clients []models.IntClient        collection := mongoconn.Client.Database("netmaker").Collection("intclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        // Filter out them ID's again        cur, err := collection.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 0}))        if err != nil {                return []models.IntClient{}, err        }        defer cancel()        for cur.Next(context.TODO()) {                err := cur.Decode(&client)                if err != nil {                        return []models.IntClient{}, err                }                // add node to our array                clients = append(clients, client)        }        //TODO: Fatal error        if err := cur.Err(); err != nil {                return []models.IntClient{}, err        }        return clients, nil}func GetAllExtClients() ([]models.ExtClient, error) {        var extclient models.ExtClient        var extclients []models.ExtClient        collection := mongoconn.Client.Database("netmaker").Collection("extclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        // Filter out them ID's again        cur, err := collection.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 0}))        if err != nil {                return []models.ExtClient{}, err        }        defer cancel()        for cur.Next(context.TODO()) {                err := cur.Decode(&extclient)                if err != nil {                        return []models.ExtClient{}, err                }                // add node to our array                extclients = append(extclients, extclient)        }        //TODO: Fatal error        if err := cur.Err(); err != nil {                return []models.ExtClient{}, err        }        return extclients, nil}//This returns a unique address for a node to use//it iterates through the list of IP's in the subnet//and checks against all nodes to see if it's taken, until it finds one.//TODO: We do not handle a case where we run out of addresses.//We will need to handle that eventuallyfunc UniqueAddress(networkName string) (string, error) {	var network models.Network	network, err := GetParentNetwork(networkName)	if err != nil {		fmt.Println("UniqueAddress encountered  an error")		return "666", err	}	offset := true	ip, ipnet, err := net.ParseCIDR(network.AddressRange)	if err != nil {		fmt.Println("UniqueAddress encountered  an error")		return "666", err	}	for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); Inc(ip) {		if offset {			offset = false			continue		}                if networkName == "comms" {                        if IsIPUniqueClients(networkName, ip.String()) {                                return ip.String(), err                        }                } else {                        if IsIPUnique(networkName, ip.String()) && IsIPUniqueExtClients(networkName, ip.String()) {                                return ip.String(), err                        }                }	}	//TODO	err1 := errors.New("ERROR: No unique addresses available. Check network subnet.")	return "W1R3: NO UNIQUE ADDRESSES AVAILABLE", err1}func UniqueAddress6(networkName string) (string, error) {	var network models.Network	network, err := GetParentNetwork(networkName)	if err != nil {		fmt.Println("Network Not Found")		return "", err	}	if network.IsDualStack == nil || *network.IsDualStack == false {		if networkName != "comms" {			return "", nil		}	}	offset := true	ip, ipnet, err := net.ParseCIDR(network.AddressRange6)	if err != nil {		fmt.Println("UniqueAddress6 encountered  an error")		return "666", err	}	for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); Inc(ip) {		if offset {			offset = false			continue		}		if networkName == "comms" {	                if IsIP6UniqueClients(networkName, ip.String()) {	                        return ip.String(), err	                }		} else {			if IsIP6Unique(networkName, ip.String()) {				return ip.String(), err			}		}	}	//TODO	err1 := errors.New("ERROR: No unique addresses available. Check network subnet.")	return "W1R3: NO UNIQUE ADDRESSES AVAILABLE", err1}//generate an access key valuefunc GenKey() string {	var seededRand *rand.Rand = rand.New(		rand.NewSource(time.Now().UnixNano()))	length := 16	charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"	b := make([]byte, length)	for i := range b {		b[i] = charset[seededRand.Intn(len(charset))]	}	return string(b)}//generate a key value//we should probably just have 1 random string generator//that  can be used across all functions//have a "base string" a "length" and a "charset"func GenKeyName() string {	var seededRand *rand.Rand = rand.New(		rand.NewSource(time.Now().UnixNano()))	length := 5	charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"	b := make([]byte, length)	for i := range b {		b[i] = charset[seededRand.Intn(len(charset))]	}	return "key" + string(b)}func IsIPUniqueExtClients(network string, ip string) bool {        var extclient models.ExtClient        isunique := true        collection := mongoconn.Client.Database("netmaker").Collection("extclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        filter := bson.M{"address": ip, "network": network}        err := collection.FindOne(ctx, filter).Decode(&extclient)        defer cancel()        if err != nil {                return isunique        }        if extclient.Address == ip {                isunique = false        }        return isunique}//checks if IP is unique in the address range//used by UniqueAddressfunc IsIPUnique(network string, ip string) bool {	var node models.Node	isunique := true	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"address": ip, "network": network}	err := collection.FindOne(ctx, filter).Decode(&node)	defer cancel()	if err != nil {		return isunique	}	if node.Address == ip {		isunique = false	}	return isunique}//checks if IP is unique in the address range//used by UniqueAddressfunc IsIP6Unique(network string, ip string) bool {	var node models.Node	isunique := true	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"address6": ip, "network": network}	err := collection.FindOne(ctx, filter).Decode(&node)	defer cancel()	if err != nil {		return isunique	}	if node.Address6 == ip {		isunique = false	}	return isunique}//checks if IP is unique in the address range//used by UniqueAddressfunc IsIP6UniqueClients(network string, ip string) bool {        var client models.IntClient        isunique := true        collection := mongoconn.Client.Database("netmaker").Collection("intclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        filter := bson.M{"address6": ip, "network": network}        err := collection.FindOne(ctx, filter).Decode(&client)        defer cancel()        if err != nil {                return isunique        }        if client.Address6 == ip {                isunique = false        }        return isunique}//checks if IP is unique in the address range//used by UniqueAddressfunc IsIPUniqueClients(network string, ip string) bool {        var client models.IntClient        isunique := true        collection := mongoconn.Client.Database("netmaker").Collection("intclients")        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)        filter := bson.M{"address": ip, "network": network}        err := collection.FindOne(ctx, filter).Decode(&client)        defer cancel()        if err != nil {                return isunique        }        if client.Address == ip {                isunique = false        }        return isunique}//called once key has been used by createNode//reduces value by one and deletes if necessaryfunc DecrimentKey(networkName string, keyvalue string) {	var network models.Network	network, err := GetParentNetwork(networkName)	if err != nil {		return	}	for i := len(network.AccessKeys) - 1; i >= 0; i-- {		currentkey := network.AccessKeys[i]		if currentkey.Value == keyvalue {			network.AccessKeys[i].Uses--			if network.AccessKeys[i].Uses < 1 {				//this is the part where it will call the delete				//not sure if there's edge cases I'm missing				DeleteKey(network, i)				return			}		}	}	collection := mongoconn.Client.Database("netmaker").Collection("networks")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	filter := bson.M{"netid": network.NetID}	update := bson.D{		{"$set", bson.D{			{"accesskeys", network.AccessKeys},		}},	}	errN := collection.FindOneAndUpdate(ctx, filter, update).Decode(&network)	defer cancel()	if errN != nil {		return	}}//takes the logic from controllers.deleteKeyfunc DeleteKey(network models.Network, i int) {	network.AccessKeys = append(network.AccessKeys[:i],		network.AccessKeys[i+1:]...)	collection := mongoconn.Client.Database("netmaker").Collection("networks")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	// Create filter	filter := bson.M{"netid": network.NetID}	// prepare update model.	update := bson.D{		{"$set", bson.D{			{"accesskeys", network.AccessKeys},		}},	}	errN := collection.FindOneAndUpdate(ctx, filter, update).Decode(&network)	defer cancel()	if errN != nil {		return	}}//increments an IP over the previousfunc Inc(ip net.IP) {	for j := len(ip) - 1; j >= 0; j-- {		ip[j]++		if ip[j] > 0 {			break		}	}}func GetAllNodes() ([]models.Node, error) {	var node models.Node	var nodes []models.Node	collection := mongoconn.Client.Database("netmaker").Collection("nodes")	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)	// Filter out them ID's again	cur, err := collection.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 0}))	if err != nil {		return []models.Node{}, err	}	defer cancel()	for cur.Next(context.TODO()) {		err := cur.Decode(&node)		if err != nil {			return []models.Node{}, err		}		// add node to our array		nodes = append(nodes, node)	}	//TODO: Fatal error	if err := cur.Err(); err != nil {		return []models.Node{}, err	}	return nodes, nil}
 |