Skip to content

Commit

Permalink
fix: 🐛 default dns not work
Browse files Browse the repository at this point in the history
  • Loading branch information
import-yuefeng committed Aug 12, 2019
1 parent b47f69a commit 0de4b1e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
5 changes: 3 additions & 2 deletions config.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@
"DNSFilter": {
"HK-DNS": {
"IPNetworkFile": "",
"DomainFile": "configuration/hk.domain",
"DomainFile": "hk.domain",
"Matcher": "regex-list"
},
"CN-DNS": {
"IPNetworkFile": "",
"DomainFile": "configuration/cn.domain",
"DomainFile": "cn.domain",
"Matcher": "regex-list"
}
},
"DefaultDNSBundle":"HK-DNS",
"IPv6UseAlternativeDNS": false,
"HostsFile": "./hosts",
"MinimumTTL": 0,
Expand Down
1 change: 1 addition & 0 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config struct {
BindAddress string
DebugHTTPAddress string
IPv6UseAlternativeDNS bool
DefaultDNSBundle string
HostsFile string
MinimumTTL int
DomainTTLFile string
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func InitServer(configFilePath string) {
conf := config.NewConfig(configFilePath)
//New dispatcher without RemoteClientBundle, RemoteClientBundle must be initiated when server is running
dispatcher := outbound.Dispatcher{

DefaultDNSBundle: conf.DefaultDNSBundle,
DNSFilter: conf.DNSFilter,
DNSBunch: conf.DNSBunch,
RedirectIPv6Record: conf.IPv6UseAlternativeDNS,
Expand Down
34 changes: 18 additions & 16 deletions core/outbound/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type Dispatcher struct {
RedirectIPv6Record bool
MinimumTTL int
DomainTTLMap map[string]uint32

DNSFilter map[string]*common.Filter
DNSBunch map[string][]*common.DNSUpstream
Hosts *hosts.Hosts
Cache *cache.Cache
DefaultDNSBundle string
DNSFilter map[string]*common.Filter
DNSBunch map[string][]*common.DNSUpstream
Hosts *hosts.Hosts
Cache *cache.Cache
}

type HitTask struct {
Expand Down Expand Up @@ -60,22 +60,22 @@ func (d *Dispatcher) Exchange(query *dns.Msg, inboundIP string) *dns.Msg {
// local Domain, ip
ch := make(chan *HitTask, len(ClientsBundle))
// hitList := list.New()
bundleLen := len(ClientsBundle)
bundleLenght := len(ClientsBundle)
var c = new(HitTask)
for bunchName := range ClientsBundle {
go func(ch chan *HitTask, bunchName string) {
c.isHit = d.isSelectDomain(ClientsBundle[bunchName], d.DNSFilter[bunchName].DomainList)
if c.isHit {
c.hitRemoteClientBundle = ClientsBundle[bunchName]
ch <- c
}
// if c.isHit {
c.hitRemoteClientBundle = ClientsBundle[bunchName]
ch <- c
// }
return
}(ch, bunchName)
}
for bundleLen != 0 {
log.Info(bundleLen)
for bundleLenght > 0 {
if x, ok := <-ch; ok {
bundleLen--
log.Info(x.isHit)
bundleLenght--
if x.isHit {
// hitList.PushBack(x.hitRemoteClientBundle)
ActiveClientBundle = x.hitRemoteClientBundle
Expand All @@ -85,10 +85,12 @@ func (d *Dispatcher) Exchange(query *dns.Msg, inboundIP string) *dns.Msg {
}
}
}
if ActiveClientBundle == nil {
log.Info("Domain match failed return nil.")
// TODO: need to set a default bundle
if ActiveClientBundle == nil && d.DefaultDNSBundle == "" {
log.Info("Domain match failed return nil; DefaultDNSBundle is nil, return nil")
return nil
} else if d.DefaultDNSBundle != "" {
log.Infof("Use default dns bundle: %s", d.DefaultDNSBundle)
ActiveClientBundle = ClientsBundle[d.DefaultDNSBundle]
}
return ActiveClientBundle.Exchange(true, true)
// isCache bool, isLog bool
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down

0 comments on commit 0de4b1e

Please sign in to comment.