add warp in warp & reserved & more more
This commit is contained in:
@@ -5,10 +5,8 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/bepass-org/warp-plus/warp"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
T "github.com/sagernet/sing-box/option"
|
||||
)
|
||||
|
||||
type outboundMap map[string]interface{}
|
||||
@@ -124,7 +122,7 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
||||
formatErr := func(err error) error {
|
||||
return fmt.Errorf("error patching outbound[%s][%s]: %w", base.Tag, base.Type, err)
|
||||
}
|
||||
err := patchWarp(&base, &configOpt)
|
||||
err := patchWarp(&base, &configOpt, true)
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
@@ -167,60 +165,6 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
||||
return &outbound, serverDomain, nil
|
||||
}
|
||||
|
||||
func patchWarp(base *option.Outbound, configOpt *ConfigOptions) error {
|
||||
if base.Type == C.TypeWireGuard {
|
||||
host := base.WireGuardOptions.Server
|
||||
|
||||
if host == "default" || host == "random" || host == "auto" || isBlockedDomain(host) {
|
||||
randomIpPort, _ := warp.RandomWarpEndpoint(true, false)
|
||||
base.WireGuardOptions.Server = randomIpPort.Addr().String()
|
||||
}
|
||||
if base.WireGuardOptions.ServerPort == 0 {
|
||||
port := warp.RandomWarpPort()
|
||||
base.WireGuardOptions.ServerPort = port
|
||||
}
|
||||
// if base.WireGuardOptions.Detour == "" {
|
||||
// base.WireGuardOptions.GSO = runtime.GOOS != "windows"
|
||||
// }
|
||||
}
|
||||
if base.Type == C.TypeCustom {
|
||||
if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok {
|
||||
key, _ := warp["key"].(string)
|
||||
host, _ := warp["host"].(string)
|
||||
port, _ := warp["port"].(float64)
|
||||
detour, _ := warp["detour"].(string)
|
||||
fakePackets, _ := warp["fake_packets"].(string)
|
||||
fakePacketsSize, _ := warp["fake_packets_size"].(string)
|
||||
fakePacketsDelay, _ := warp["fake_packets_delay"].(string)
|
||||
var warpConfig *T.Outbound
|
||||
var err error
|
||||
if configOpt != nil && (key == "p1" || key == "p2") {
|
||||
warpConfig = base
|
||||
} else {
|
||||
warpConfig, err = generateWarp(key, host, uint16(port), fakePackets, fakePacketsSize, fakePacketsDelay)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("Error generating warp config: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
base.Type = C.TypeWireGuard
|
||||
warpConfig.WireGuardOptions.Detour = detour
|
||||
if detour != "" {
|
||||
if warpConfig.WireGuardOptions.MTU > 1000 {
|
||||
warpConfig.WireGuardOptions.MTU -= 50
|
||||
}
|
||||
warpConfig.WireGuardOptions.FakePackets = ""
|
||||
}
|
||||
base.WireGuardOptions = warpConfig.WireGuardOptions
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (o outboundMap) transportType() string {
|
||||
// if transport, ok := o["transport"].(map[string]interface{}); ok {
|
||||
// if transportType, ok := transport["type"].(string); ok {
|
||||
|
||||
Reference in New Issue
Block a user