got grpc private comms working

This commit is contained in:
root
2021-05-29 19:06:35 +00:00
18 changed files with 283 additions and 57 deletions

View File

@@ -702,9 +702,15 @@ func UniqueAddress(networkName string) (string, error) {
offset = false
continue
}
if IsIPUnique(networkName, ip.String()) && IsIPUniqueExtClients(networkName, ip.String()) {
return ip.String(), err
}
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
@@ -894,6 +900,33 @@ func IsIP6UniqueClients(network string, ip string) bool {
return isunique
}
//checks if IP is unique in the address range
//used by UniqueAddress
func 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 necessary
func DecrimentKey(networkName string, keyvalue string) {