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