diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index edd13ed9..83371183 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -31,6 +31,8 @@ body: label: Version description: What version are you running? options: + - v0.13.1 + - v0.13.0 - v0.12.2 - v0.12.1 - v0.12.0 diff --git a/.github/workflows/docker-builder.yml b/.github/workflows/docker-builder.yml index 17736e90..d23a1230 100644 --- a/.github/workflows/docker-builder.yml +++ b/.github/workflows/docker-builder.yml @@ -18,11 +18,11 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push to docker hub + - name: Build and push to docker hub uses: docker/build-push-action@v2 with: context: . - load: true - platform: linux/amd64 + push: true + platforms: linux/amd64, linux/arm64 file: ./docker/Dockerfile-go-builder tags: gravitl/go-builder:latest diff --git a/README.md b/README.md index 60db345e..fdd2669c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ a platform for modern, blazing fast virtual networks

- + diff --git a/compose/docker-compose.contained.yml b/compose/docker-compose.contained.yml index 75b36059..a2e8699c 100644 --- a/compose/docker-compose.contained.yml +++ b/compose/docker-compose.contained.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.13.0 + image: gravitl/netmaker:v0.13.1 volumes: - dnsconfig:/root/config/dnsconfig - sqldata:/root/data @@ -16,6 +16,7 @@ services: - net.ipv4.ip_forward=1 - net.ipv4.conf.all.src_valid_mark=1 - net.ipv6.conf.all.disable_ipv6=0 + - net.ipv6.conf.all.forwarding=1 restart: always environment: SERVER_NAME: "broker.NETMAKER_BASE_DOMAIN" @@ -42,7 +43,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.13.0 + image: gravitl/netmaker-ui:v0.13.1 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.hostnetwork.yml b/compose/docker-compose.hostnetwork.yml index 77facdba..723ac1e7 100644 --- a/compose/docker-compose.hostnetwork.yml +++ b/compose/docker-compose.hostnetwork.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.13.0 + image: gravitl/netmaker:v0.13.1 volumes: - dnsconfig:/root/config/dnsconfig - /usr/bin/wg:/usr/bin/wg @@ -37,7 +37,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.13.0 + image: gravitl/netmaker-ui:v0.13.1 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.nocaddy.yml b/compose/docker-compose.nocaddy.yml index 550d9e9d..ce20d5df 100644 --- a/compose/docker-compose.nocaddy.yml +++ b/compose/docker-compose.nocaddy.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.13.0 + image: gravitl/netmaker:v0.13.1 volumes: - dnsconfig:/root/config/dnsconfig - sqldata:/root/data @@ -16,6 +16,7 @@ services: - net.ipv4.ip_forward=1 - net.ipv4.conf.all.src_valid_mark=1 - net.ipv6.conf.all.disable_ipv6=0 + - net.ipv6.conf.all.forwarding=1 restart: always environment: SERVER_NAME: "broker.NETMAKER_BASE_DOMAIN" @@ -42,7 +43,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.13.0 + image: gravitl/netmaker-ui:v0.13.1 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.nodns.yml b/compose/docker-compose.nodns.yml index 5a2dacec..5bebc0fb 100644 --- a/compose/docker-compose.nodns.yml +++ b/compose/docker-compose.nodns.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.13.0 + image: gravitl/netmaker:v0.13.1 volumes: - dnsconfig:/root/config/dnsconfig - sqldata:/root/data @@ -16,6 +16,7 @@ services: - net.ipv4.ip_forward=1 - net.ipv4.conf.all.src_valid_mark=1 - net.ipv6.conf.all.disable_ipv6=0 + - net.ipv6.conf.all.forwarding=1 restart: always environment: SERVER_NAME: "broker.NETMAKER_BASE_DOMAIN" @@ -43,7 +44,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.13.0 + image: gravitl/netmaker-ui:v0.13.1 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.reference.yml b/compose/docker-compose.reference.yml index 749d226d..b20c1d52 100644 --- a/compose/docker-compose.reference.yml +++ b/compose/docker-compose.reference.yml @@ -2,7 +2,7 @@ services: netmaker: # The Primary Server for running Netmaker privileged: true # Necessary to run sudo/root level commands on host system. Likely using this if running with host networking on. container_name: netmaker - image: gravitl/netmaker:v0.13.0 + image: gravitl/netmaker:v0.13.1 volumes: # Volume mounts necessary for CLIENT_MODE to control wireguard networking on host (except dnsconfig, which is where dns config files are stored for use by CoreDNS) - dnsconfig:/root/config/dnsconfig # Netmaker writes Corefile to this location, which gets mounted by CoreDNS for DNS configuration. - sqldata:/root/data @@ -15,6 +15,7 @@ services: - net.ipv4.ip_forward=1 - net.ipv4.conf.all.src_valid_mark=1 - net.ipv6.conf.all.disable_ipv6=0 + - net.ipv6.conf.all.forwarding=1 restart: always network_mode: host # Must configure with very particular settngs for host networking to work. Do not just set on! environment: @@ -44,7 +45,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.13.0 + image: gravitl/netmaker-ui:v0.13.1 links: - "netmaker:api" ports: diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 75b36059..a2e8699c 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -3,7 +3,7 @@ version: "3.4" services: netmaker: container_name: netmaker - image: gravitl/netmaker:v0.13.0 + image: gravitl/netmaker:v0.13.1 volumes: - dnsconfig:/root/config/dnsconfig - sqldata:/root/data @@ -16,6 +16,7 @@ services: - net.ipv4.ip_forward=1 - net.ipv4.conf.all.src_valid_mark=1 - net.ipv6.conf.all.disable_ipv6=0 + - net.ipv6.conf.all.forwarding=1 restart: always environment: SERVER_NAME: "broker.NETMAKER_BASE_DOMAIN" @@ -42,7 +43,7 @@ services: container_name: netmaker-ui depends_on: - netmaker - image: gravitl/netmaker-ui:v0.13.0 + image: gravitl/netmaker-ui:v0.13.1 links: - "netmaker:api" ports: diff --git a/controllers/dns.go b/controllers/dns.go index b1891599..dfa9f67b 100644 --- a/controllers/dns.go +++ b/controllers/dns.go @@ -9,6 +9,8 @@ import ( "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/logic" "github.com/gravitl/netmaker/models" + "github.com/gravitl/netmaker/mq" + "github.com/gravitl/netmaker/servercfg" ) func dnsHandlers(r *mux.Router) { @@ -116,6 +118,20 @@ func createDNS(w http.ResponseWriter, r *http.Request) { returnErrorResponse(w, r, formatError(err, "internal")) return } + logger.Log(1, "new DNS record added:", entry.Name) + if servercfg.IsMessageQueueBackend() { + serverNode, err := logic.GetNetworkServerLocal(entry.Network) + if err != nil { + logger.Log(1, "failed to find server node after DNS update on", entry.Network) + } else { + if err = logic.ServerUpdate(&serverNode, false); err != nil { + logger.Log(1, "failed to update server node after DNS update on", entry.Network) + } + if err = mq.PublishPeerUpdate(&serverNode); err != nil { + logger.Log(0, "failed to publish peer update after ACL update on", entry.Network) + } + } + } w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(entry) } diff --git a/controllers/ext_client.go b/controllers/ext_client.go index 06acef72..c0fdb88d 100644 --- a/controllers/ext_client.go +++ b/controllers/ext_client.go @@ -153,7 +153,7 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) { } gwendpoint := gwnode.Endpoint + ":" + strconv.Itoa(int(gwnode.ListenPort)) newAllowedIPs := network.AddressRange - if newAllowedIPs != "" { + if newAllowedIPs != "" && network.AddressRange6 != "" { newAllowedIPs += "," } if network.AddressRange6 != "" { diff --git a/logic/peers.go b/logic/peers.go index 13af8fa6..eef272ab 100644 --- a/logic/peers.go +++ b/logic/peers.go @@ -83,7 +83,7 @@ func GetNodePeers(network *models.Network, nodeid string, excludeRelayed bool, i if node.UDPHolePunch == "yes" && node.IsStatic != "yes" && peer.ListenPort == node.ListenPort { peer.ListenPort = node.LocalListenPort } - if node.IsRelay == "yes" { + if node.IsRelay == "yes" { // TODO, check if addressrange6 needs to be appended peer.AllowedIPs = append(peer.AllowedIPs, network.AddressRange) for _, egressNode := range egressNetworkNodes { if egressNode.IsRelayed == "yes" && StringSliceContains(node.RelayAddrs, egressNode.Address) { @@ -139,7 +139,7 @@ func GetPeersList(refnode *models.Node) ([]models.Node, error) { if relayNode.Address != "" { var peerNode = setPeerInfo(&relayNode) network, err := GetNetwork(networkName) - if err == nil { + if err == nil { // TODO: check if addressrange6 needs to be appended peerNode.AllowedIPs = append(peerNode.AllowedIPs, network.AddressRange) var _, egressNetworkNodes, err = getNetworkEgressAndNodes(networkName) if err == nil { diff --git a/logic/wireguard.go b/logic/wireguard.go index 849365f1..95324023 100644 --- a/logic/wireguard.go +++ b/logic/wireguard.go @@ -3,6 +3,7 @@ package logic import ( "errors" "fmt" + "net" "os" "os/exec" "strconv" @@ -11,6 +12,7 @@ import ( "github.com/gravitl/netmaker/logger" "github.com/gravitl/netmaker/models" + "github.com/gravitl/netmaker/netclient/local" "github.com/gravitl/netmaker/netclient/ncutils" "github.com/gravitl/netmaker/netclient/wireguard" "golang.zx2c4.com/wireguard/wgctrl" @@ -257,6 +259,10 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig wireguard.SetPeers(ifacename, node, peers) } + if node.IsServer == "yes" { + setServerRoutes(node.Interface, node.Network) + } + return err } @@ -387,3 +393,21 @@ func removeLocalServer(node *models.Node) error { } return err } + +func setServerRoutes(iface, network string) { + parentNetwork, err := GetParentNetwork(network) + if err == nil { + if parentNetwork.AddressRange != "" { + ip, cidr, err := net.ParseCIDR(parentNetwork.AddressRange) + if err == nil { + local.SetCIDRRoute(iface, ip.String(), cidr) + } + } + if parentNetwork.AddressRange6 != "" { + ip, cidr, err := net.ParseCIDR(parentNetwork.AddressRange6) + if err == nil { + local.SetCIDRRoute(iface, ip.String(), cidr) + } + } + } +} diff --git a/netclient/command/commands.go b/netclient/command/commands.go index 34aee8c0..bda80cce 100644 --- a/netclient/command/commands.go +++ b/netclient/command/commands.go @@ -73,31 +73,44 @@ func Leave(cfg *config.ClientConfig, force bool) error { // Pull - runs pull command from cli func Pull(cfg *config.ClientConfig) error { var err error + var networks = []string{} if cfg.Network == "all" { logger.Log(0, "No network selected. Running Pull for all networks.") - networks, err := ncutils.GetSystemNetworks() + networks, err = ncutils.GetSystemNetworks() if err != nil { logger.Log(1, "Error retrieving networks. Exiting.") return err } - for _, network := range networks { - _, err = functions.Pull(network, true) - if err != nil { - logger.Log(1, "Error pulling network config for network: ", network, "\n", err.Error()) - } else { - logger.Log(1, "pulled network config for "+network) - } - } - err = nil } else { + networks = append(networks, cfg.Network) + } - _, err = functions.Pull(cfg.Network, true) + var currentServers = make(map[string]config.ClientConfig) + + for _, network := range networks { + currCfg, err := config.ReadConfig(network) + if err != nil { + logger.Log(1, "could not read config when pulling for network", network) + continue + } + + _, err = functions.Pull(network, true) + if err != nil { + logger.Log(1, "Error pulling network config for network: ", network, "\n", err.Error()) + } else { + logger.Log(1, "pulled network config for "+network) + } + + currentServers[currCfg.Server.Server] = *currCfg + } + + for _, clientCfg := range currentServers { _, newKey, kerr := ed25519.GenerateKey(rand.Reader) if kerr == nil && err == nil { if kerr := tls.SaveKey(ncutils.GetNetclientPath(), ncutils.GetSeparator()+"client.key", newKey); kerr != nil { logger.Log(0, "error saving key", kerr.Error()) } else { - if kerr = functions.RegisterWithServer(&newKey, cfg); err != nil { + if kerr = functions.RegisterWithServer(&newKey, &clientCfg); err != nil { logger.Log(0, "registration error", kerr.Error()) } else { daemon.Restart() @@ -106,12 +119,7 @@ func Pull(cfg *config.ClientConfig) error { } } logger.Log(1, "reset network and peer configs") - if err == nil { - logger.Log(1, "reset network and peer configs") - logger.Log(1, "success") - } else { - logger.Log(0, "error occurred pulling configs from server") - } + return err } diff --git a/netclient/functions/daemon.go b/netclient/functions/daemon.go index 180695c2..9bb5d70a 100644 --- a/netclient/functions/daemon.go +++ b/netclient/functions/daemon.go @@ -2,6 +2,8 @@ package functions import ( "context" + "crypto/ed25519" + "crypto/rand" "crypto/tls" "crypto/x509" "errors" @@ -22,6 +24,7 @@ import ( "github.com/gravitl/netmaker/netclient/daemon" "github.com/gravitl/netmaker/netclient/ncutils" "github.com/gravitl/netmaker/netclient/wireguard" + ssl "github.com/gravitl/netmaker/tls" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) @@ -38,8 +41,7 @@ type cachedMessage struct { // Daemon runs netclient daemon from command line func Daemon() error { - var exists = struct{}{} - serverSet := make(map[string]struct{}) + serverSet := make(map[string]config.ClientConfig) // == initial pull of all networks == networks, _ := ncutils.GetSystemNetworks() if len(networks) == 0 { @@ -50,7 +52,7 @@ func Daemon() error { cfg := config.ClientConfig{} cfg.Network = network cfg.ReadConfig() - serverSet[cfg.Server.Server] = exists + serverSet[cfg.Server.Server] = cfg //temporary code --- remove in version v0.13.0 removeHostDNS(network, ncutils.IsWindows()) // end of code to be removed in version v0.13.0 @@ -58,11 +60,11 @@ func Daemon() error { } // == subscribe to all nodes for each on machine == - for server := range serverSet { + for server, config := range serverSet { logger.Log(1, "started daemon for server ", server) ctx, cancel := context.WithCancel(context.Background()) networkcontext.Store(server, cancel) - go messageQueue(ctx, server) + go messageQueue(ctx, &config) } // == add waitgroup and cancel for checkin routine == @@ -115,10 +117,11 @@ func PingServer(cfg *config.ClientConfig) error { return err } pinger.Timeout = 2 * time.Second + pinger.Count = 3 pinger.Run() stats := pinger.Statistics() if stats.PacketLoss == 100 { - return errors.New("ping error") + return errors.New("ping error " + fmt.Sprintf("%f", stats.PacketLoss)) } logger.Log(3, "ping of server", cfg.Server.Server, "was successful") return nil @@ -168,12 +171,12 @@ func unsubscribeNode(client mqtt.Client, nodeCfg *config.ClientConfig) { // sets up Message Queue and subsribes/publishes updates to/from server // the client should subscribe to ALL nodes that exist on server locally -func messageQueue(ctx context.Context, server string) { - logger.Log(0, "netclient daemon started for server: ", server) - client := setupMQTT(nil, server, false) +func messageQueue(ctx context.Context, cfg *config.ClientConfig) { + logger.Log(0, "netclient daemon started for server: ", cfg.Server.Server) + client := setupMQTT(cfg, false) defer client.Disconnect(250) <-ctx.Done() - logger.Log(0, "shutting down daemon for server ", server) + logger.Log(0, "shutting down daemon for server ", cfg.Server.Server) } // NewTLSConf sets up tls configuration to connect to broker securely @@ -204,11 +207,9 @@ func NewTLSConfig(server string) *tls.Config { // setupMQTT creates a connection to broker and returns client // this function is primarily used to create a connection to publish to the broker -func setupMQTT(cfg *config.ClientConfig, server string, publish bool) mqtt.Client { +func setupMQTT(cfg *config.ClientConfig, publish bool) mqtt.Client { opts := mqtt.NewClientOptions() - if cfg != nil { - server = cfg.Server.Server - } + server := cfg.Server.Server opts.AddBroker("ssl://" + server + ":8883") // TODO get the appropriate port of the comms mq server opts.SetTLSConfig(NewTLSConfig(server)) opts.SetClientID(ncutils.MakeRandomString(23)) @@ -236,44 +237,30 @@ func setupMQTT(cfg *config.ClientConfig, server string, publish bool) mqtt.Clien opts.SetOrderMatters(true) opts.SetResumeSubs(true) opts.SetConnectionLostHandler(func(c mqtt.Client, e error) { - logger.Log(0, "detected broker connection lost, running pull for ", cfg.Node.Network) - _, err := Pull(cfg.Node.Network, true) - if err != nil { - logger.Log(0, "could not run pull, server unreachable: ", err.Error()) - logger.Log(0, "waiting to retry...") - } - logger.Log(0, "connection re-established with mqtt server") + logger.Log(0, "detected broker connection lost for", cfg.Server.Server) }) client := mqtt.NewClient(opts) - - tperiod := time.Now().Add(12 * time.Second) - for { - //if after 12 seconds, try a pull on the last try - if time.Now().After(tperiod) { - logger.Log(0, "running pull for ", cfg.Node.Network) - _, err := Pull(cfg.Node.Network, true) - if err != nil { - logger.Log(0, "could not run pull, exiting ", cfg.Node.Network, " setup: ", err.Error()) - return client - } - time.Sleep(time.Second) - } - if token := client.Connect(); token.Wait() && token.Error() != nil { - - logger.Log(0, "unable to connect to broker, retrying ...") - if time.Now().After(tperiod) { - logger.Log(0, "could not connect to broker, exiting ", cfg.Node.Network, " setup: ", token.Error().Error()) - if strings.Contains(token.Error().Error(), "connectex") || strings.Contains(token.Error().Error(), "i/o timeout") { - logger.Log(0, "connection issue detected.. pulling and restarting daemon") - Pull(cfg.Node.Network, true) - daemon.Restart() - } - return client - } + for token := client.Connect(); !token.WaitTimeout(30*time.Second) || token.Error() != nil; token = client.Connect() { + logger.Log(0, "unable to connect to broker, retrying ...") + var err error + if token.Error() == nil { + err = errors.New("connect timeout") } else { - break + err = token.Error() + } + logger.Log(0, "could not connect to broker", cfg.Server.Server, err.Error()) + if strings.Contains(err.Error(), "connectex") || strings.Contains(err.Error(), "connect timeout") { + logger.Log(0, "connection issue detected.. attempt connection with new certs") + key, err := ssl.ReadKey(ncutils.GetNetclientPath() + ncutils.GetSeparator() + "client.key") + if err != nil { + _, *key, err = ed25519.GenerateKey(rand.Reader) + if err != nil { + log.Fatal("could not generate new key") + } + } + RegisterWithServer(key, cfg) + daemon.Restart() } - time.Sleep(2 * time.Second) } return client } diff --git a/netclient/functions/list.go b/netclient/functions/list.go index 63b0bfc7..3212d8b2 100644 --- a/netclient/functions/list.go +++ b/netclient/functions/list.go @@ -3,19 +3,25 @@ package functions import ( "encoding/json" "fmt" + "io" + "net/http" "github.com/gravitl/netmaker/logger" + "github.com/gravitl/netmaker/models" "github.com/gravitl/netmaker/netclient/config" "github.com/gravitl/netmaker/netclient/ncutils" + "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) // Peer - the peer struct for list type Peer struct { - Name string `json:"name"` - Interface string `json:"interface,omitempty"` - PrivateIPv4 string `json:"private_ipv4,omitempty"` - PrivateIPv6 string `json:"private_ipv6,omitempty"` - PublicEndpoint string `json:"public_endpoint,omitempty"` + Name string `json:"name,omitempty"` + Interface string `json:"interface,omitempty"` + PrivateIPv4 string `json:"private_ipv4,omitempty"` + PrivateIPv6 string `json:"private_ipv6,omitempty"` + PublicKey string `json:"public_key,omitempty"` + PublicEndpoint string `json:"public_endpoint,omitempty"` + Addresses []address `json:"addresses,omitempty"` } // Network - the local node network representation for list command @@ -26,6 +32,11 @@ type Network struct { Peers []Peer `json:"peers"` } +type address struct { + CIDR string `json:"cidr,omitempty"` + IP string `json:"ip,omitempty"` +} + // List - lists the current peers for the local node with name and node ID func List(network string) error { nets := []Network{} @@ -46,6 +57,10 @@ func List(network string) error { logger.Log(1, network+": Could not retrieve network configuration.") return err } + peers, err := getPeers(network) + if err == nil && len(peers) > 0 { + net.Peers = peers + } nets = append(nets, net) } @@ -80,3 +95,53 @@ func getNetwork(network string) (Network, error) { }, }, nil } + +func getPeers(network string) ([]Peer, error) { + cfg, err := config.ReadConfig(network) + if err != nil { + return []Peer{}, err + } + token, err := Authenticate(cfg) + if err != nil { + return nil, err + } + url := "https://" + cfg.Server.API + "/api/nodes/" + cfg.Network + "/" + cfg.Node.ID + response, err := API("", http.MethodGet, url, token) + if err != nil { + return nil, err + } + if response.StatusCode != http.StatusOK { + bytes, err := io.ReadAll(response.Body) + if err != nil { + fmt.Println(err) + } + return nil, (fmt.Errorf("%s %w", string(bytes), err)) + } + defer response.Body.Close() + var nodeGET models.NodeGet + if err := json.NewDecoder(response.Body).Decode(&nodeGET); err != nil { + return nil, fmt.Errorf("error decoding node %w", err) + } + if nodeGET.Peers == nil { + nodeGET.Peers = []wgtypes.PeerConfig{} + } + + peers := []Peer{} + for _, peer := range nodeGET.Peers { + var addresses = []address{} + for j := range peer.AllowedIPs { + newAddress := address{ + CIDR: peer.AllowedIPs[j].String(), + IP: peer.AllowedIPs[j].IP.String(), + } + addresses = append(addresses, newAddress) + } + peers = append(peers, Peer{ + PublicKey: peer.PublicKey.String(), + PublicEndpoint: peer.Endpoint.String(), + Addresses: addresses, + }) + } + + return peers, nil +} diff --git a/netclient/functions/mqpublish.go b/netclient/functions/mqpublish.go index ae1bd7d8..7bedde00 100644 --- a/netclient/functions/mqpublish.go +++ b/netclient/functions/mqpublish.go @@ -76,7 +76,7 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) { } } if err := PingServer(&nodeCfg); err != nil { - logger.Log(0, "could not ping server for , ", nodeCfg.Network, "\n", err.Error()) + logger.Log(0, "could not ping server for", nodeCfg.Network, nodeCfg.Server.Server+"\n", err.Error()) } else { Hello(&nodeCfg) } @@ -128,17 +128,25 @@ func publish(nodeCfg *config.ClientConfig, dest string, msg []byte, qos byte) er return err } - client := setupMQTT(nodeCfg, "", true) + client := setupMQTT(nodeCfg, true) defer client.Disconnect(250) encrypted, err := ncutils.Chunk(msg, serverPubKey, trafficPrivKey) if err != nil { return err } - if token := client.Publish(dest, qos, false, encrypted); token.Wait() && token.Error() != nil { - return token.Error() + if token := client.Publish(dest, qos, false, encrypted); !token.WaitTimeout(30*time.Second) || token.Error() != nil { + logger.Log(0, "could not connect to broker at "+nodeCfg.Server.Server+":8883") + var err error + if token.Error() == nil { + err = errors.New("connection timeout") + } else { + err = token.Error() + } + if err != nil { + return token.Error() + } } - return nil } diff --git a/netclient/netclient.exe.manifest.xml b/netclient/netclient.exe.manifest.xml index 48e6003e..739dbf89 100644 --- a/netclient/netclient.exe.manifest.xml +++ b/netclient/netclient.exe.manifest.xml @@ -1,7 +1,7 @@