mosdns: forward: avoid picking same upstream
* Link: https://github.com/IrineSistiana/mosdns/pull/842 Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
parent
ab4c2a0787
commit
805606d137
@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=mosdns
|
PKG_NAME:=mosdns
|
||||||
PKG_VERSION:=5.3.3
|
PKG_VERSION:=5.3.3
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||||
PKG_SOURCE_URL:=https://codeload.github.com/IrineSistiana/mosdns/tar.gz/v$(PKG_VERSION)?
|
PKG_SOURCE_URL:=https://codeload.github.com/IrineSistiana/mosdns/tar.gz/v$(PKG_VERSION)?
|
||||||
@ -22,7 +22,7 @@ PKG_USE_MIPS16:=0
|
|||||||
PKG_BUILD_FLAGS:=no-mips16
|
PKG_BUILD_FLAGS:=no-mips16
|
||||||
|
|
||||||
GO_PKG:=github.com/IrineSistiana/mosdns
|
GO_PKG:=github.com/IrineSistiana/mosdns
|
||||||
GO_PKG_LDFLAGS_X:=main.version=v$(PKG_VERSION)
|
GO_PKG_LDFLAGS_X:=main.version=v$(PKG_VERSION)-$(PKG_RELEASE)
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||||
|
62
mosdns/patches/200-forward-avoid-picking-same-upstream.patch
Normal file
62
mosdns/patches/200-forward-avoid-picking-same-upstream.patch
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
---
|
||||||
|
plugin/executable/forward/forward.go | 7 ++++++-
|
||||||
|
plugin/executable/forward/utils.go | 5 -----
|
||||||
|
2 files changed, 6 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"
|
||||||
|
"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
|
||||||
|
done := make(chan struct{})
|
||||||
|
defer close(done)
|
||||||
|
|
||||||
|
+ p := rand.Perm(len(us))
|
||||||
|
for i := 0; i < concurrent; i++ {
|
||||||
|
- u := randPick(us)
|
||||||
|
+ u := us[p[i]]
|
||||||
|
qc := copyPayload(queryPayload)
|
||||||
|
go func(uqid uint32, question dns.Question) {
|
||||||
|
defer pool.ReleaseBuf(qc)
|
||||||
|
--- a/plugin/executable/forward/utils.go
|
||||||
|
+++ b/plugin/executable/forward/utils.go
|
||||||
|
@@ -21,7 +21,6 @@ package fastforward
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
- "math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/IrineSistiana/mosdns/v5/pkg/pool"
|
||||||
|
@@ -153,10 +152,6 @@ func (q *queryInfo) MarshalLogObject(enc
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
-func randPick[T any](s []T) T {
|
||||||
|
- return s[rand.Intn(len(s))]
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
func copyPayload(b *[]byte) *[]byte {
|
||||||
|
bc := pool.GetBuf(len(*b))
|
||||||
|
copy(*bc, *b)
|
Loading…
Reference in New Issue
Block a user