-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mosdns: patches: update from upstream
Signed-off-by: sbwml <[email protected]>
- Loading branch information
Showing
3 changed files
with
47 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 10 additions & 20 deletions
30
...forward-avoid-picking-same-upstream.patch → ...cking-same-upstream-if-concurrent-2.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,31 @@ | ||
From 348bc3f68c676de929e74accc75e62d01ea999be Mon Sep 17 00:00:00 2001 | ||
From: Henry-ZHR <henry-zhr@qq.com> | ||
Date: Mon, 16 Sep 2024 10:59:42 +0800 | ||
Subject: [PATCH] forward: avoid picking same upstream | ||
From f5d190ab1542b96688353eeb3d3d5c46fbad8b7c Mon Sep 17 00:00:00 2001 | ||
From: Irine Sistiana <[email protected].com> | ||
Date: Wed, 11 Dec 2024 20:49:42 +0800 | ||
Subject: [PATCH 1/2] forward: avoid picking same upstream if concurrent > 2 | ||
|
||
--- | ||
plugin/executable/forward/forward.go | 7 ++++++- | ||
plugin/executable/forward/forward.go | 4 +++- | ||
plugin/executable/forward/utils.go | 5 ----- | ||
2 files changed, 6 insertions(+), 6 deletions(-) | ||
2 files changed, 3 insertions(+), 6 deletions(-) | ||
|
||
--- a/plugin/executable/forward/forward.go | ||
+++ b/plugin/executable/forward/forward.go | ||
@@ -24,6 +24,7 @@ import ( | ||
"crypto/tls" | ||
"errors" | ||
"fmt" | ||
+ "math/rand" | ||
+ "math/rand/v2" | ||
"strings" | ||
"time" | ||
|
||
@@ -251,6 +252,9 @@ func (f *Forward) exchange(ctx context.C | ||
if concurrent > maxConcurrentQueries { | ||
concurrent = maxConcurrentQueries | ||
} | ||
+ if concurrent > len(us) { | ||
+ concurrent = len(us) | ||
+ } | ||
|
||
type res struct { | ||
r *dns.Msg | ||
@@ -261,8 +265,9 @@ func (f *Forward) exchange(ctx context.C | ||
@@ -261,8 +262,9 @@ func (f *Forward) exchange(ctx context.C | ||
done := make(chan struct{}) | ||
defer close(done) | ||
|
||
+ p := rand.Perm(len(us)) | ||
+ r := rand.IntN(len(us)) | ||
for i := 0; i < concurrent; i++ { | ||
- u := randPick(us) | ||
+ u := us[p[i]] | ||
+ u := us[(r+i)%len(us)] | ||
qc := copyPayload(queryPayload) | ||
go func(uqid uint32, question dns.Question) { | ||
defer pool.ReleaseBuf(qc) | ||
|
36 changes: 36 additions & 0 deletions
36
mosdns/patches/201-upstream-resend-udp-package-every-1s.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
From f20baf28be3e18cef0a4695d25db202dbc124300 Mon Sep 17 00:00:00 2001 | ||
From: Irine Sistiana <[email protected]> | ||
Date: Wed, 11 Dec 2024 20:51:12 +0800 | ||
Subject: [PATCH 2/2] upstream: resend udp package every 1s | ||
|
||
--- | ||
pkg/upstream/transport/conn_traditional.go | 15 +++++++++++++++ | ||
1 file changed, 15 insertions(+) | ||
|
||
--- a/pkg/upstream/transport/conn_traditional.go | ||
+++ b/pkg/upstream/transport/conn_traditional.go | ||
@@ -124,9 +124,24 @@ func (dc *TraditionalDnsConn) exchange(c | ||
dc.c.SetReadDeadline(time.Now().Add(waitingReplyTimeout)) | ||
} | ||
|
||
+ var resend <-chan time.Time | ||
+ if !dc.isTcp { | ||
+ ticker := time.NewTicker(time.Second) | ||
+ resend = ticker.C | ||
+ defer ticker.Stop() | ||
+ } | ||
+ | ||
+wait: | ||
select { | ||
case <-ctx.Done(): | ||
return nil, context.Cause(ctx) | ||
+ case <-resend: | ||
+ err := dc.writeQuery(q, assignedQid) | ||
+ if err != nil { | ||
+ dc.CloseWithErr(fmt.Errorf("write err, %w", err)) | ||
+ return nil, err | ||
+ } | ||
+ goto wait | ||
case r := <-respChan: | ||
orgId := binary.BigEndian.Uint16(q) | ||
binary.BigEndian.PutUint16(*r, orgId) |