Skip to content

Commit 735213f

Browse files
committed
Use glog
1 parent 80e5bb5 commit 735213f

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

dnscrypt-proxy/certs.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"bytes"
55
"encoding/binary"
66
"errors"
7-
"log"
87
"strings"
98
"time"
109

10+
"github.com/golang/glog"
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-
log.Printf("[%v] Unable to unpack the certificate\n", providerName)
44+
glog.Warningf("[%v] Unable to unpack the certificate", providerName)
4545
continue
4646
}
4747
if len(binCert) < 124 {
48-
log.Printf("[%v] Certificate too short\n", providerName)
48+
glog.Warningf("[%v] Certificate too short", providerName)
4949
continue
5050
}
5151
if !bytes.Equal(binCert[:4], CertMagic[:4]) {
52-
log.Printf("[%v] Invalid cert magic\n", providerName)
52+
glog.Warningf("[%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-
log.Printf("[%v] Unsupported crypto construction\n", providerName)
62+
glog.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-
log.Printf("[%v] Incorrect signature\n", providerName)
68+
glog.Warningf("[%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-
log.Printf("[%v] Certificate not valid at the current date\n", providerName)
75+
glog.Infof("[%v] Certificate not valid at the current date", providerName)
7676
continue
7777
}
7878
if serial < highestSerial {
79-
log.Printf("[%v] Superseded by a previous certificate\n", providerName)
79+
glog.Infof("[%v] Superseded by a previous certificate", providerName)
8080
continue
8181
}
8282
if serial == highestSerial {
8383
if cryptoConstruction < certInfo.CryptoConstruction {
84-
log.Printf("[%v] Keeping the previous, preferred crypto construction", providerName)
84+
glog.Infof("[%v] Keeping the previous, preferred crypto construction", providerName)
8585
continue
8686
} else {
87-
log.Printf("[%v] Upgrading the construction from %v to %v\n", providerName, certInfo.CryptoConstruction, cryptoConstruction)
87+
glog.Infof("[%v] Upgrading the construction from %v to %v", providerName, certInfo.CryptoConstruction, cryptoConstruction)
8888
}
8989
}
9090
if cryptoConstruction != XChacha20Poly1305 && cryptoConstruction != XSalsa20Poly1305 {
91-
log.Printf("[%v] Cryptographic construction %v not supported\n", providerName, cryptoConstruction)
91+
glog.Warningf("[%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-
log.Printf("[%v] Weak public key\n", providerName)
100+
glog.Warningf("[%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-
log.Printf("[%v] Valid cert found: %x\n", providerName, certInfo.ServerPk)
111+
glog.Infof("[%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-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"errors"
55
"flag"
66
"fmt"
7-
"log"
87
"time"
98

109
"github.com/BurntSushi/toml"
10+
"github.com/golang/glog"
1111
)
1212

1313
type Config struct {
@@ -53,7 +53,7 @@ func ConfigLoad(proxy *Proxy, config_file string) error {
5353
flag.Parse()
5454
config := newConfig()
5555
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
56-
log.Println(err)
56+
glog.Error(err)
5757
return err
5858
}
5959
proxy.timeout = time.Duration(config.Timeout) * time.Millisecond

dnscrypt-proxy/main.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package main
22

33
import (
44
"crypto/rand"
5-
"fmt"
6-
"log"
75
"net"
86
"time"
97

8+
"github.com/golang/glog"
109
"golang.org/x/crypto/curve25519"
1110
)
1211

@@ -30,7 +29,6 @@ type Proxy struct {
3029
}
3130

3231
func main() {
33-
log.SetFlags(0)
3432
proxy := Proxy{}
3533
if err := ConfigLoad(&proxy, "dnscrypt-proxy.toml"); err != nil {
3634
panic(err)
@@ -44,7 +42,7 @@ func main() {
4442
func (proxy *Proxy) StartProxy() {
4543
proxy.questionSizeEstimator = NewQuestionSizeEstimator()
4644
if _, err := rand.Read(proxy.proxySecretKey[:]); err != nil {
47-
log.Fatal(err)
45+
glog.Fatal(err)
4846
}
4947
curve25519.ScalarBaseMult(&proxy.proxyPublicKey, &proxy.proxySecretKey)
5048
for _, registeredServer := range proxy.registeredServers {
@@ -53,17 +51,17 @@ func (proxy *Proxy) StartProxy() {
5351
for _, listenAddrStr := range proxy.listenAddresses {
5452
listenUDPAddr, err := net.ResolveUDPAddr("udp", listenAddrStr)
5553
if err != nil {
56-
log.Fatal(err)
54+
glog.Fatal(err)
5755
}
5856
listenTCPAddr, err := net.ResolveTCPAddr("tcp", listenAddrStr)
5957
if err != nil {
60-
log.Fatal(err)
58+
glog.Fatal(err)
6159
}
6260
if err := proxy.udpListener(listenUDPAddr); err != nil {
63-
log.Fatal(err)
61+
glog.Fatal(err)
6462
}
6563
if err := proxy.tcpListener(listenTCPAddr); err != nil {
66-
log.Fatal(err)
64+
glog.Fatal(err)
6765
}
6866
}
6967
for {
@@ -79,7 +77,7 @@ func (proxy *Proxy) udpListener(listenAddr *net.UDPAddr) error {
7977
}
8078
go func() {
8179
defer clientPc.Close()
82-
fmt.Printf("Now listening to %v [UDP]\n", listenAddr)
80+
glog.Infof("Now listening to %v [UDP]", listenAddr)
8381
for {
8482
buffer := make([]byte, MaxDNSPacketSize-1)
8583
length, clientAddr, err := clientPc.ReadFrom(buffer)
@@ -102,7 +100,7 @@ func (proxy *Proxy) tcpListener(listenAddr *net.TCPAddr) error {
102100
}
103101
go func() {
104102
defer acceptPc.Close()
105-
fmt.Printf("Now listening to %v [TCP]\n", listenAddr)
103+
glog.Infof("Now listening to %v [TCP]", listenAddr)
106104
for {
107105
clientPc, err := acceptPc.Accept()
108106
if err != nil {

dnscrypt-proxy/serversInfo.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package main
22

33
import (
44
"encoding/hex"
5-
"fmt"
6-
"log"
75
"math/rand"
86
"net"
97
"strings"
108
"sync"
119
"time"
1210

1311
"github.com/VividCortex/ewma"
12+
"github.com/golang/glog"
1413
"golang.org/x/crypto/ed25519"
1514
)
1615

@@ -77,7 +76,7 @@ func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp
7776
}
7877

7978
func (serversInfo *ServersInfo) refresh(proxy *Proxy) {
80-
fmt.Println("Refreshing certificates")
79+
glog.Infof("Refreshing certificates")
8180
serversInfo.RLock()
8281
registeredServers := serversInfo.registeredServers
8382
serversInfo.RUnlock()
@@ -108,7 +107,7 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
108107
func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp ServerStamp) (ServerInfo, error) {
109108
serverPk, err := hex.DecodeString(strings.Replace(stamp.serverPkStr, ":", "", -1))
110109
if err != nil || len(serverPk) != ed25519.PublicKeySize {
111-
log.Fatal("Invalid public key")
110+
glog.Fatal("Unsupported public key: [%v]", serverPk)
112111
}
113112
certInfo, err := FetchCurrentCert(proxy, proxy.mainProto, serverPk, stamp.serverAddrStr, stamp.providerName)
114113
if err != nil {

0 commit comments

Comments
 (0)