Skip to content

Commit df3fb0c

Browse files
committed
Keep lines short
$ golines -w -m 120 --shorten-comments .
1 parent c043577 commit df3fb0c

29 files changed

+516
-93
lines changed

dnscrypt-proxy/coldstart.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i
116116
return false
117117
}
118118

119-
func addColdStartListener(proxy *Proxy, ipsMap *CaptivePortalMap, listenAddrStr string, cancelChannel chan struct{}) error {
119+
func addColdStartListener(
120+
proxy *Proxy,
121+
ipsMap *CaptivePortalMap,
122+
listenAddrStr string,
123+
cancelChannel chan struct{},
124+
) error {
120125
listenUDPAddr, err := net.ResolveUDPAddr("udp", listenAddrStr)
121126
if err != nil {
122127
return err

dnscrypt-proxy/config.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ func findConfigFile(configFile *string) (string, error) {
314314
func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
315315
foundConfigFile, err := findConfigFile(flags.ConfigFile)
316316
if err != nil {
317-
return fmt.Errorf("Unable to load the configuration file [%s] -- Maybe use the -config command-line switch?", *flags.ConfigFile)
317+
return fmt.Errorf(
318+
"Unable to load the configuration file [%s] -- Maybe use the -config command-line switch?",
319+
*flags.ConfigFile,
320+
)
318321
}
319322
config := newConfig()
320323
md, err := toml.DecodeFile(foundConfigFile, &config)
@@ -638,7 +641,9 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
638641
}
639642

640643
// Backwards compatibility
641-
config.BrokenImplementations.FragmentsBlocked = append(config.BrokenImplementations.FragmentsBlocked, config.BrokenImplementations.BrokenQueryPadding...)
644+
config.BrokenImplementations.FragmentsBlocked = append(
645+
config.BrokenImplementations.FragmentsBlocked,
646+
config.BrokenImplementations.BrokenQueryPadding...)
642647

643648
proxy.serversBlockingFragments = config.BrokenImplementations.FragmentsBlocked
644649

@@ -707,7 +712,9 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
707712
// if 'userName' is set and we are the parent process drop privilege and exit
708713
if len(proxy.userName) > 0 && !proxy.child {
709714
proxy.dropPrivilege(proxy.userName, FileDescriptors)
710-
return errors.New("Dropping privileges is not supporting on this operating system. Unset `user_name` in the configuration file")
715+
return errors.New(
716+
"Dropping privileges is not supporting on this operating system. Unset `user_name` in the configuration file",
717+
)
711718
}
712719
if !config.OfflineMode {
713720
if err := config.loadSources(proxy); err != nil {
@@ -727,8 +734,12 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
727734
hasSpecificRoutes := false
728735
for _, server := range proxy.registeredServers {
729736
if via, ok := (*proxy.routes)[server.name]; ok {
730-
if server.stamp.Proto != stamps.StampProtoTypeDNSCrypt && server.stamp.Proto != stamps.StampProtoTypeODoHTarget {
731-
dlog.Errorf("DNS anonymization is only supported with the DNSCrypt and ODoH protocols - Connections to [%v] cannot be anonymized", server.name)
737+
if server.stamp.Proto != stamps.StampProtoTypeDNSCrypt &&
738+
server.stamp.Proto != stamps.StampProtoTypeODoHTarget {
739+
dlog.Errorf(
740+
"DNS anonymization is only supported with the DNSCrypt and ODoH protocols - Connections to [%v] cannot be anonymized",
741+
server.name,
742+
)
732743
} else {
733744
dlog.Noticef("Anonymized DNS: routing [%v] via %v", server.name, via)
734745
}
@@ -757,7 +768,8 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) erro
757768
var hostAddr string
758769
hostAddr, port = ExtractHostAndPort(addrStr, port)
759770
addrs := make([]string, 0)
760-
if (registeredServer.stamp.Proto == stamps.StampProtoTypeDoH || registeredServer.stamp.Proto == stamps.StampProtoTypeODoHTarget) && len(registeredServer.stamp.ProviderName) > 0 {
771+
if (registeredServer.stamp.Proto == stamps.StampProtoTypeDoH || registeredServer.stamp.Proto == stamps.StampProtoTypeODoHTarget) &&
772+
len(registeredServer.stamp.ProviderName) > 0 {
761773
providerName := registeredServer.stamp.ProviderName
762774
var host string
763775
host, port = ExtractHostAndPort(providerName, port)
@@ -866,7 +878,16 @@ func (config *Config) loadSource(proxy *Proxy, cfgSourceName string, cfgSource *
866878
} else if cfgSource.RefreshDelay > 168 {
867879
cfgSource.RefreshDelay = 168
868880
}
869-
source, err := NewSource(cfgSourceName, proxy.xTransport, cfgSource.URLs, cfgSource.MinisignKeyStr, cfgSource.CacheFile, cfgSource.FormatStr, time.Duration(cfgSource.RefreshDelay)*time.Hour, cfgSource.Prefix)
881+
source, err := NewSource(
882+
cfgSourceName,
883+
proxy.xTransport,
884+
cfgSource.URLs,
885+
cfgSource.MinisignKeyStr,
886+
cfgSource.CacheFile,
887+
cfgSource.FormatStr,
888+
time.Duration(cfgSource.RefreshDelay)*time.Hour,
889+
cfgSource.Prefix,
890+
)
870891
if err != nil {
871892
if len(source.in) <= 0 {
872893
dlog.Criticalf("Unable to retrieve source [%s]: [%s]", cfgSourceName, err)
@@ -894,7 +915,10 @@ func cdFileDir(fileName string) error {
894915
func cdLocal() {
895916
exeFileName, err := os.Executable()
896917
if err != nil {
897-
dlog.Warnf("Unable to determine the executable directory: [%s] -- You will need to specify absolute paths in the configuration file", err)
918+
dlog.Warnf(
919+
"Unable to determine the executable directory: [%s] -- You will need to specify absolute paths in the configuration file",
920+
err,
921+
)
898922
} else if err := os.Chdir(filepath.Dir(exeFileName)); err != nil {
899923
dlog.Warnf("Unable to change working directory to [%s]: %s", exeFileName, err)
900924
}

dnscrypt-proxy/crypto.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ func unpad(packet []byte) ([]byte, error) {
4545
}
4646
}
4747

48-
func ComputeSharedKey(cryptoConstruction CryptoConstruction, secretKey *[32]byte, serverPk *[32]byte, providerName *string) (sharedKey [32]byte) {
48+
func ComputeSharedKey(
49+
cryptoConstruction CryptoConstruction,
50+
secretKey *[32]byte,
51+
serverPk *[32]byte,
52+
providerName *string,
53+
) (sharedKey [32]byte) {
4954
if cryptoConstruction == XChacha20Poly1305 {
5055
var err error
5156
sharedKey, err = xsecretbox.SharedKey(*secretKey, *serverPk)
@@ -68,7 +73,11 @@ func ComputeSharedKey(cryptoConstruction CryptoConstruction, secretKey *[32]byte
6873
return
6974
}
7075

71-
func (proxy *Proxy) Encrypt(serverInfo *ServerInfo, packet []byte, proto string) (sharedKey *[32]byte, encrypted []byte, clientNonce []byte, err error) {
76+
func (proxy *Proxy) Encrypt(
77+
serverInfo *ServerInfo,
78+
packet []byte,
79+
proto string,
80+
) (sharedKey *[32]byte, encrypted []byte, clientNonce []byte, err error) {
7281
nonce, clientNonce := make([]byte, NonceSize), make([]byte, HalfNonceSize)
7382
crypto_rand.Read(clientNonce)
7483
copy(nonce, clientNonce)
@@ -120,7 +129,12 @@ func (proxy *Proxy) Encrypt(serverInfo *ServerInfo, packet []byte, proto string)
120129
return
121130
}
122131

123-
func (proxy *Proxy) Decrypt(serverInfo *ServerInfo, sharedKey *[32]byte, encrypted []byte, nonce []byte) ([]byte, error) {
132+
func (proxy *Proxy) Decrypt(
133+
serverInfo *ServerInfo,
134+
sharedKey *[32]byte,
135+
encrypted []byte,
136+
nonce []byte,
137+
) ([]byte, error) {
124138
serverMagicLen := len(ServerMagic)
125139
responseHeaderLen := serverMagicLen + NonceSize
126140
if len(encrypted) < responseHeaderLen+TagSize+int(MinDNSPacketSize) ||

dnscrypt-proxy/dnscrypt_certs.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ type CertInfo struct {
2020
ForwardSecurity bool
2121
}
2222

23-
func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk ed25519.PublicKey, serverAddress string, providerName string, isNew bool, relay *DNSCryptRelay, knownBugs ServerBugs) (CertInfo, int, bool, error) {
23+
func FetchCurrentDNSCryptCert(
24+
proxy *Proxy,
25+
serverName *string,
26+
proto string,
27+
pk ed25519.PublicKey,
28+
serverAddress string,
29+
providerName string,
30+
isNew bool,
31+
relay *DNSCryptRelay,
32+
knownBugs ServerBugs,
33+
) (CertInfo, int, bool, error) {
2434
if len(pk) != ed25519.PublicKeySize {
2535
return CertInfo{}, 0, false, errors.New("Invalid public key length")
2636
}
@@ -34,7 +44,11 @@ func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk
3444
query.SetQuestion(providerName, dns.TypeTXT)
3545
if !strings.HasPrefix(providerName, "2.dnscrypt-cert.") {
3646
if relay != nil && !proxy.anonDirectCertFallback {
37-
dlog.Warnf("[%v] uses a non-standard provider name, enable direct cert fallback to use with a relay ('%v' doesn't start with '2.dnscrypt-cert.')", *serverName, providerName)
47+
dlog.Warnf(
48+
"[%v] uses a non-standard provider name, enable direct cert fallback to use with a relay ('%v' doesn't start with '2.dnscrypt-cert.')",
49+
*serverName,
50+
providerName,
51+
)
3852
} else {
3953
dlog.Warnf("[%v] uses a non-standard provider name ('%v' doesn't start with '2.dnscrypt-cert.')", *serverName, providerName)
4054
relay = nil
@@ -44,7 +58,15 @@ func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk
4458
if knownBugs.fragmentsBlocked {
4559
tryFragmentsSupport = false
4660
}
47-
in, rtt, fragmentsBlocked, err := DNSExchange(proxy, proto, &query, serverAddress, relay, serverName, tryFragmentsSupport)
61+
in, rtt, fragmentsBlocked, err := DNSExchange(
62+
proxy,
63+
proto,
64+
&query,
65+
serverAddress,
66+
relay,
67+
serverName,
68+
tryFragmentsSupport,
69+
)
4870
if err != nil {
4971
dlog.Noticef("[%s] TIMEOUT", *serverName)
5072
return CertInfo{}, 0, fragmentsBlocked, err
@@ -95,10 +117,17 @@ func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk
95117
}
96118
ttl := tsEnd - tsBegin
97119
if ttl > 86400*7 {
98-
dlog.Infof("[%v] the key validity period for this server is excessively long (%d days), significantly reducing reliability and forward security.", *serverName, ttl/86400)
120+
dlog.Infof(
121+
"[%v] the key validity period for this server is excessively long (%d days), significantly reducing reliability and forward security.",
122+
*serverName,
123+
ttl/86400,
124+
)
99125
daysLeft := (tsEnd - now) / 86400
100126
if daysLeft < 1 {
101-
dlog.Criticalf("[%v] certificate will expire today -- Switch to a different resolver as soon as possible", *serverName)
127+
dlog.Criticalf(
128+
"[%v] certificate will expire today -- Switch to a different resolver as soon as possible",
129+
*serverName,
130+
)
102131
} else if daysLeft <= 7 {
103132
dlog.Warnf("[%v] certificate is about to expire -- if you don't manage this server, tell the server operator about it", *serverName)
104133
} else if daysLeft <= 30 {
@@ -112,7 +141,13 @@ func FetchCurrentDNSCryptCert(proxy *Proxy, serverName *string, proto string, pk
112141
}
113142
if !proxy.certIgnoreTimestamp {
114143
if now > tsEnd || now < tsBegin {
115-
dlog.Debugf("[%v] Certificate not valid at the current date (now: %v is not in [%v..%v])", *serverName, now, tsBegin, tsEnd)
144+
dlog.Debugf(
145+
"[%v] Certificate not valid at the current date (now: %v is not in [%v..%v])",
146+
*serverName,
147+
now,
148+
tsBegin,
149+
tsEnd,
150+
)
116151
continue
117152
}
118153
}

dnscrypt-proxy/dnsutils.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func NormalizeQName(str string) (string, error) {
135135
}
136136

137137
func getMinTTL(msg *dns.Msg, minTTL uint32, maxTTL uint32, cacheNegMinTTL uint32, cacheNegMaxTTL uint32) time.Duration {
138-
if (msg.Rcode != dns.RcodeSuccess && msg.Rcode != dns.RcodeNameError) || (len(msg.Answer) <= 0 && len(msg.Ns) <= 0) {
138+
if (msg.Rcode != dns.RcodeSuccess && msg.Rcode != dns.RcodeNameError) ||
139+
(len(msg.Answer) <= 0 && len(msg.Ns) <= 0) {
139140
return time.Duration(cacheNegMinTTL) * time.Second
140141
}
141142
var ttl uint32
@@ -304,7 +305,15 @@ type DNSExchangeResponse struct {
304305
err error
305306
}
306307

307-
func DNSExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress string, relay *DNSCryptRelay, serverName *string, tryFragmentsSupport bool) (*dns.Msg, time.Duration, bool, error) {
308+
func DNSExchange(
309+
proxy *Proxy,
310+
proto string,
311+
query *dns.Msg,
312+
serverAddress string,
313+
relay *DNSCryptRelay,
314+
serverName *string,
315+
tryFragmentsSupport bool,
316+
) (*dns.Msg, time.Duration, bool, error) {
308317
for {
309318
cancelChannel := make(chan struct{})
310319
channel := make(chan DNSExchangeResponse)
@@ -375,12 +384,23 @@ func DNSExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress strin
375384
}
376385
return nil, 0, false, err
377386
}
378-
dlog.Infof("Unable to get the public key for [%v] via relay [%v], retrying over a direct connection", *serverName, relay.RelayUDPAddr.IP)
387+
dlog.Infof(
388+
"Unable to get the public key for [%v] via relay [%v], retrying over a direct connection",
389+
*serverName,
390+
relay.RelayUDPAddr.IP,
391+
)
379392
relay = nil
380393
}
381394
}
382395

383-
func _dnsExchange(proxy *Proxy, proto string, query *dns.Msg, serverAddress string, relay *DNSCryptRelay, paddedLen int) DNSExchangeResponse {
396+
func _dnsExchange(
397+
proxy *Proxy,
398+
proto string,
399+
query *dns.Msg,
400+
serverAddress string,
401+
relay *DNSCryptRelay,
402+
paddedLen int,
403+
) DNSExchangeResponse {
384404
var packet []byte
385405
var rtt time.Duration
386406

dnscrypt-proxy/estimators.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ type QuestionSizeEstimator struct {
1717
}
1818

1919
func NewQuestionSizeEstimator() QuestionSizeEstimator {
20-
return QuestionSizeEstimator{minQuestionSize: InitialMinQuestionSize, ewma: ewma.NewMovingAverage(SizeEstimatorEwmaDecay)}
20+
return QuestionSizeEstimator{
21+
minQuestionSize: InitialMinQuestionSize,
22+
ewma: ewma.NewMovingAverage(SizeEstimatorEwmaDecay),
23+
}
2124
}
2225

2326
func (questionSizeEstimator *QuestionSizeEstimator) MinQuestionSize() int {

dnscrypt-proxy/fuzzing_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ func FuzzParseODoHTargetConfigs(f *testing.F) {
2323
func FuzzParseStampParser(f *testing.F) {
2424
f.Add("sdns://AgcAAAAAAAAACzEwNC4yMS42Ljc4AA1kb2guY3J5cHRvLnN4Ci9kbnMtcXVlcnk")
2525
f.Add("sdns://AgcAAAAAAAAAGlsyNjA2OjQ3MDA6MzAzNzo6NjgxNTo2NGVdABJkb2gtaXB2Ni5jcnlwdG8uc3gKL2Rucy1xdWVyeQ")
26-
f.Add("sdns://AQcAAAAAAAAADTUxLjE1LjEyMi4yNTAg6Q3ZfapcbHgiHKLF7QFoli0Ty1Vsz3RXs1RUbxUrwZAcMi5kbnNjcnlwdC1jZXJ0LnNjYWxld2F5LWFtcw")
27-
f.Add("sdns://AQcAAAAAAAAAFlsyMDAxOmJjODoxODIwOjUwZDo6MV0g6Q3ZfapcbHgiHKLF7QFoli0Ty1Vsz3RXs1RUbxUrwZAcMi5kbnNjcnlwdC1jZXJ0LnNjYWxld2F5LWFtcw")
26+
f.Add(
27+
"sdns://AQcAAAAAAAAADTUxLjE1LjEyMi4yNTAg6Q3ZfapcbHgiHKLF7QFoli0Ty1Vsz3RXs1RUbxUrwZAcMi5kbnNjcnlwdC1jZXJ0LnNjYWxld2F5LWFtcw",
28+
)
29+
f.Add(
30+
"sdns://AQcAAAAAAAAAFlsyMDAxOmJjODoxODIwOjUwZDo6MV0g6Q3ZfapcbHgiHKLF7QFoli0Ty1Vsz3RXs1RUbxUrwZAcMi5kbnNjcnlwdC1jZXJ0LnNjYWxld2F5LWFtcw",
31+
)
2832
f.Add("sdns://gQ8xNjMuMTcyLjE4MC4xMjU")
2933
f.Add("sdns://BQcAAAAAAAAADm9kb2guY3J5cHRvLnN4Ci9kbnMtcXVlcnk")
3034
f.Add("sdns://hQcAAAAAAAAAACCi3jNJDEdtNW4tvHN8J3lpIklSa2Wrj7qaNCgEgci9_BpvZG9oLXJlbGF5LmVkZ2Vjb21wdXRlLmFwcAEv")

dnscrypt-proxy/local-doh.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,25 @@ func (proxy *Proxy) localDoHListener(acceptPc *net.TCPListener) {
114114
}
115115

116116
func dohPaddedLen(unpaddedLen int) int {
117-
boundaries := [...]int{64, 128, 192, 256, 320, 384, 512, 704, 768, 896, 960, 1024, 1088, 1152, 2688, 4080, MaxDNSPacketSize}
117+
boundaries := [...]int{
118+
64,
119+
128,
120+
192,
121+
256,
122+
320,
123+
384,
124+
512,
125+
704,
126+
768,
127+
896,
128+
960,
129+
1024,
130+
1088,
131+
1152,
132+
2688,
133+
4080,
134+
MaxDNSPacketSize,
135+
}
118136
for _, boundary := range boundaries {
119137
if boundary >= unpaddedLen {
120138
return boundary

dnscrypt-proxy/logger.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ func Logger(logMaxSize int, logMaxAge int, logMaxBackups int, fileName string) i
2222
}
2323
return fp
2424
}
25-
logger := &lumberjack.Logger{LocalTime: true, MaxSize: logMaxSize, MaxAge: logMaxAge, MaxBackups: logMaxBackups, Filename: fileName, Compress: true}
25+
logger := &lumberjack.Logger{
26+
LocalTime: true,
27+
MaxSize: logMaxSize,
28+
MaxAge: logMaxAge,
29+
MaxBackups: logMaxBackups,
30+
Filename: fileName,
31+
Compress: true,
32+
}
2633

2734
return logger
2835
}

dnscrypt-proxy/netprobe_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ func NetProbe(proxy *Proxy, address string, timeout int) error {
3232
pc, err := net.DialUDP("udp", nil, remoteUDPAddr)
3333
if err == nil {
3434
// Write at least 1 byte. This ensures that sockets are ready to use for writing.
35-
// Windows specific: during the system startup, sockets can be created but the underlying buffers may not be setup yet. If this is the case
36-
// Write fails with WSAENOBUFS: "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full"
35+
// Windows specific: during the system startup, sockets can be created but the underlying buffers may not be
36+
// setup yet. If this is the case Write fails with WSAENOBUFS: "An operation on a socket could not be
37+
// performed because the system lacked sufficient buffer space or because a queue was full"
3738
_, err = pc.Write([]byte{0})
3839
}
3940
if err != nil {

0 commit comments

Comments
 (0)