new: add early support for
This commit is contained in:
@@ -258,7 +258,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
Type: C.RuleTypeDefault,
|
||||
DefaultOptions: option.DefaultRule{
|
||||
GeoIP: []string{"private"},
|
||||
Outbound: OutboundBypassTag,
|
||||
Outbound: OutboundBypassTag,
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -388,6 +388,17 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
|
||||
var outbounds []option.Outbound
|
||||
var tags []string
|
||||
if opt.WarpOptions != nil && (opt.WarpOptions.Mode == "proxy_over_warp" || opt.WarpOptions.Mode == "warp_over_proxy") {
|
||||
out, err := generateWarpSingbox(opt.WarpOptions.WireguardConfig, opt.WarpOptions.CleanIP, opt.WarpOptions.CleanPort, opt.WarpOptions.FakePackets, opt.WarpOptions.FakePacketSize, opt.WarpOptions.FakePacketDelay)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
||||
}
|
||||
out.Tag = "Hiddify Warp Config"
|
||||
if opt.WarpOptions.Mode == "warp_over_proxy" {
|
||||
out.WireGuardOptions.Detour = "select"
|
||||
}
|
||||
outbounds = append(outbounds, *out)
|
||||
}
|
||||
for _, out := range input.Outbounds {
|
||||
outbound, serverDomain, err := patchOutbound(out, opt)
|
||||
if err != nil {
|
||||
@@ -410,6 +421,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
if !strings.Contains(out.Tag, "§hide§") {
|
||||
tags = append(tags, out.Tag)
|
||||
}
|
||||
out = patchHiddifyWarpFromConfig(out, opt)
|
||||
outbounds = append(outbounds, out)
|
||||
}
|
||||
}
|
||||
@@ -502,6 +514,27 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
return &options, nil
|
||||
}
|
||||
|
||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||
if opt.WarpOptions != nil && opt.WarpOptions.Mode == "proxy_over_warp" {
|
||||
out.DirectOptions.Detour = "Hiddify Warp Config"
|
||||
out.HTTPOptions.Detour = "Hiddify Warp Config"
|
||||
out.Hysteria2Options.Detour = "Hiddify Warp Config"
|
||||
out.HysteriaOptions.Detour = "Hiddify Warp Config"
|
||||
out.SSHOptions.Detour = "Hiddify Warp Config"
|
||||
out.ShadowTLSOptions.Detour = "Hiddify Warp Config"
|
||||
out.ShadowsocksOptions.Detour = "Hiddify Warp Config"
|
||||
out.ShadowsocksROptions.Detour = "Hiddify Warp Config"
|
||||
out.SocksOptions.Detour = "Hiddify Warp Config"
|
||||
out.TUICOptions.Detour = "Hiddify Warp Config"
|
||||
out.TorOptions.Detour = "Hiddify Warp Config"
|
||||
out.TrojanOptions.Detour = "Hiddify Warp Config"
|
||||
out.VLESSOptions.Detour = "Hiddify Warp Config"
|
||||
out.VMessOptions.Detour = "Hiddify Warp Config"
|
||||
out.WireGuardOptions.Detour = "Hiddify Warp Config"
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func getIPs(domains []string) []string {
|
||||
res := []string{}
|
||||
for _, d := range domains {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/bepass-org/wireguard-go/warp"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
dns "github.com/sagernet/sing-dns"
|
||||
)
|
||||
@@ -18,6 +19,7 @@ type ConfigOptions struct {
|
||||
RouteOptions
|
||||
MuxOptions
|
||||
TLSTricks
|
||||
*WarpOptions
|
||||
}
|
||||
|
||||
type DNSOptions struct {
|
||||
@@ -70,6 +72,17 @@ type MuxOptions struct {
|
||||
MuxProtocol string `json:"mux-protocol"`
|
||||
}
|
||||
|
||||
type WarpOptions struct {
|
||||
Mode string `json:"mode"`
|
||||
WarpAccount
|
||||
warp.WireguardConfig
|
||||
FakePackets string `json:"fake-packets"`
|
||||
FakePacketSize string `json:"fake-packet-size"`
|
||||
FakePacketDelay string `json:"fake-packet-delay"`
|
||||
CleanIP string `json:"clean-ip"`
|
||||
CleanPort uint16 `json:"clean-port"`
|
||||
}
|
||||
|
||||
func DefaultConfigOptions() *ConfigOptions {
|
||||
return &ConfigOptions{
|
||||
DNSOptions: DNSOptions{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/netip"
|
||||
@@ -89,6 +88,20 @@ func generateRandomPort() uint16 {
|
||||
}
|
||||
|
||||
func generateWarp(license string, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string) (*T.Outbound, error) {
|
||||
|
||||
_, _, wgConfig, err := warp.LoadOrCreateIdentityHiddify(license, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if wgConfig == nil {
|
||||
return nil, fmt.Errorf("invalid warp config")
|
||||
}
|
||||
fmt.Printf("%v", wgConfig)
|
||||
|
||||
return generateWarpSingbox(*wgConfig, host, port, fakePackets, fakePacketsSize, fakePacketsDelay)
|
||||
}
|
||||
|
||||
func generateWarpSingbox(wgConfig warp.WireguardConfig, host string, port uint16, fakePackets string, fakePacketsSize string, fakePacketsDelay string) (*T.Outbound, error) {
|
||||
if host == "" || isBlockedDomain(host) {
|
||||
host = "auto"
|
||||
}
|
||||
@@ -102,16 +115,7 @@ func generateWarp(license string, host string, port uint16, fakePackets string,
|
||||
if fakePackets != "" && fakePacketsDelay == "" {
|
||||
fakePacketsDelay = "20-250"
|
||||
}
|
||||
|
||||
_, _, wgConfig, err := warp.LoadOrCreateIdentityHiddify(license, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if wgConfig == nil {
|
||||
return nil, fmt.Errorf("invalid warp config")
|
||||
}
|
||||
fmt.Printf("%v", wgConfig)
|
||||
singboxConfig, err := wireGuardToSingbox(*wgConfig, host, port)
|
||||
singboxConfig, err := wireGuardToSingbox(wgConfig, host, port)
|
||||
if err != nil {
|
||||
fmt.Printf("%v %v", singboxConfig, err)
|
||||
return nil, err
|
||||
@@ -120,13 +124,7 @@ func generateWarp(license string, host string, port uint16, fakePackets string,
|
||||
singboxConfig.WireGuardOptions.FakePackets = fakePackets
|
||||
singboxConfig.WireGuardOptions.FakePacketsSize = fakePacketsSize
|
||||
singboxConfig.WireGuardOptions.FakePacketsDelay = fakePacketsDelay
|
||||
singboxJSON, err := json.MarshalIndent(singboxConfig, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println("Error marshaling Singbox configuration:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println(string(singboxJSON))
|
||||
return singboxConfig, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user