Skip to content

Commit

Permalink
chg: add wireguard mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 17, 2024
1 parent 0af1865 commit 60d55de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions option/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 11 additions & 5 deletions outbound/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -56,6 +56,7 @@ type WireGuard struct {
fakePackets []int
fakePacketsSize []int
fakePacketsDelay []int
fakePacketsMode string
lastUpdate time.Time
}

Expand All @@ -78,14 +79,15 @@ 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)
if err != nil {
return nil, err
}
outbound.fakePacketsSize = []int{40, 100}
outbound.fakePacketsDelay = []int{200, 500}
outbound.fakePacketsDelay = []int{10, 50}

if options.FakePacketsSize != "" {
var err error
Expand All @@ -102,7 +104,6 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context
return nil, err
}
}

}

peers, err := wireguard.ParsePeers(options)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 60d55de

Please sign in to comment.