From 60d55deb81f9468727b1bac3802f1719b24fb15e Mon Sep 17 00:00:00 2001 From: hiddify-com <114227601+hiddify-com@users.noreply.github.com> Date: Wed, 17 Jul 2024 22:56:31 +0200 Subject: [PATCH] chg: add wireguard mode --- go.mod | 2 +- go.sum | 4 ++-- option/wireguard.go | 1 + outbound/wireguard.go | 16 +++++++++++----- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f54637857f..268bd38e67 100644 --- a/go.mod +++ b/go.mod @@ -106,4 +106,4 @@ require ( lukechampine.com/blake3 v1.2.1 // indirect ) -replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240712191632-973cb66a43af +replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240717205116-b0de5e908866 diff --git a/go.sum b/go.sum index a6a43bb4d2..52c9c7cebe 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,8 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= -github.com/hiddify/wireguard-go v0.0.0-20240712191632-973cb66a43af h1:ebo07veHL6CqHDkNipNC2rsjrYLx9WEBk2XNGGLRbhc= -github.com/hiddify/wireguard-go v0.0.0-20240712191632-973cb66a43af/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc= +github.com/hiddify/wireguard-go v0.0.0-20240717205116-b0de5e908866 h1:VhAIBUXPHpO1VWiNUJ97PmfHm6iuuuijf9SSPyZ2xu4= +github.com/hiddify/wireguard-go v0.0.0-20240717205116-b0de5e908866/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc= github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b h1:1+115FqGoS8p6Iry9AYmrcWDvSveH0F7P2nX1LU00qg= github.com/imkira/go-observer/v2 v2.0.0-20230629064422-8e0b61f11f1b/go.mod h1:XCscqBi1KKh7GcVDDAdkT/Cf6WDjnDAA1XM3nwmA0Ag= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/option/wireguard.go b/option/wireguard.go index f3fd3aa42a..6778d6056c 100644 --- a/option/wireguard.go +++ b/option/wireguard.go @@ -21,6 +21,7 @@ type WireGuardOutboundOptions struct { FakePackets string `json:"fake_packets,omitempty"` FakePacketsSize string `json:"fake_packets_size,omitempty"` FakePacketsDelay string `json:"fake_packets_delay,omitempty"` + FakePacketsMode string `json:"fake_packets_mode,omitempty"` } type WireGuardPeer struct { diff --git a/outbound/wireguard.go b/outbound/wireguard.go index 0964d217a5..b20c6edbb4 100644 --- a/outbound/wireguard.go +++ b/outbound/wireguard.go @@ -20,8 +20,8 @@ import ( "github.com/sagernet/sing-box/option" "github.com/sagernet/sing-box/outbound/houtbound" "github.com/sagernet/sing-box/transport/wireguard" - "github.com/sagernet/sing-dns" - "github.com/sagernet/sing-tun" + dns "github.com/sagernet/sing-dns" + tun "github.com/sagernet/sing-tun" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" @@ -56,6 +56,7 @@ type WireGuard struct { fakePackets []int fakePacketsSize []int fakePacketsDelay []int + fakePacketsMode string lastUpdate time.Time } @@ -78,6 +79,7 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context outbound.fakePackets = []int{0, 0} outbound.fakePacketsSize = []int{0, 0} outbound.fakePacketsDelay = []int{0, 0} + outbound.fakePacketsMode = options.FakePacketsMode if options.FakePackets != "" { var err error outbound.fakePackets, err = option.ParseIntRange(options.FakePackets) @@ -85,7 +87,7 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context return nil, err } outbound.fakePacketsSize = []int{40, 100} - outbound.fakePacketsDelay = []int{200, 500} + outbound.fakePacketsDelay = []int{10, 50} if options.FakePacketsSize != "" { var err error @@ -102,7 +104,6 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context return nil, err } } - } peers, err := wireguard.ParsePeers(options) @@ -200,7 +201,12 @@ func (w *WireGuard) start() error { Errorf: func(format string, args ...interface{}) { w.logger.Error(fmt.Sprintf(strings.ToLower(format), args...)) }, - }, w.workers, w.fakePackets, w.fakePacketsSize, w.fakePacketsDelay) + }, w.workers) + wgDevice.FakePackets = w.fakePackets + wgDevice.FakePacketsSize = w.fakePacketsSize + wgDevice.FakePacketsDelays = w.fakePacketsDelay + wgDevice.FakePacketsMode = w.fakePacketsMode + ipcConf := w.ipcConf for _, peer := range w.peers { ipcConf += peer.GenerateIpcLines()