Skip to content

Commit a2d7aec

Browse files
authored
fix: improvements in memory consumption (#100)
* fix: must close the connection after processing I think it should help to close #80 * feat: migration to github.com/things-go/go-socks5 - preallocate config slices - not used interfaces in consumer - do not allocate new variables in loops * feat: close connection after full processing * feat: correct process sigint signal * feat: improve build system * fix: http proxy * feat: update golangci-lint-action to v3.7.0 * feat: correct process routines * fix: close http conn correctly * feat: update golangci-lint-action to v4 * fix: goreleaser used clean now
1 parent 49f5688 commit a2d7aec

File tree

12 files changed

+205
-140
lines changed

12 files changed

+205
-140
lines changed

.github/workflows/build.yml

+29-28
Original file line numberDiff line numberDiff line change
@@ -6,145 +6,146 @@ on:
66
pull_request:
77
branches:
88
- '**'
9+
workflow_dispatch:
910

1011
jobs:
1112
windowsAmd64Build:
1213
name: Build Windows amd64 Version
1314
runs-on: ubuntu-latest
1415
steps:
15-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1617
- name: Setting up Go
17-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v5
1819
with:
19-
go-version: "1.20"
20+
go-version: "1.21"
2021
- name: Building Windows amd64 Version
2122
run: |
2223
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o WireProxy_amd64.exe -v ./cmd/wireproxy
2324
mkdir release_windows_amd64
2425
mv WireProxy_amd64.exe wireproxy.exe
2526
cp wireproxy.exe release_windows_amd64/wireproxy.exe
2627
- name: Upload Windows amd64 Version
27-
uses: actions/upload-artifact@v1
28+
uses: actions/upload-artifact@v4
2829
with:
2930
name: WireProxy_windows_amd64
3031
path: release_windows_amd64
3132
windowsArm64Build:
3233
name: Build Windows arm64 Version
3334
runs-on: ubuntu-latest
3435
steps:
35-
- uses: actions/checkout@v2
36+
- uses: actions/checkout@v4
3637
- name: Setting up Go
37-
uses: actions/setup-go@v2
38+
uses: actions/setup-go@v5
3839
with:
39-
go-version: "1.20"
40+
go-version: "1.21"
4041
- name: Building Windows arm64 Version
4142
run: |
4243
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -o WireProxy_arm64.exe -v ./cmd/wireproxy
4344
mkdir release_windows_arm64
4445
mv WireProxy_arm64.exe wireproxy.exe
4546
cp wireproxy.exe release_windows_arm64/wireproxy.exe
4647
- name: Upload Windows arm64 Version
47-
uses: actions/upload-artifact@v1
48+
uses: actions/upload-artifact@v4
4849
with:
4950
name: WireProxy_windows_arm64
5051
path: release_windows_arm64
5152
linuxAmd64Build:
5253
name: Build Linux amd64 Version
5354
runs-on: ubuntu-latest
5455
steps:
55-
- uses: actions/checkout@v2
56+
- uses: actions/checkout@v4
5657
- name: Setting up Go
57-
uses: actions/setup-go@v2
58+
uses: actions/setup-go@v5
5859
with:
59-
go-version: "1.20"
60+
go-version: "1.21"
6061
- name: Building Linux amd64 Version
6162
run: |
6263
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o WireProxy_amd64 -v ./cmd/wireproxy
6364
mkdir release_linux_amd64
6465
mv WireProxy_amd64 wireproxy
6566
cp wireproxy release_linux_amd64/wireproxy
6667
- name: Upload Linux amd64 Version
67-
uses: actions/upload-artifact@v1
68+
uses: actions/upload-artifact@v4
6869
with:
6970
name: WireProxy_linux_amd64
7071
path: release_linux_amd64
7172
linuxArm64Build:
7273
name: Build Linux arm64 Version
7374
runs-on: ubuntu-latest
7475
steps:
75-
- uses: actions/checkout@v2
76+
- uses: actions/checkout@v4
7677
- name: Setting up Go
77-
uses: actions/setup-go@v2
78+
uses: actions/setup-go@v5
7879
with:
79-
go-version: "1.20"
80+
go-version: "1.21"
8081
- name: Building Linux arm64 Version
8182
run: |
8283
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o WireProxy_arm64 -v ./cmd/wireproxy
8384
mkdir release_linux_arm64
8485
mv WireProxy_arm64 wireproxy
8586
cp wireproxy release_linux_arm64/wireproxy
8687
- name: Upload Linux arm64 Version
87-
uses: actions/upload-artifact@v1
88+
uses: actions/upload-artifact@v4
8889
with:
8990
name: WireProxy_linux_arm64
9091
path: release_linux_arm64
9192
linuxS390xBuild:
9293
name: Build Linux s390x Version
9394
runs-on: ubuntu-latest
9495
steps:
95-
- uses: actions/checkout@v2
96+
- uses: actions/checkout@v4
9697
- name: Setting up Go
97-
uses: actions/setup-go@v2
98+
uses: actions/setup-go@v5
9899
with:
99-
go-version: "1.20"
100+
go-version: "1.21"
100101
- name: Building Linux s390x Version
101102
run: |
102103
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -o WireProxy_s390x -v ./cmd/wireproxy
103104
mkdir release_linux_s390x
104105
mv WireProxy_s390x wireproxy
105106
cp wireproxy release_linux_s390x/wireproxy
106107
- name: Upload Linux s390x Version
107-
uses: actions/upload-artifact@v1
108+
uses: actions/upload-artifact@v4
108109
with:
109110
name: WireProxy_linux_s390x
110111
path: release_linux_s390x
111112
darwinAmd64Build:
112113
name: Build Darwin amd64 Version
113114
runs-on: ubuntu-latest
114115
steps:
115-
- uses: actions/checkout@v2
116+
- uses: actions/checkout@v4
116117
- name: Setting up Go
117-
uses: actions/setup-go@v2
118+
uses: actions/setup-go@v5
118119
with:
119-
go-version: "1.20"
120+
go-version: "1.21"
120121
- name: Building Darwin amd64 Version
121122
run: |
122123
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o WireProxy_amd64 -v ./cmd/wireproxy
123124
mkdir release_darwin_amd64
124125
mv WireProxy_amd64 wireproxy
125126
cp wireproxy release_darwin_amd64/wireproxy
126127
- name: Upload Darwin amd64 Version
127-
uses: actions/upload-artifact@v1
128+
uses: actions/upload-artifact@v4
128129
with:
129130
name: WireProxy_darwin_amd64
130131
path: release_darwin_amd64
131132
darwinArm64Build:
132133
name: Build Darwin arm64 Version
133134
runs-on: ubuntu-latest
134135
steps:
135-
- uses: actions/checkout@v2
136+
- uses: actions/checkout@v4
136137
- name: Setting up Go
137-
uses: actions/setup-go@v2
138+
uses: actions/setup-go@v5
138139
with:
139-
go-version: "1.20"
140+
go-version: "1.21"
140141
- name: Building Darwin arm64 Version
141142
run: |
142143
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o WireProxy_arm64 -v ./cmd/wireproxy
143144
mkdir release_darwin_arm64
144145
mv WireProxy_arm64 wireproxy
145146
cp wireproxy release_darwin_arm64/wireproxy
146147
- name: Upload Darwin arm64 Version
147-
uses: actions/upload-artifact@v1
148+
uses: actions/upload-artifact@v4
148149
with:
149150
name: WireProxy_darwin_arm64
150151
path: release_darwin_arm64

.github/workflows/container.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ jobs:
2828

2929
steps:
3030
- name: Set up QEMU
31-
uses: docker/setup-qemu-action@v2
31+
uses: docker/setup-qemu-action@v3
3232

3333
- name: Set up Docker Buildx
3434
id: buildx
35-
uses: docker/setup-buildx-action@v2.0.0
35+
uses: docker/setup-buildx-action@v3.0.0
3636

3737
- name: Login to GitHub Container Registry
38-
uses: docker/login-action@v2
38+
uses: docker/login-action@v3
3939
with:
4040
registry: ghcr.io
4141
username: ${{ github.actor }}
4242
password: ${{ secrets.GITHUB_TOKEN }}
4343

44-
- uses: actions/checkout@v3
44+
- uses: actions/checkout@v4
4545
with:
4646
submodules: recursive
4747

4848
# Needed for buildx gha cache to work
4949
- name: Expose GitHub Runtime
50-
uses: crazy-max/ghaction-github-runtime@v2
50+
uses: crazy-max/ghaction-github-runtime@v3
5151

5252
- name: Build container
5353
env:

.github/workflows/golangci-lint.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ on:
66
pull_request:
77
branches:
88
- '**'
9+
workflow_dispatch:
10+
911
permissions:
1012
contents: read
1113
jobs:
1214
golangci:
1315
name: lint
1416
runs-on: ubuntu-latest
1517
steps:
16-
- uses: actions/setup-go@v2
18+
- uses: actions/setup-go@v5
1719
with:
18-
go-version: '1.20'
19-
- uses: actions/checkout@v3
20+
go-version: '1.21'
21+
- uses: actions/checkout@v4
2022
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v3
23+
uses: golangci/golangci-lint-action@v4
24+
with:
25+
version: latest

.github/workflows/test.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ on:
66
pull_request:
77
branches:
88
- '**'
9+
workflow_dispatch:
910

1011
jobs:
1112
test:
1213
name: Test wireproxy
1314
runs-on: ubuntu-latest
1415
steps:
15-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1617
- name: Setting up Go
17-
uses: actions/setup-go@v2
18+
uses: actions/setup-go@v5
1819
with:
19-
go-version: "1.20"
20+
go-version: "1.21"
2021
- name: Install dependencies
2122
run: sudo apt install wireguard curl
2223
- name: Building wireproxy

.github/workflows/wireproxy.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ jobs:
2828
cp ./.github/wireproxy-releaser.yml ${{ env.workdir }}/.goreleaser.yml
2929
3030
- name: Set up GoReleaser
31-
uses: actions/setup-go@v2
31+
uses: actions/setup-go@v5
3232
with:
33-
go-version: "1.20"
33+
go-version: "1.21"
3434

3535
- name: Run GoReleaser
36-
uses: goreleaser/goreleaser-action@v2
36+
uses: goreleaser/goreleaser-action@v5
3737
with:
3838
distribution: goreleaser
3939
workdir: ${{ env.workdir }}
4040
version: latest
41-
args: release --rm-dist
41+
args: release --clean
4242
env:
4343
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4444

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Start by building the application.
2-
FROM docker.io/golang:1.20 as build
2+
FROM docker.io/golang:1.21 as build
33

44
WORKDIR /usr/src/wireproxy
55
COPY . .
@@ -14,6 +14,6 @@ VOLUME [ "/etc/wireproxy"]
1414
ENTRYPOINT [ "/usr/bin/wireproxy" ]
1515
CMD [ "--config", "/etc/wireproxy/config" ]
1616

17-
LABEL org.opencontainers.image.title wireproxy
18-
LABEL org.opencontainers.image.description "Wireguard client that exposes itself as a socks5 proxy"
19-
LABEL org.opencontainers.image.licenses ISC
17+
LABEL org.opencontainers.image.title="wireproxy"
18+
LABEL org.opencontainers.image.description="Wireguard client that exposes itself as a socks5 proxy"
19+
LABEL org.opencontainers.image.licenses="ISC"

cmd/wireproxy/main.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"os"
78
"os/exec"
9+
"os/signal"
810
"syscall"
911

1012
"github.com/akamensky/argparse"
11-
"github.com/octeep/wireproxy"
13+
"github.com/pufferffish/wireproxy"
1214
"golang.zx2c4.com/wireguard/device"
1315
"suah.dev/protect"
1416
)
@@ -46,6 +48,15 @@ func executablePath() string {
4648
}
4749

