Skip to content

Commit

Permalink
mosdns: patches: update from upstream
Browse files Browse the repository at this point in the history
Signed-off-by: sbwml <[email protected]>
  • Loading branch information
sbwml committed Dec 17, 2024
1 parent dde0c95 commit 4fc714f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
2 changes: 1 addition & 1 deletion mosdns/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down
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)
Expand Down
36 changes: 36 additions & 0 deletions mosdns/patches/201-upstream-resend-udp-package-every-1s.patch
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)

0 comments on commit 4fc714f

Please sign in to comment.