Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Jan 27, 2024
1 parent 03b8fe8 commit aa7959f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 50 deletions.
23 changes: 12 additions & 11 deletions ecs.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright © by Jeff Foley 2021-2023. All rights reserved.
// Copyright © by Jeff Foley 2021-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

package resolve

import (
"time"

"github.com/miekg/dns"
)

Expand All @@ -26,31 +28,30 @@ func (r *Resolvers) ClientSubnetCheck() {
})
}

var count int
for _, res := range all {
send(res)
count++
if count == 100 {
count = 0
time.Sleep(100 * time.Millisecond)
}
}

retries := make(map[string]struct{})
for i := 0; i < alen; i++ {
resp := <-ch

// pull the resolver associated with this message
key := xchgKey(resp.Id, resp.Question[0].Name)
res, found := msgsToRes[key]
if !found {
continue
}
delete(msgsToRes, key)
// give resolvers one additional chance to respond
if _, already := retries[res.address.IP.String()]; !already && resp.Rcode == RcodeNoResponse {
i--
retries[res.address.IP.String()] = struct{}{}
send(res)
continue
}
// check if the resolver responded, but did not return a successful response
if resp.Rcode != dns.RcodeSuccess || (!resp.Authoritative && !resp.RecursionAvailable) {
res.stop()
if res != nil {
res.stop()
}
continue
}

Expand Down
2 changes: 1 addition & 1 deletion ecs_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2022-2023. All rights reserved.
// Copyright © by Jeff Foley 2022-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion rate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2022-2023. All rights reserved.
// Copyright © by Jeff Foley 2022-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down
67 changes: 34 additions & 33 deletions resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2017-2023. All rights reserved.
// Copyright © by Jeff Foley 2017-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -321,43 +321,42 @@ func (r *Resolvers) processResponses() {
case <-r.resps.Signal():
}

var response *resp
if element, ok := r.resps.Next(); ok {
if r, valid := element.(*resp); valid {
response = r
r.resps.Process(func(element interface{}) {
if response, ok := element.(*resp); ok && r != nil {
r.processSingleResp(response)
}
}
if response == nil {
continue
}
})
}
}

var res *resolver
addr := response.Addr.IP.String()
if res = r.pool.LookupResolver(addr); res == nil {
detector := r.getDetectionResolver()
func (r *Resolvers) processSingleResp(response *resp) {
var res *resolver
addr := response.Addr.IP.String()

if detector != nil && addr == detector.address.IP.String() {
res = detector
}
}
if res == nil {
continue
if res = r.pool.LookupResolver(addr); res == nil {
detector := r.getDetectionResolver()

if detector != nil && addr == detector.address.IP.String() {
res = detector
}
}
if res == nil {
return
}

msg := response.Msg
name := msg.Question[0].Name
if req := res.xchgs.remove(msg.Id, name); req != nil {
req.Resp = msg
if req.Resp.Truncated {
go req.Res.tcpExchange(req)
} else {
req.Result <- req.Resp
req.Res.collectStats(req.Resp)
if r.servRates != nil {
r.servRates.Success(name)
}
req.release()
msg := response.Msg
name := msg.Question[0].Name
if req := res.xchgs.remove(msg.Id, name); req != nil {
req.Resp = msg
if req.Resp.Truncated {
go req.Res.tcpExchange(req)
} else {
req.Result <- req.Resp
req.Res.collectStats(req.Resp)
if r.servRates != nil {
r.servRates.Success(name)
}
req.release()
}
}
}
Expand Down Expand Up @@ -394,7 +393,9 @@ func (r *Resolvers) timeouts() {
r.Lock()
d := r.timeout / 2
r.Unlock()
time.Sleep(d)
if d > 0 {
time.Sleep(d)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion resolvers_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2017-2023. All rights reserved.
// Copyright © by Jeff Foley 2017-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion thresholds.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2017-2023. All rights reserved.
// Copyright © by Jeff Foley 2017-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion xchg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2021-2023. All rights reserved.
// Copyright © by Jeff Foley 2021-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion xchg_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2021-2023. All rights reserved.
// Copyright © by Jeff Foley 2021-2024. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0

Expand Down

0 comments on commit aa7959f

Please sign in to comment.