mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-05 21:56:45 +00:00
TLS support for planetmint (#381)
* added TSL support for mqtt * added configuration value mqtt-tls (bool) to support tls and non-tls connections (testing) Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
43d152fcf6
commit
b45c381b3b
@ -23,6 +23,7 @@ mqtt-domain = "{{ .PlmntConfig.MqttDomain }}"
|
||||
mqtt-port = {{ .PlmntConfig.MqttPort }}
|
||||
mqtt-user = "{{ .PlmntConfig.MqttUser }}"
|
||||
mqtt-password = "{{ .PlmntConfig.MqttPassword }}"
|
||||
mqtt-tls = "{{ .PlmntConfig.MqttTLS }}"
|
||||
|
||||
`
|
||||
|
||||
@ -40,6 +41,7 @@ type Config struct {
|
||||
MqttPort int `json:"mqtt-port" mapstructure:"mqtt-port"`
|
||||
MqttUser string `json:"mqtt-user" mapstructure:"mqtt-user"`
|
||||
MqttPassword string `json:"mqtt-password" mapstructure:"mqtt-password"`
|
||||
MqttTLS bool `json:"mqtt-tls" mapstructure:"mqtt-tls"`
|
||||
}
|
||||
|
||||
// cosmos-sdk wide global singleton
|
||||
@ -63,6 +65,7 @@ func DefaultConfig() *Config {
|
||||
MqttPort: 1885,
|
||||
MqttUser: "user",
|
||||
MqttPassword: "password",
|
||||
MqttTLS: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -51,11 +52,19 @@ func LazyLoadMonitorMQTTClient() {
|
||||
conf := config.GetConfig()
|
||||
hostPort := net.JoinHostPort(conf.MqttDomain, strconv.FormatInt(int64(conf.MqttPort), 10))
|
||||
uri := "tcp://" + hostPort
|
||||
if conf.MqttTLS {
|
||||
uri = "ssl://" + hostPort
|
||||
}
|
||||
|
||||
opts := mqtt.NewClientOptions().AddBroker(uri)
|
||||
opts.SetClientID(conf.ValidatorAddress + "-monitor")
|
||||
opts.SetUsername(conf.MqttUser)
|
||||
opts.SetPassword(conf.MqttPassword)
|
||||
if conf.MqttTLS {
|
||||
tlsConfig := &tls.Config{}
|
||||
opts.SetTLSConfig(tlsConfig)
|
||||
}
|
||||
|
||||
MonitorMQTTClient = mqtt.NewClient(opts)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -42,11 +43,19 @@ func LazyLoadMQTTClient() {
|
||||
conf := config.GetConfig()
|
||||
hostPort := net.JoinHostPort(conf.MqttDomain, strconv.FormatInt(int64(conf.MqttPort), 10))
|
||||
uri := "tcp://" + hostPort
|
||||
if conf.MqttTLS {
|
||||
uri = "ssl://" + hostPort
|
||||
}
|
||||
|
||||
opts := mqtt.NewClientOptions().AddBroker(uri)
|
||||
opts.SetClientID(conf.ValidatorAddress)
|
||||
opts.SetUsername(conf.MqttUser)
|
||||
opts.SetPassword(conf.MqttPassword)
|
||||
if conf.MqttTLS {
|
||||
tlsConfig := &tls.Config{}
|
||||
opts.SetTLSConfig(tlsConfig)
|
||||
}
|
||||
|
||||
MQTTClient = mqtt.NewClient(opts)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user