mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-10-31 12:16:29 +08:00 
			
		
		
		
	go routines now run forever like they are supposed to
This commit is contained in:
		| @@ -30,6 +30,7 @@ func Daemon() error { | ||||
| 	signal.Notify(quit, syscall.SIGTERM, os.Interrupt) | ||||
| 	<-quit | ||||
| 	cancel() | ||||
| 	ncutils.Log("all done") | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| @@ -48,11 +49,7 @@ func SetupMQTT(cfg config.ClientConfig) mqtt.Client { | ||||
|  | ||||
| //Netclient sets up Message Queue and subsribes/publishes updates to/from server | ||||
| func Netclient(ctx context.Context, network string) { | ||||
| 	select { | ||||
| 	case <-ctx.Done(): | ||||
| 		ncutils.Log("shutting down daemon") | ||||
| 		return | ||||
| 	default: | ||||
| 	ncutils.Log("netclient go routine started for " + network) | ||||
| 	var cfg config.ClientConfig | ||||
| 	cfg.Network = network | ||||
| 	cfg.ReadConfig() | ||||
| @@ -70,7 +67,10 @@ func Netclient(ctx context.Context, network string) { | ||||
| 	defer client.Disconnect(250) | ||||
| 	go Checkin(ctx, cfg, network) | ||||
| 	go Metrics(ctx, cfg, network) | ||||
| 	} | ||||
| 	<-ctx.Done() | ||||
| 	ncutils.Log("shutting down daemon") | ||||
| 	return | ||||
| 	ncutils.Log("netclient go routine ended for " + network) | ||||
| } | ||||
|  | ||||
| //All -- mqtt message hander for all ('#') topics | ||||
| @@ -97,6 +97,7 @@ var UpdateKeys mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) | ||||
| //Checkin  -- go routine that checks for public or local ip changes, publishes changes | ||||
| //   if there are no updates, simply "pings" the server as a checkin | ||||
| func Checkin(ctx context.Context, cfg config.ClientConfig, network string) { | ||||
| 	for { | ||||
| 		select { | ||||
| 		case <-ctx.Done(): | ||||
| 			ncutils.Log("Checkin cancelled") | ||||
| @@ -134,6 +135,7 @@ func Checkin(ctx context.Context, cfg config.ClientConfig, network string) { | ||||
| 			Hello(cfg, network) | ||||
| 			ncutils.Log("Checkin complete") | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| //UpdateEndpoint -- publishes an endpoint update to broker | ||||
| @@ -159,7 +161,7 @@ func UpdateLocalAddress(cfg config.ClientConfig, network, ip string) { | ||||
| //Hello -- ping the broker to let server know node is alive and doing fine | ||||
| func Hello(cfg config.ClientConfig, network string) { | ||||
| 	client := SetupMQTT(cfg) | ||||
| 	if token := client.Publish("ping/"+network+"/"+cfg.Node.ID, 0, false, "hello world!"); token.Wait() && token.Error() != nil { | ||||
| 	if token := client.Publish("ping/"+cfg.Node.ID, 0, false, "hello world!"); token.Wait() && token.Error() != nil { | ||||
| 		ncutils.Log("error publishing ping " + token.Error().Error()) | ||||
| 	} | ||||
| 	client.Disconnect(250) | ||||
| @@ -167,6 +169,7 @@ func Hello(cfg config.ClientConfig, network string) { | ||||
|  | ||||
| //Metics --  go routine that collects wireguard metrics and publishes to broker | ||||
| func Metrics(ctx context.Context, cfg config.ClientConfig, network string) { | ||||
| 	for { | ||||
| 		select { | ||||
| 		case <-ctx.Done(): | ||||
| 			ncutils.Log("Metrics collection cancelled") | ||||
| @@ -198,4 +201,5 @@ func Metrics(ctx context.Context, cfg config.ClientConfig, network string) { | ||||
| 			client.Disconnect(250) | ||||
| 			ncutils.Log("metrics collection complete") | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Matthew R Kasun
					Matthew R Kasun