changed to logrus
This commit is contained in:
parent
e711f6e5fe
commit
0a977fee87
|
@ -7,6 +7,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/AdguardTeam/dnsproxy/upstream"
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
||||||
|
|
||||||
"github.com/AdguardTeam/dnsproxy/proxy"
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
||||||
|
@ -97,21 +99,19 @@ func (s *Server) startInternal(config *ServerConfig) error {
|
||||||
s.ServerConfig = *config
|
s.ServerConfig = *config
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.dnsFilter == nil {
|
if s.dnsFilter != nil || s.dnsProxy != nil {
|
||||||
log.Printf("Creating dnsfilter")
|
return errors.New("DNS server is already started")
|
||||||
s.dnsFilter = dnsfilter.New(&s.Config)
|
}
|
||||||
// add rules only if they are enabled
|
|
||||||
if s.FilteringEnabled {
|
err := s.initDNSFilter()
|
||||||
// TODO: Handle error
|
if err != nil {
|
||||||
s.dnsFilter.AddRules(s.Filters)
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Loading stats from querylog")
|
log.Printf("Loading stats from querylog")
|
||||||
err := fillStatsFromQueryLog()
|
err = fillStatsFromQueryLog()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to load stats from querylog: %s", err)
|
return errorx.Decorate(err, "failed to load stats from querylog")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
|
@ -139,12 +139,23 @@ func (s *Server) startInternal(config *ServerConfig) error {
|
||||||
proxyConfig.Upstreams = defaultValues.Upstreams
|
proxyConfig.Upstreams = defaultValues.Upstreams
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Don't let call Start the second time
|
// Initialize and start the DNS proxy
|
||||||
// Initialize the DNS proxy
|
|
||||||
s.dnsProxy = &proxy.Proxy{Config: proxyConfig}
|
s.dnsProxy = &proxy.Proxy{Config: proxyConfig}
|
||||||
|
return s.dnsProxy.Start()
|
||||||
|
}
|
||||||
|
|
||||||
err = s.dnsProxy.Start()
|
// Initializes the DNS filter
|
||||||
return err
|
func (s *Server) initDNSFilter() error {
|
||||||
|
log.Printf("Creating dnsfilter")
|
||||||
|
s.dnsFilter = dnsfilter.New(&s.Config)
|
||||||
|
// add rules only if they are enabled
|
||||||
|
if s.FilteringEnabled {
|
||||||
|
err := s.dnsFilter.AddRules(s.Filters)
|
||||||
|
if err != nil {
|
||||||
|
return errorx.Decorate(err, "could not initialize dnsfilter")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop stops the DNS server
|
// Stop stops the DNS server
|
||||||
|
|
|
@ -3,7 +3,6 @@ package dnsforward
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -12,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -5,11 +5,12 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/go-test/deep"
|
"github.com/go-test/deep"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package dnsforward
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -14,6 +13,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/bluele/gcache"
|
"github.com/bluele/gcache"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,11 +3,12 @@ package dnsforward
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
"github.com/AdguardTeam/AdGuardHome/dnsfilter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -13,6 +13,7 @@ require (
|
||||||
github.com/joomcode/errorx v0.1.0
|
github.com/joomcode/errorx v0.1.0
|
||||||
github.com/miekg/dns v1.1.1
|
github.com/miekg/dns v1.1.1
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
|
github.com/pkg/errors v0.8.0
|
||||||
github.com/shirou/gopsutil v2.18.10+incompatible
|
github.com/shirou/gopsutil v2.18.10+incompatible
|
||||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
|
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
|
||||||
github.com/sirupsen/logrus v1.2.0
|
github.com/sirupsen/logrus v1.2.0
|
||||||
|
|
Loading…
Reference in New Issue