Skip to content

Commit

Permalink
Use internal DNS cache
Browse files Browse the repository at this point in the history
Otherwise ANY call will call a DNS resolve.
  • Loading branch information
misery committed Feb 13, 2023
1 parent f45cdb4 commit 205e02a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All parameters can be passed via cmdline arguments or via environment variables.
- ``-polling`` / ``POLLING`` Refresh interval in seconds. (optional, 300 seconds as default)
- ``-tempchange`` / ``TEMPCHANGE`` Temperature change warning in hours. (optional, 12 hours as default)
- ``-full`` / ``FULL`` Provide any information to broker, most times this is not necessary. (optional)
- ``-dns`` / ``DNS`` Use internal DNS cache. (optional, default: true)
- ``-verbose`` / ``VERBOSE`` Provide more verbose logging. (optional)


Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/misery/HeatingMqttBridge

require github.com/eclipse/paho.mqtt.golang v1.4.2
require github.com/ncruces/go-dns v1.2.0

require (
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/ncruces/go-dns v1.2.0 h1:eSiRR6vRBaXtTbvS8gy4/RFk5ahO3W5VCipA5iBTylc=
github.com/ncruces/go-dns v1.2.0/go.mod h1:sZV4lxB+nXBYekemnR/EKewk8pZFTdFzF+LK2d7JPFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
"os"
Expand All @@ -42,6 +43,7 @@ import (
"time"

MQTT "github.com/eclipse/paho.mqtt.golang"
DNS "github.com/ncruces/go-dns"
)

var bridge *bridgeCfg
Expand Down Expand Up @@ -636,6 +638,7 @@ func createBridge() *bridgeCfg {
polling := flag.Int("polling", 300, "Refresh interval in seconds")
tempchange := flag.Int("tempchange", 12, "Temperature change warning in hours")
full := flag.Bool("full", false, "Provide full information to broker")
dnsCache := flag.Bool("dns", true, "Use internal DNS cache")
verbose := flag.Bool("verbose", false, "Provide verbose log information")
flag.Parse()

Expand All @@ -648,6 +651,7 @@ func createBridge() *bridgeCfg {
if *env {
setBoolParam(clean, "clean")
setBoolParam(full, "full")
setBoolParam(dnsCache, "dns")
setBoolParam(verbose, "verbose")

if !isFlagPassed("polling") {
Expand All @@ -671,6 +675,11 @@ func createBridge() *bridgeCfg {
*tempchange = 12
}

if *dnsCache {
log.Println("Use internal DNS cache")
net.DefaultResolver = DNS.NewCachingResolver(net.DefaultResolver)
}

return &bridgeCfg{
Client: MQTT.NewClient(createClientOptions(*broker, *user, *password, *clean, *topic)),
KeepRunning: make(chan bool),
Expand Down

0 comments on commit 205e02a

Please sign in to comment.