Skip to content

Commit b26f59e

Browse files
update code
Signed-off-by: Matheus Sampaio Queiroga <[email protected]>
1 parent 4069323 commit b26f59e

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

addon/userspace/go/go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ module sirherobrine23.org/Wireguard/wireguard-tools.js/wg-tun
22

33
go 1.21.6
44

5-
require (
6-
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
7-
)
5+
require golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
86

97
require (
10-
golang.org/x/sys v0.12.0 // indirect
11-
golang.org/x/crypto v0.13.0 // indirect
12-
golang.org/x/net v0.15.0 // indirect
8+
golang.org/x/crypto v0.22.0 // indirect
9+
golang.org/x/net v0.24.0 // indirect
10+
golang.org/x/sys v0.19.0 // indirect
1311
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
1412
)

addon/userspace/go/go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
22
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
33
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
44
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
5+
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
6+
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
57
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
68
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
9+
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
10+
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
711
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
812
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13+
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
14+
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
915
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
1016
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
1117
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=

addon/userspace/go/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@ import (
66
"fmt"
77
"os"
88
"os/signal"
9+
"runtime"
910
"runtime/debug"
1011
"strings"
1112
"syscall"
13+
_ "unsafe"
1214

1315
"golang.zx2c4.com/wireguard/conn"
1416
"golang.zx2c4.com/wireguard/device"
1517
"golang.zx2c4.com/wireguard/ipc"
1618
"golang.zx2c4.com/wireguard/tun"
19+
1720
)
1821

1922
const levelLog = device.LogLevelError
2023

24+
//go:linkname socketDirectory golang.xz2c4.com/wireguard/ipc.socketDirectory
25+
var socketDirectory = "/var/run/wireguard"
26+
27+
func init() {
28+
if runtime.GOOS == "windows" {
29+
socketDirectory = `\\.\pipe\ProtectedPrefix\Administrators\WireGuard`
30+
}
31+
}
32+
2133
// End process function callbacks
2234
var TunsEndProcess = make(map[string]func())
2335

addon/userspace/go/main_unix.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

addon/userspace/go/main_windows.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

binding.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ sources:
1212
prebuild:
1313
- shell: bash
1414
cwd: ./addon/userspace/go
15+
ifOs:
16+
- "!win32"
17+
- "!linux"
1518
env:
1619
CGO_ENABLED: "1"
1720
LDFLAGS: "-w"
@@ -31,7 +34,7 @@ target:
3134
- "-w"
3235
- "-fpermissive"
3336
- "-fPIC"
34-
windows:
37+
win32:
3538
sources:
3639
- "!addon/userspace/wginterface.cpp"
3740
- "addon/win/wginterface.cpp"
@@ -47,7 +50,7 @@ target:
4750
defines:
4851
- "_HAS_EXCEPTIONS=1"
4952
- "ONSTARTADDON"
50-
macos:
53+
darwin:
5154
flags:
5255
- "!-fno-exceptions"
5356
- "-fpermissive"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
},
4747
"dependencies": {
4848
"node-addon-api": "^8.0.0",
49-
"rebory": "^0.2.5"
49+
"rebory": "^0.2.10"
5050
}
5151
}

src/quick.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { isIP } from "net";
22
import { format } from "util";
3-
import { Peer, WgConfigBase } from "./wginterface.js";
3+
import { SetConfig } from "./wginterface.js";
44

5-
export interface QuickConfig extends WgConfigBase<Peer>, Partial<Record<`${"Post" | "Pre"}${"Up" | "Down"}`, string[]>> {
5+
export interface QuickConfig extends SetConfig, Partial<Record<`${"Post" | "Pre"}${"Up" | "Down"}`, string[]>> {
66
DNS?: string[];
77
Table?: number;
88
MTU?: number;
@@ -92,7 +92,7 @@ export function stringify(wgConfig: QuickConfig): string {
9292
const peerConfig = wgConfig.peers[pubKey];
9393
configStr.push("", "[Peer]", format("PublicKey = %s", pubKey));
9494
if (peerConfig.presharedKey) configStr.push(format("PresharedKey = %s", peerConfig.presharedKey));
95-
if (peerConfig.keepInterval > 0) configStr.push(format("PersistentKeepalive = %n", peerConfig.keepInterval));
95+
if (peerConfig.keepInterval > 0) configStr.push(format("PersistentKeepalive = %d", peerConfig.keepInterval));
9696
if (peerConfig.endpoint) configStr.push(format("Endpoint = %s", peerConfig.endpoint));
9797
if (peerConfig.allowedIPs) configStr.push(format("AllowedIPs = %s", peerConfig.allowedIPs.join(", ")));
9898
}

0 commit comments

Comments
 (0)