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,
|
Type: C.RuleTypeDefault,
|
||||||
DefaultOptions: option.DefaultRule{
|
DefaultOptions: option.DefaultRule{
|
||||||
GeoIP: []string{"private"},
|
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 outbounds []option.Outbound
|
||||||
var tags []string
|
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 {
|
for _, out := range input.Outbounds {
|
||||||
outbound, serverDomain, err := patchOutbound(out, opt)
|
outbound, serverDomain, err := patchOutbound(out, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -410,6 +421,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
if !strings.Contains(out.Tag, "§hide§") {
|
if !strings.Contains(out.Tag, "§hide§") {
|
||||||
tags = append(tags, out.Tag)
|
tags = append(tags, out.Tag)
|
||||||
}
|
}
|
||||||
|
out = patchHiddifyWarpFromConfig(out, opt)
|
||||||
outbounds = append(outbounds, out)
|
outbounds = append(outbounds, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,6 +514,27 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
return &options, nil
|
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 {
|
func getIPs(domains []string) []string {
|
||||||
res := []string{}
|
res := []string{}
|
||||||
for _, d := range domains {
|
for _, d := range domains {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/bepass-org/wireguard-go/warp"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
dns "github.com/sagernet/sing-dns"
|
dns "github.com/sagernet/sing-dns"
|
||||||
)
|
)
|
||||||
@@ -18,6 +19,7 @@ type ConfigOptions struct {
|
|||||||
RouteOptions
|
RouteOptions
|
||||||
MuxOptions
|
MuxOptions
|
||||||
TLSTricks
|
TLSTricks
|
||||||
|
*WarpOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
type DNSOptions struct {
|
type DNSOptions struct {
|
||||||
@@ -70,6 +72,17 @@ type MuxOptions struct {
|
|||||||
MuxProtocol string `json:"mux-protocol"`
|
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 {
|
func DefaultConfigOptions() *ConfigOptions {
|
||||||
return &ConfigOptions{
|
return &ConfigOptions{
|
||||||
DNSOptions: DNSOptions{
|
DNSOptions: DNSOptions{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/netip"
|
"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) {
|
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) {
|
if host == "" || isBlockedDomain(host) {
|
||||||
host = "auto"
|
host = "auto"
|
||||||
}
|
}
|
||||||
@@ -102,16 +115,7 @@ func generateWarp(license string, host string, port uint16, fakePackets string,
|
|||||||
if fakePackets != "" && fakePacketsDelay == "" {
|
if fakePackets != "" && fakePacketsDelay == "" {
|
||||||
fakePacketsDelay = "20-250"
|
fakePacketsDelay = "20-250"
|
||||||
}
|
}
|
||||||
|
singboxConfig, err := wireGuardToSingbox(wgConfig, host, port)
|
||||||
_, _, 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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%v %v", singboxConfig, err)
|
fmt.Printf("%v %v", singboxConfig, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -120,13 +124,7 @@ func generateWarp(license string, host string, port uint16, fakePackets string,
|
|||||||
singboxConfig.WireGuardOptions.FakePackets = fakePackets
|
singboxConfig.WireGuardOptions.FakePackets = fakePackets
|
||||||
singboxConfig.WireGuardOptions.FakePacketsSize = fakePacketsSize
|
singboxConfig.WireGuardOptions.FakePacketsSize = fakePacketsSize
|
||||||
singboxConfig.WireGuardOptions.FakePacketsDelay = fakePacketsDelay
|
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
|
return singboxConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
go.mod
3
go.mod
@@ -19,6 +19,7 @@ require (
|
|||||||
require (
|
require (
|
||||||
berty.tech/go-libtor v1.0.385 // indirect
|
berty.tech/go-libtor v1.0.385 // indirect
|
||||||
github.com/ajg/form v1.5.1 // indirect
|
github.com/ajg/form v1.5.1 // indirect
|
||||||
|
github.com/akavel/rsrc v0.10.2 // indirect
|
||||||
github.com/andybalholm/brotli v1.0.6 // indirect
|
github.com/andybalholm/brotli v1.0.6 // indirect
|
||||||
github.com/caddyserver/certmagic v0.20.0 // indirect
|
github.com/caddyserver/certmagic v0.20.0 // indirect
|
||||||
github.com/cloudflare/circl v1.3.7 // indirect
|
github.com/cloudflare/circl v1.3.7 // indirect
|
||||||
@@ -104,7 +105,7 @@ require (
|
|||||||
lukechampine.com/blake3 v1.2.1 // indirect
|
lukechampine.com/blake3 v1.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.6-0.20240216185805-d761a1b2b609
|
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.8.6-0.20240219213330-bd64e4e35e00
|
||||||
|
|
||||||
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240214142457-fadc619f4357
|
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240214142457-fadc619f4357
|
||||||
|
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -2,6 +2,8 @@ berty.tech/go-libtor v1.0.385 h1:RWK94C3hZj6Z2GdvePpHJLnWYobFr3bY/OdUJ5aoEXw=
|
|||||||
berty.tech/go-libtor v1.0.385/go.mod h1:9swOOQVb+kmvuAlsgWUK/4c52pm69AdbJsxLzk+fJEw=
|
berty.tech/go-libtor v1.0.385/go.mod h1:9swOOQVb+kmvuAlsgWUK/4c52pm69AdbJsxLzk+fJEw=
|
||||||
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
|
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
|
||||||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
||||||
|
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
|
||||||
|
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||||
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
|
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
|
||||||
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||||
github.com/caddyserver/certmagic v0.20.0 h1:bTw7LcEZAh9ucYCRXyCpIrSAGplplI0vGYJ4BpCQ/Fc=
|
github.com/caddyserver/certmagic v0.20.0 h1:bTw7LcEZAh9ucYCRXyCpIrSAGplplI0vGYJ4BpCQ/Fc=
|
||||||
@@ -51,8 +53,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
|
|||||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240215114454-3acea56c88fc h1:7Nbu6wraBxlYZzBCcacGwMP8iv1cxbToFRLDeZgajdo=
|
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240215114454-3acea56c88fc h1:7Nbu6wraBxlYZzBCcacGwMP8iv1cxbToFRLDeZgajdo=
|
||||||
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240215114454-3acea56c88fc/go.mod h1:E1qZQpw2IrbRtFpTloTHGfJ2bJc4ZpZRNS497Eq5jCo=
|
github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240215114454-3acea56c88fc/go.mod h1:E1qZQpw2IrbRtFpTloTHGfJ2bJc4ZpZRNS497Eq5jCo=
|
||||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240216185805-d761a1b2b609 h1:toWbGTpKIDsp0aDwghUd3KMuOGoaX7MTLunzRuzelnw=
|
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240219213330-bd64e4e35e00 h1:ff/d4hMZTQv0DNAIr6Oiov4juvLjzazvGPvTimNeCpo=
|
||||||
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240216185805-d761a1b2b609/go.mod h1:usnCk4Fbp/3HAJ+b7LnogPP7x4En2Kc4ujNlnDsi1Sc=
|
github.com/hiddify/hiddify-sing-box v1.8.6-0.20240219213330-bd64e4e35e00/go.mod h1:usnCk4Fbp/3HAJ+b7LnogPP7x4En2Kc4ujNlnDsi1Sc=
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a h1:ObxmZ8AyhIxtH2Vu+vmDAsxsbsTPGq9pJzcY0V+3BCU=
|
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a h1:ObxmZ8AyhIxtH2Vu+vmDAsxsbsTPGq9pJzcY0V+3BCU=
|
||||||
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
github.com/hiddify/ray2sing v0.0.0-20240213091709-ba1d827e4f4a/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||||
github.com/hiddify/wireguard-go v0.0.0-20240214142457-fadc619f4357 h1:INJqz+o+vG0DqCKxVyAhpFrRPH3QyzbggmXsfCNd7+k=
|
github.com/hiddify/wireguard-go v0.0.0-20240214142457-fadc619f4357 h1:INJqz+o+vG0DqCKxVyAhpFrRPH3QyzbggmXsfCNd7+k=
|
||||||
|
|||||||
Reference in New Issue
Block a user