Fix lint errors
This commit is contained in:
+2
-8
@@ -61,10 +61,7 @@ type ClientOptions struct {
|
||||
}
|
||||
|
||||
func NewClient(options ClientOptions) *Client {
|
||||
cacheCapacity := options.CacheCapacity
|
||||
if cacheCapacity < 1024 {
|
||||
cacheCapacity = 1024
|
||||
}
|
||||
cacheCapacity := max(options.CacheCapacity, 1024)
|
||||
client := &Client{
|
||||
ctx: options.Context,
|
||||
timeout: options.Timeout,
|
||||
@@ -426,10 +423,7 @@ func (c *Client) loadResponse(question dns.Question, transport adapter.DNSTransp
|
||||
c.cache.Remove(key)
|
||||
return nil, 0, false
|
||||
}
|
||||
nowTTL := int(expireAt.Sub(timeNow).Seconds())
|
||||
if nowTTL < 0 {
|
||||
nowTTL = 0
|
||||
}
|
||||
nowTTL := max(int(expireAt.Sub(timeNow).Seconds()), 0)
|
||||
response = response.Copy()
|
||||
normalizeTTL(response, uint32(nowTTL))
|
||||
return response, nowTTL, false
|
||||
|
||||
@@ -1011,33 +1011,6 @@ func lookupDNSRuleSetMetadata(router adapter.Router, tag string, metadataOverrid
|
||||
return ruleSet.Metadata(), nil
|
||||
}
|
||||
|
||||
func referencedDNSRuleSetTags(rules []option.DNSRule) []string {
|
||||
tagMap := make(map[string]bool)
|
||||
var walkRule func(rule option.DNSRule)
|
||||
walkRule = func(rule option.DNSRule) {
|
||||
switch rule.Type {
|
||||
case "", C.RuleTypeDefault:
|
||||
for _, tag := range rule.DefaultOptions.RuleSet {
|
||||
tagMap[tag] = true
|
||||
}
|
||||
case C.RuleTypeLogical:
|
||||
for _, subRule := range rule.LogicalOptions.Rules {
|
||||
walkRule(subRule)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, rule := range rules {
|
||||
walkRule(rule)
|
||||
}
|
||||
tags := make([]string, 0, len(tagMap))
|
||||
for tag := range tagMap {
|
||||
if tag != "" {
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
func validateLegacyDNSModeDisabledRules(router adapter.Router, rules []option.DNSRule, metadataOverrides map[string]adapter.RuleSetMetadata) error {
|
||||
var seenEvaluate bool
|
||||
for i, rule := range rules {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -113,14 +112,6 @@ func (r *fakeRouter) RuleSet(tag string) (adapter.RuleSet, bool) {
|
||||
return ruleSet, loaded
|
||||
}
|
||||
|
||||
func (r *fakeRouter) setRuleSet(tag string, ruleSet adapter.RuleSet) {
|
||||
r.access.Lock()
|
||||
defer r.access.Unlock()
|
||||
if r.ruleSets == nil {
|
||||
r.ruleSets = make(map[string]adapter.RuleSet)
|
||||
}
|
||||
r.ruleSets[tag] = ruleSet
|
||||
}
|
||||
func (r *fakeRouter) Rules() []adapter.Rule { return nil }
|
||||
func (r *fakeRouter) NeedFindProcess() bool { return false }
|
||||
func (r *fakeRouter) NeedFindNeighbor() bool { return false }
|
||||
@@ -210,12 +201,6 @@ func (s *fakeRuleSet) updateMetadata(metadata adapter.RuleSetMetadata) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *fakeRuleSet) snapshotCallbacks() []adapter.RuleSetUpdateCallback {
|
||||
s.access.Lock()
|
||||
defer s.access.Unlock()
|
||||
return s.callbacks.Array()
|
||||
}
|
||||
|
||||
func (s *fakeRuleSet) refCount() int {
|
||||
s.access.Lock()
|
||||
defer s.access.Unlock()
|
||||
@@ -322,26 +307,6 @@ func newTestRouterWithContextAndLogger(t *testing.T, ctx context.Context, rules
|
||||
return router
|
||||
}
|
||||
|
||||
func waitForLogMessageContaining(t *testing.T, entries <-chan log.Entry, done <-chan struct{}, substring string) log.Entry {
|
||||
t.Helper()
|
||||
timeout := time.After(time.Second)
|
||||
for {
|
||||
select {
|
||||
case entry, ok := <-entries:
|
||||
if !ok {
|
||||
t.Fatal("log subscription closed")
|
||||
}
|
||||
if strings.Contains(entry.Message, substring) {
|
||||
return entry
|
||||
}
|
||||
case <-done:
|
||||
t.Fatal("log subscription closed")
|
||||
case <-timeout:
|
||||
t.Fatalf("timed out waiting for log message containing %q", substring)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fixedQuestion(name string, qType uint16) mDNS.Question {
|
||||
return mDNS.Question{
|
||||
Name: mDNS.Fqdn(name),
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//go:build darwin && !cgo
|
||||
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
|
||||
mDNS "github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func (t *Transport) systemExchange(ctx context.Context, message *mDNS.Msg) (*mDNS.Msg, error) {
|
||||
return nil, E.New(`local DNS server requires CGO on darwin, rebuild with CGO_ENABLED=1`)
|
||||
}
|
||||
Reference in New Issue
Block a user