4850
func main() {
51+
s := make(chan os.Signal, 1)
52+
signal.Notify(s, syscall.SIGINT, syscall.SIGQUIT)
53+
ctx, cancel := context.WithCancel(context.Background())
54+
55+
go func() {
56+
<-s
57+
cancel()
58+
}()
59+
4960
exePath := executablePath()
5061
unveilOrPanic("/", "r")
5162
unveilOrPanic(exePath, "x")
@@ -138,5 +149,5 @@ func main() {
138149
go spawner.SpawnRoutine(tnet)
139150
}
140151

141-
select {} // sleep eternally
152+
<-ctx.Done()
142153
}

config.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type TCPClientTunnelConfig struct {
3636
}
3737

3838
type STDIOTunnelConfig struct {
39-
Target string
39+
Target string
4040
}
4141

4242
type TCPServerTunnelConfig struct {
@@ -125,8 +125,9 @@ func parseNetIP(section *ini.Section, keyName string) ([]netip.Addr, error) {
125125
return []netip.Addr{}, nil
126126
}
127127

128-
var ips []netip.Addr
129-
for _, str := range key.StringsWithShadows(",") {
128+
keys := key.StringsWithShadows(",")
129+
var ips = make([]netip.Addr, 0, len(keys))
130+
for _, str := range keys {
130131
str = strings.TrimSpace(str)
131132
ip, err := netip.ParseAddr(str)
132133
if err != nil {
@@ -143,8 +144,9 @@ func parseCIDRNetIP(section *ini.Section, keyName string) ([]netip.Addr, error)
143144
return []netip.Addr{}, nil
144145
}
145146

146-
var ips []netip.Addr
147-
for _, str := range key.StringsWithShadows(",") {
147+
keys := key.StringsWithShadows(",")
148+
var ips = make([]netip.Addr, 0, len(keys))
149+
for _, str := range keys {
148150
prefix, err := netip.ParsePrefix(str)
149151
if err != nil {
150152
return nil, err
@@ -162,8 +164,9 @@ func parseAllowedIPs(section *ini.Section) ([]netip.Prefix, error) {
162164
return []netip.Prefix{}, nil
163165
}
164166

165-
var ips []netip.Prefix
166-
for _, str := range key.StringsWithShadows(",") {
167+
keys := key.StringsWithShadows(",")
168+
var ips = make([]netip.Prefix, 0, len(keys))
169+
for _, str := range keys {
167170
prefix, err := netip.ParsePrefix(str)
168171
if err != nil {
169172
return nil, err
@@ -237,7 +240,7 @@ func ParseInterface(cfg *ini.File, device *DeviceConfig) error {
237240
return nil
238241
}
239242

240-
// ParsePeer parses the [Peer] section and extract the information into `peers`
243+
// ParsePeers parses the [Peer] section and extract the information into `peers`
241244
func ParsePeers(cfg *ini.File, peers *[]PeerConfig) error {
242245
sections, err := cfg.SectionsByName("Peer")
243246
if len(sections) < 1 || err != nil {

0 commit comments

Comments
 (0)