From 424c801c6c9b762412946994c0b9f8b8ff072f33 Mon Sep 17 00:00:00 2001 From: 0xdcarns Date: Tue, 25 Jan 2022 23:04:03 -0500 Subject: [PATCH] server update --- controllers/node_grpc.go | 7 +++++-- models/network.go | 10 +++++----- netclient/config/config.go | 1 + netclient/functions/daemon.go | 9 +++++---- netclient/functions/join.go | 2 ++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/controllers/node_grpc.go b/controllers/node_grpc.go index b0130b79..53bb8d99 100644 --- a/controllers/node_grpc.go +++ b/controllers/node_grpc.go @@ -68,8 +68,11 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object) } var serverNodes = logic.GetServerNodes(node.Network) - for _, server := range serverNodes { - node.NetworkSettings.DefaultServerAddrs = append(node.NetworkSettings.DefaultServerAddrs, server.Address) + for i, server := range serverNodes { + node.NetworkSettings.DefaultServerAddrs += server.Address + if i < len(serverNodes)-1 { + node.NetworkSettings.DefaultServerAddrs += "," + } } err = logic.CreateNode(&node) diff --git a/models/network.go b/models/network.go index 492b61d0..0103199b 100644 --- a/models/network.go +++ b/models/network.go @@ -34,11 +34,11 @@ type Network struct { LocalRange string `json:"localrange" bson:"localrange" validate:"omitempty,cidr"` // checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL - DefaultCheckInInterval int32 `json:"checkininterval,omitempty" bson:"checkininterval,omitempty" validate:"omitempty,numeric,min=2,max=100000"` - DefaultUDPHolePunch string `json:"defaultudpholepunch" bson:"defaultudpholepunch" validate:"checkyesorno"` - DefaultExtClientDNS string `json:"defaultextclientdns" bson:"defaultextclientdns"` - DefaultMTU int32 `json:"defaultmtu" bson:"defaultmtu"` - DefaultServerAddrs []string `json:"defaultserveraddrs" bson:"defaultserveraddrs"` + DefaultCheckInInterval int32 `json:"checkininterval,omitempty" bson:"checkininterval,omitempty" validate:"omitempty,numeric,min=2,max=100000"` + DefaultUDPHolePunch string `json:"defaultudpholepunch" bson:"defaultudpholepunch" validate:"checkyesorno"` + DefaultExtClientDNS string `json:"defaultextclientdns" bson:"defaultextclientdns"` + DefaultMTU int32 `json:"defaultmtu" bson:"defaultmtu"` + DefaultServerAddrs string `json:"defaultserveraddrs" bson:"defaultserveraddrs" yaml:"defaultserveraddrs"` } // SaveData - sensitive fields of a network that should be kept the same diff --git a/netclient/config/config.go b/netclient/config/config.go index 66d19762..fb602bfa 100644 --- a/netclient/config/config.go +++ b/netclient/config/config.go @@ -119,6 +119,7 @@ func ModConfig(node *models.Node) error { modconfig.Node = (*node) modconfig.NetworkSettings = node.NetworkSettings + log.Printf("%v \n", modconfig) err = Write(&modconfig, network) return err } diff --git a/netclient/functions/daemon.go b/netclient/functions/daemon.go index d7c41e9f..4f01475b 100644 --- a/netclient/functions/daemon.go +++ b/netclient/functions/daemon.go @@ -8,6 +8,7 @@ import ( "os" "os/signal" "runtime" + "strings" "sync" "syscall" "time" @@ -59,7 +60,8 @@ func Daemon() error { // SetupMQTT creates a connection to broker and return client func SetupMQTT(cfg *config.ClientConfig) mqtt.Client { opts := mqtt.NewClientOptions() - for i, addr := range cfg.Node.NetworkSettings.DefaultServerAddrs { + serverAddrs := strings.Split(cfg.Node.NetworkSettings.DefaultServerAddrs, ",") + for i, addr := range serverAddrs { if addr != "" { ncutils.Log(fmt.Sprintf("adding server (%d) to listen on network %s \n", (i + 1), cfg.Node.Network)) opts.AddBroker(addr + ":1883") @@ -215,13 +217,12 @@ var UpdatePeers mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) var cfg config.ClientConfig cfg.Network = peerUpdate.Network cfg.ReadConfig() - var shouldReSub = shouldResub(cfg.Node.NetworkSettings.DefaultServerAddrs, peerUpdate.ServerAddrs) + var shouldReSub = shouldResub(strings.Split(cfg.Node.NetworkSettings.DefaultServerAddrs, ","), peerUpdate.ServerAddrs) if shouldReSub { client.Disconnect(250) // kill client // un sub, re sub.. how? client.Unsubscribe("update/"+cfg.Node.ID, "update/peers/"+cfg.Node.ID) - cfg.Node.NetworkSettings.DefaultServerAddrs = peerUpdate.ServerAddrs - + cfg.Node.NetworkSettings.DefaultServerAddrs = strings.Join(peerUpdate.ServerAddrs, ",") } file := ncutils.GetNetclientPathSpecific() + cfg.Node.Interface + ".conf" err = wireguard.UpdateWgPeers(file, peerUpdate.Peers) diff --git a/netclient/functions/join.go b/netclient/functions/join.go index f5c38c85..b37bf24c 100644 --- a/netclient/functions/join.go +++ b/netclient/functions/join.go @@ -161,6 +161,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error { if err = json.Unmarshal([]byte(nodeData), &node); err != nil { return err } + log.Printf("%v \n", nodeData) } // get free port based on returned default listen port @@ -183,6 +184,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error { } if node.IsServer != "yes" { // == handle client side == + cfg.Node = node err = config.ModConfig(&node) if err != nil { return err