Skip to content

Commit 9a3cd91

Browse files
committed
Use dlog for everything
1 parent 735213f commit 9a3cd91

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

dnscrypt-proxy/certs.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/golang/glog"
10+
"github.com/jedisct1/dlog"
1111
"github.com/jedisct1/xsecretbox"
1212
"github.com/miekg/dns"
1313
"golang.org/x/crypto/ed25519"
@@ -41,15 +41,15 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
4141
for _, answerRr := range in.Answer {
4242
binCert, err := packTxtString(strings.Join(answerRr.(*dns.TXT).Txt, ""))
4343
if err != nil {
44-
glog.Warningf("[%v] Unable to unpack the certificate", providerName)
44+
dlog.Warnf("[%v] Unable to unpack the certificate", providerName)
4545
continue
4646
}
4747
if len(binCert) < 124 {
48-
glog.Warningf("[%v] Certificate too short", providerName)
48+
dlog.Warnf("[%v] Certificate too short", providerName)
4949
continue
5050
}
5151
if !bytes.Equal(binCert[:4], CertMagic[:4]) {
52-
glog.Warningf("[%v] Invalid cert magic", providerName)
52+
dlog.Warnf("[%v] Invalid cert magic", providerName)
5353
continue
5454
}
5555
cryptoConstruction := CryptoConstruction(0)
@@ -59,36 +59,36 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
5959
case 0x0002:
6060
cryptoConstruction = XChacha20Poly1305
6161
default:
62-
glog.Infof("[%v] Unsupported crypto construction", providerName)
62+
dlog.Infof("[%v] Unsupported crypto construction", providerName)
6363
continue
6464
}
6565
signature := binCert[8:72]
6666
signed := binCert[72:]
6767
if !ed25519.Verify(pk, signed, signature) {
68-
glog.Warningf("[%v] Incorrect signature", providerName)
68+
dlog.Warnf("[%v] Incorrect signature", providerName)
6969
continue
7070
}
7171
serial := binary.BigEndian.Uint32(binCert[112:116])
7272
tsBegin := binary.BigEndian.Uint32(binCert[116:120])
7373
tsEnd := binary.BigEndian.Uint32(binCert[120:124])
7474
if now > tsEnd || now < tsBegin {
75-
glog.Infof("[%v] Certificate not valid at the current date", providerName)
75+
dlog.Infof("[%v] Certificate not valid at the current date", providerName)
7676
continue
7777
}
7878
if serial < highestSerial {
79-
glog.Infof("[%v] Superseded by a previous certificate", providerName)
79+
dlog.Infof("[%v] Superseded by a previous certificate", providerName)
8080
continue
8181
}
8282
if serial == highestSerial {
8383
if cryptoConstruction < certInfo.CryptoConstruction {
84-
glog.Infof("[%v] Keeping the previous, preferred crypto construction", providerName)
84+
dlog.Infof("[%v] Keeping the previous, preferred crypto construction", providerName)
8585
continue
8686
} else {
87-
glog.Infof("[%v] Upgrading the construction from %v to %v", providerName, certInfo.CryptoConstruction, cryptoConstruction)
87+
dlog.Infof("[%v] Upgrading the construction from %v to %v", providerName, certInfo.CryptoConstruction, cryptoConstruction)
8888
}
8989
}
9090
if cryptoConstruction != XChacha20Poly1305 && cryptoConstruction != XSalsa20Poly1305 {
91-
glog.Warningf("[%v] Cryptographic construction %v not supported", providerName, cryptoConstruction)
91+
dlog.Warnf("[%v] Cryptographic construction %v not supported", providerName, cryptoConstruction)
9292
continue
9393
}
9494
var serverPk [32]byte
@@ -97,7 +97,7 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
9797
if cryptoConstruction == XChacha20Poly1305 {
9898
sharedKey, err = xsecretbox.SharedKey(proxy.proxySecretKey, serverPk)
9999
if err != nil {
100-
glog.Warningf("[%v] Weak public key", providerName)
100+
dlog.Errorf("[%v] Weak public key", providerName)
101101
continue
102102
}
103103
} else {
@@ -108,7 +108,7 @@ func FetchCurrentCert(proxy *Proxy, proto string, pk ed25519.PublicKey, serverAd
108108
certInfo.CryptoConstruction = cryptoConstruction
109109
copy(certInfo.ServerPk[:], serverPk[:])
110110
copy(certInfo.MagicQuery[:], binCert[104:112])
111-
glog.Infof("[%v] Valid cert found: [%x]", providerName, certInfo.ServerPk)
111+
dlog.Noticef("[%v] Valid cert found: [%x]", providerName, certInfo.ServerPk)
112112
}
113113
if certInfo.CryptoConstruction == UndefinedConstruction {
114114
return certInfo, errors.New("No useable certificate found")

dnscrypt-proxy/config.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"time"
88

99
"github.com/BurntSushi/toml"
10-
"github.com/golang/glog"
10+
"github.com/jedisct1/dlog"
1111
)
1212

1313
type Config struct {
@@ -53,7 +53,6 @@ func ConfigLoad(proxy *Proxy, config_file string) error {
5353
flag.Parse()
5454
config := newConfig()
5555
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
56-
glog.Error(err)
5756
return err
5857
}
5958
proxy.timeout = time.Duration(config.Timeout) * time.Millisecond
@@ -89,7 +88,7 @@ func ConfigLoad(proxy *Proxy, config_file string) error {
8988
var stamp ServerStamp
9089
var err error
9190
if len(serverConfig.Stamp) > 0 {
92-
panic("Stamps are not implemented yet")
91+
dlog.Fatal("Stamps are not implemented yet")
9392
} else {
9493
stamp, err = NewServerStampFromLegacy(serverConfig.Address, serverConfig.PublicKey, serverConfig.ProviderName)
9594
if err != nil {

dnscrypt-proxy/main.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net"
66
"time"
77

8-
"github.com/golang/glog"
8+
"github.com/jedisct1/dlog"
99
"golang.org/x/crypto/curve25519"
1010
)
1111

@@ -29,9 +29,10 @@ type Proxy struct {
2929
}
3030

3131
func main() {
32+
dlog.Init("dnscrypt-proxy", dlog.SeverityNotice)
3233
proxy := Proxy{}
3334
if err := ConfigLoad(&proxy, "dnscrypt-proxy.toml"); err != nil {
34-
panic(err)
35+
dlog.Fatal(err)
3536
}
3637
if proxy.daemonize {
3738
Daemonize()
@@ -42,7 +43,7 @@ func main() {
4243
func (proxy *Proxy) StartProxy() {
4344
proxy.questionSizeEstimator = NewQuestionSizeEstimator()
4445
if _, err := rand.Read(proxy.proxySecretKey[:]); err != nil {
45-
glog.Fatal(err)
46+
dlog.Fatal(err)
4647
}
4748
curve25519.ScalarBaseMult(&proxy.proxyPublicKey, &proxy.proxySecretKey)
4849
for _, registeredServer := range proxy.registeredServers {
@@ -51,19 +52,20 @@ func (proxy *Proxy) StartProxy() {
5152
for _, listenAddrStr := range proxy.listenAddresses {
5253
listenUDPAddr, err := net.ResolveUDPAddr("udp", listenAddrStr)
5354
if err != nil {
54-
glog.Fatal(err)
55+
dlog.Fatal(err)
5556
}
5657
listenTCPAddr, err := net.ResolveTCPAddr("tcp", listenAddrStr)
5758
if err != nil {
58-
glog.Fatal(err)
59+
dlog.Fatal(err)
5960
}
6061
if err := proxy.udpListener(listenUDPAddr); err != nil {
61-
glog.Fatal(err)
62+
dlog.Fatal(err)
6263
}
6364
if err := proxy.tcpListener(listenTCPAddr); err != nil {
64-
glog.Fatal(err)
65+
dlog.Fatal(err)
6566
}
6667
}
68+
dlog.Notice("dnscrypt-proxy is ready")
6769
for {
6870
time.Sleep(proxy.certRefreshDelay)
6971
proxy.serversInfo.refresh(proxy)
@@ -77,7 +79,7 @@ func (proxy *Proxy) udpListener(listenAddr *net.UDPAddr) error {
7779
}
7880
go func() {
7981
defer clientPc.Close()
80-
glog.Infof("Now listening to %v [UDP]", listenAddr)
82+
dlog.Noticef("Now listening to %v [UDP]", listenAddr)
8183
for {
8284
buffer := make([]byte, MaxDNSPacketSize-1)
8385
length, clientAddr, err := clientPc.ReadFrom(buffer)
@@ -100,7 +102,7 @@ func (proxy *Proxy) tcpListener(listenAddr *net.TCPAddr) error {
100102
}
101103
go func() {
102104
defer acceptPc.Close()
103-
glog.Infof("Now listening to %v [TCP]", listenAddr)
105+
dlog.Noticef("Now listening to %v [TCP]", listenAddr)
104106
for {
105107
clientPc, err := acceptPc.Accept()
106108
if err != nil {

dnscrypt-proxy/serversInfo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/VividCortex/ewma"
12-
"github.com/golang/glog"
12+
"github.com/jedisct1/dlog"
1313
"golang.org/x/crypto/ed25519"
1414
)
1515

@@ -76,7 +76,7 @@ func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp
7676
}
7777

7878
func (serversInfo *ServersInfo) refresh(proxy *Proxy) {
79-
glog.Infof("Refreshing certificates")
79+
dlog.Infof("Refreshing certificates")
8080
serversInfo.RLock()
8181
registeredServers := serversInfo.registeredServers
8282
serversInfo.RUnlock()
@@ -107,7 +107,7 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
107107
func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp ServerStamp) (ServerInfo, error) {
108108
serverPk, err := hex.DecodeString(strings.Replace(stamp.serverPkStr, ":", "", -1))
109109
if err != nil || len(serverPk) != ed25519.PublicKeySize {
110-
glog.Fatal("Unsupported public key: [%v]", serverPk)
110+
dlog.Fatalf("Unsupported public key: [%v]", serverPk)
111111
}
112112
certInfo, err := FetchCurrentCert(proxy, proxy.mainProto, serverPk, stamp.serverAddrStr, stamp.providerName)
113113
if err != nil {

glide.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import:
66
version: ^1.1.1
77
- package: github.com/VividCortex/godaemon
88
- package: github.com/hashicorp/golang-lru
9+
- package: github.com/jedisct1/dlog
910
- package: github.com/jedisct1/xsecretbox
1011
- package: github.com/miekg/dns
1112
version: ^1.0.3

0 commit comments

Comments
 (0)