From ce1a0749e417e65fe62dd934310bca98de8a59a7 Mon Sep 17 00:00:00 2001 From: actions-user Date: Wed, 18 Dec 2024 00:17:34 +0800 Subject: [PATCH] update 2024-12-18 00:17:34 --- mosdns/Makefile | 2 +- ...cking-same-upstream-if-concurrent-2.patch} | 30 ++++++---------- ...upstream-resend-udp-package-every-1s.patch | 36 +++++++++++++++++++ 3 files changed, 47 insertions(+), 21 deletions(-) rename mosdns/patches/{200-forward-avoid-picking-same-upstream.patch => 200-forward-avoid-picking-same-upstream-if-concurrent-2.patch} (58%) create mode 100644 mosdns/patches/201-upstream-resend-udp-package-every-1s.patch diff --git a/mosdns/Makefile b/mosdns/Makefile index b147b33b..6eaba528 100644 --- a/mosdns/Makefile +++ b/mosdns/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mosdns PKG_VERSION:=5.3.3 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://codeload.github.com/IrineSistiana/mosdns/tar.gz/v$(PKG_VERSION)? diff --git a/mosdns/patches/200-forward-avoid-picking-same-upstream.patch b/mosdns/patches/200-forward-avoid-picking-same-upstream-if-concurrent-2.patch similarity index 58% rename from mosdns/patches/200-forward-avoid-picking-same-upstream.patch rename to mosdns/patches/200-forward-avoid-picking-same-upstream-if-concurrent-2.patch index a90e1d75..b03ee060 100644 --- a/mosdns/patches/200-forward-avoid-picking-same-upstream.patch +++ b/mosdns/patches/200-forward-avoid-picking-same-upstream-if-concurrent-2.patch @@ -1,12 +1,12 @@ -From 348bc3f68c676de929e74accc75e62d01ea999be Mon Sep 17 00:00:00 2001 -From: Henry-ZHR -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 <49315432+IrineSistiana@users.noreply.github.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 @@ -14,28 +14,18 @@ Subject: [PATCH] forward: avoid picking same upstream "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) diff --git a/mosdns/patches/201-upstream-resend-udp-package-every-1s.patch b/mosdns/patches/201-upstream-resend-udp-package-every-1s.patch new file mode 100644 index 00000000..a22ed5f3 --- /dev/null +++ b/mosdns/patches/201-upstream-resend-udp-package-every-1s.patch @@ -0,0 +1,36 @@ +From f20baf28be3e18cef0a4695d25db202dbc124300 Mon Sep 17 00:00:00 2001 +From: Irine Sistiana <49315432+IrineSistiana@users.noreply.github.com> +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)