-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3ecd43
commit 9f3101f
Showing
4 changed files
with
118 additions
and
4 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
19 changes: 19 additions & 0 deletions
19
mosdns/patches/203-add-response-for-bad-request-in-ServeHTTP-handler.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,19 @@ | ||
From 0b86b89629f32e7c8b859239aa1a4814f256053c Mon Sep 17 00:00:00 2001 | ||
From: sbwml <[email protected]> | ||
Date: Thu, 28 Sep 2023 16:42:54 +0800 | ||
Subject: [PATCH 3/5] add response for bad request in ServeHTTP handler | ||
|
||
--- | ||
pkg/server/http_handler.go | 1 + | ||
1 file changed, 1 insertion(+) | ||
|
||
--- a/pkg/server/http_handler.go | ||
+++ b/pkg/server/http_handler.go | ||
@@ -93,6 +93,7 @@ func (h *HttpHandler) ServeHTTP(w http.R | ||
if err != nil { | ||
h.warnErr(req, "invalid request", err) | ||
w.WriteHeader(http.StatusBadRequest) | ||
+ w.Write([]byte("Bad Request")) | ||
return | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
mosdns/patches/204-black_hole-apply-Fisher-Yates-shuffle-algorithm-to-r.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,51 @@ | ||
From e34dca717e78d24a84b98c2b5d371c4253b7e260 Mon Sep 17 00:00:00 2001 | ||
From: sbwml <[email protected]> | ||
Date: Wed, 20 Sep 2023 14:51:19 +0800 | ||
Subject: [PATCH 4/5] black_hole: apply Fisher-Yates shuffle algorithm to | ||
randomize IP order | ||
|
||
--- | ||
plugin/executable/black_hole/black_hole.go | 15 +++++++++++++++ | ||
1 file changed, 15 insertions(+) | ||
|
||
--- a/plugin/executable/black_hole/black_hole.go | ||
+++ b/plugin/executable/black_hole/black_hole.go | ||
@@ -27,6 +27,8 @@ import ( | ||
"github.com/miekg/dns" | ||
"net/netip" | ||
"strings" | ||
+ "math/rand" | ||
+ "sync" | ||
) | ||
|
||
const PluginType = "black_hole" | ||
@@ -40,6 +42,7 @@ var _ sequence.Executable = (*BlackHole) | ||
type BlackHole struct { | ||
ipv4 []netip.Addr | ||
ipv6 []netip.Addr | ||
+ shuffleMutex sync.Mutex | ||
} | ||
|
||
// QuickSetup format: [ipv4|ipv6] ... | ||
@@ -65,9 +68,21 @@ func NewBlackHole(ips []string) (*BlackH | ||
return b, nil | ||
} | ||
|
||
+func (b *BlackHole) shuffleIPs() { | ||
+ b.shuffleMutex.Lock() | ||
+ defer b.shuffleMutex.Unlock() | ||
+ rand.Shuffle(len(b.ipv4), func(i, j int) { | ||
+ b.ipv4[i], b.ipv4[j] = b.ipv4[j], b.ipv4[i] | ||
+ }) | ||
+ rand.Shuffle(len(b.ipv6), func(i, j int) { | ||
+ b.ipv6[i], b.ipv6[j] = b.ipv6[j], b.ipv6[i] | ||
+ }) | ||
+} | ||
+ | ||
// Exec implements sequence.Executable. It set a response with given ips if | ||
// query has corresponding qtypes. | ||
func (b *BlackHole) Exec(_ context.Context, qCtx *query_context.Context) error { | ||
+ b.shuffleIPs() | ||
if r := b.Response(qCtx.Q()); r != nil { | ||
qCtx.SetResponse(r) | ||
} |
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,46 @@ | ||
From 2dc08749e2de8f19ef869e7f89c9979edbbc71ff Mon Sep 17 00:00:00 2001 | ||
From: sbwml <[email protected]> | ||
Date: Wed, 20 Sep 2023 21:05:18 +0800 | ||
Subject: [PATCH 5/5] format logtime | ||
|
||
--- | ||
mlog/logger.go | 18 ++++++++++++++---- | ||
1 file changed, 14 insertions(+), 4 deletions(-) | ||
|
||
--- a/mlog/logger.go | ||
+++ b/mlog/logger.go | ||
@@ -21,9 +21,11 @@ package mlog | ||
|
||
import ( | ||
"fmt" | ||
+ "os" | ||
+ "time" | ||
+ | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
- "os" | ||
) | ||
|
||
type LogConfig struct { | ||
@@ -64,10 +66,18 @@ func NewLogger(lc LogConfig) (*zap.Logge | ||
out = stderr | ||
} | ||
|
||
- if lc.Production { | ||
- return zap.New(zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), out, lvl)), nil | ||
+ encoderConfig := zap.NewDevelopmentEncoderConfig() | ||
+ encoderConfig.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) { | ||
+ enc.AppendString(t.Format("2006-01-02 15:04:05")) | ||
} | ||
- return zap.New(zapcore.NewCore(zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()), out, lvl)), nil | ||
+ | ||
+ core := zapcore.NewCore( | ||
+ zapcore.NewConsoleEncoder(encoderConfig), | ||
+ out, | ||
+ lvl, | ||
+ ) | ||
+ | ||
+ return zap.New(core), nil | ||
} | ||
|
||
// L is a global logger. |