mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
added option for insecure mqtt connections
This commit is contained in:
parent
8d8644afa1
commit
edcbc912a0
3 changed files with 10 additions and 5 deletions
3
main.go
3
main.go
|
@ -168,7 +168,8 @@ func startControllers() {
|
|||
// Should we be using a context vice a waitgroup????????????
|
||||
func runMessageQueue(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
logger.Log(0, "connecting to mq broker at", servercfg.GetMessageQueueEndpoint())
|
||||
brokerHost, secure := servercfg.GetMessageQueueEndpoint()
|
||||
logger.Log(0, "connecting to mq broker at", brokerHost, "with TLS?", fmt.Sprintf("%v", secure))
|
||||
var client = mq.SetupMQTT(false) // Set up the subscription listener
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go mq.Keepalive(ctx)
|
||||
|
|
5
mq/mq.go
5
mq/mq.go
|
@ -24,10 +24,13 @@ var peer_force_send = 0
|
|||
// SetupMQTT creates a connection to broker and return client
|
||||
func SetupMQTT(publish bool) mqtt.Client {
|
||||
opts := mqtt.NewClientOptions()
|
||||
opts.AddBroker(servercfg.GetMessageQueueEndpoint())
|
||||
broker, secure := servercfg.GetMessageQueueEndpoint()
|
||||
opts.AddBroker(broker)
|
||||
id := ncutils.MakeRandomString(23)
|
||||
opts.ClientID = id
|
||||
if secure {
|
||||
opts.SetTLSConfig(&serverctl.TlsConfig)
|
||||
}
|
||||
opts.SetAutoReconnect(true)
|
||||
opts.SetConnectRetry(true)
|
||||
opts.SetConnectRetryInterval(time.Second << 2)
|
||||
|
|
|
@ -222,14 +222,15 @@ func GetMQPort() string {
|
|||
}
|
||||
|
||||
// GetMessageQueueEndpoint - gets the message queue endpoint
|
||||
func GetMessageQueueEndpoint() string {
|
||||
func GetMessageQueueEndpoint() (string, bool) {
|
||||
host, _ := GetPublicIP()
|
||||
if os.Getenv("MQ_HOST") != "" {
|
||||
host = os.Getenv("MQ_HOST")
|
||||
} else if config.Config.Server.MQHOST != "" {
|
||||
host = config.Config.Server.MQHOST
|
||||
}
|
||||
return "ssl://" + host + ":" + GetMQServerPort()
|
||||
secure := strings.Contains(host, "mqtts") || strings.Contains(host, "ssl")
|
||||
return host + ":" + GetMQServerPort(), secure
|
||||
}
|
||||
|
||||
// GetMasterKey - gets the configured master key of server
|
||||
|
|
Loading…
Reference in a new issue