Launch
This commit is contained in:
15
internal/platformtun/wintun_other.go
Normal file
15
internal/platformtun/wintun_other.go
Normal file
@@ -0,0 +1,15 @@
|
||||
//go:build !windows
|
||||
|
||||
package platformtun
|
||||
|
||||
import "strings"
|
||||
|
||||
type Logger interface {
|
||||
Add(level, format string, args ...any)
|
||||
}
|
||||
|
||||
func Prepare(device, interfaceName string, mtu int, logger Logger) (string, string, func(), error) {
|
||||
device = strings.TrimSpace(device)
|
||||
interfaceName = strings.TrimSpace(interfaceName)
|
||||
return device, interfaceName, nil, nil
|
||||
}
|
||||
57
internal/platformtun/wintun_windows.go
Normal file
57
internal/platformtun/wintun_windows.go
Normal file
@@ -0,0 +1,57 @@
|
||||
//go:build windows
|
||||
|
||||
package platformtun
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"socksrevivepc/internal/wintunloader"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Add(level, format string, args ...any)
|
||||
}
|
||||
|
||||
// Prepare validates and loads Wintun for the current process, then normalizes
|
||||
// the device string used by tun2socks. It intentionally does not pre-open a
|
||||
// WireGuard TUN adapter here: tun2socks must own the live adapter/session.
|
||||
// Pre-opening and closing the adapter before tun2socks can make some Windows
|
||||
// builds close/crash with no useful GUI error.
|
||||
func Prepare(device, interfaceName string, mtu int, logger Logger) (string, string, func(), error) {
|
||||
if mtu <= 0 {
|
||||
mtu = 1500
|
||||
}
|
||||
|
||||
if err := wintunloader.Prepare(logger); err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
|
||||
device = normalizeWindowsDevice(device)
|
||||
interfaceName = normalizeWindowsInterface(interfaceName)
|
||||
if logger != nil {
|
||||
logger.Add("info", "Windows Wintun is ready: adapter=%s device=%s mtu=%d", interfaceName, device, mtu)
|
||||
}
|
||||
return device, interfaceName, nil, nil
|
||||
}
|
||||
|
||||
func normalizeWindowsDevice(device string) string {
|
||||
device = strings.TrimSpace(device)
|
||||
// tun2socks v2 uses the Windows device model name "wintun". Values
|
||||
// like "wintun://SocksRevive" are Linux-style URL device strings and
|
||||
// can make the engine search for a non-existent network interface.
|
||||
if device == "" || strings.EqualFold(device, "tun") || strings.EqualFold(device, "wintun") {
|
||||
return "wintun"
|
||||
}
|
||||
if strings.HasPrefix(strings.ToLower(device), "wintun://") || strings.EqualFold(device, "tun://wintun") {
|
||||
return "wintun"
|
||||
}
|
||||
return "wintun"
|
||||
}
|
||||
|
||||
func normalizeWindowsInterface(interfaceName string) string {
|
||||
interfaceName = strings.TrimSpace(interfaceName)
|
||||
if interfaceName == "" || strings.EqualFold(interfaceName, "SocksRevive") {
|
||||
return "wintun"
|
||||
}
|
||||
return interfaceName
|
||||
}
|
||||
Reference in New Issue
Block a user