fix: bugs
This commit is contained in:
@@ -73,12 +73,14 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
|
||||
DNSClientOptions: option.DNSClientOptions{
|
||||
IndependentCache: configOpt.IndependentDNSCache,
|
||||
},
|
||||
Final: "dns-remote",
|
||||
Servers: []option.DNSServerOptions{
|
||||
{
|
||||
Tag: "dns-remote",
|
||||
Address: configOpt.RemoteDnsAddress,
|
||||
AddressResolver: "dns-direct",
|
||||
Strategy: configOpt.RemoteDnsDomainStrategy,
|
||||
Detour: "proxy",
|
||||
},
|
||||
{
|
||||
Tag: "dns-direct",
|
||||
|
||||
@@ -94,12 +94,15 @@ func isOutboundReality(base option.Outbound) bool {
|
||||
}
|
||||
|
||||
func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbound, string, error) {
|
||||
var serverDomain string
|
||||
var outbound option.Outbound
|
||||
|
||||
formatErr := func(err error) error {
|
||||
return fmt.Errorf("error patching outbound[%s][%s]: %w", base.Tag, base.Type, err)
|
||||
}
|
||||
err := patchWarp(&base)
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
var outbound option.Outbound
|
||||
|
||||
jsonData, err := base.MarshalJSON()
|
||||
if err != nil {
|
||||
@@ -111,7 +114,7 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
|
||||
var serverDomain string
|
||||
if server, ok := obj["server"].(string); ok {
|
||||
if server != "" && net.ParseIP(server) == nil {
|
||||
serverDomain = fmt.Sprintf("full:%s", server)
|
||||
@@ -134,15 +137,11 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
err = patchWarp(outbound)
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
|
||||
return &outbound, serverDomain, nil
|
||||
}
|
||||
|
||||
func patchWarp(base option.Outbound) error {
|
||||
func patchWarp(base *option.Outbound) error {
|
||||
if base.Type == C.TypeCustom {
|
||||
if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok {
|
||||
key, _ := warp["key"].(string)
|
||||
@@ -151,6 +150,7 @@ func patchWarp(base option.Outbound) error {
|
||||
fakePackets, _ := warp["fake_packets"].(string)
|
||||
warpConfig, err := generateWarp(key, host, uint16(port))
|
||||
if err != nil {
|
||||
fmt.Printf("Error generating warp config: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"os"
|
||||
|
||||
"github.com/hiddify/ray2sing/ray2sing"
|
||||
@@ -23,21 +24,23 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var jsonObj map[string]interface{}
|
||||
|
||||
fmt.Printf("Convert using json\n")
|
||||
jsonDecoder := json.NewDecoder(SJ.NewCommentFilter(bytes.NewReader(content)))
|
||||
if err := jsonDecoder.Decode(&jsonObj); err == nil {
|
||||
if jsonObj["outbounds"] == nil {
|
||||
return nil, fmt.Errorf("[SingboxParser] no outbounds found")
|
||||
}
|
||||
return validateResult(content, "SingboxParser")
|
||||
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
|
||||
return validateResult(newContent, "SingboxParser")
|
||||
}
|
||||
|
||||
fmt.Printf("Convert using v2ray\n")
|
||||
v2rayStr, err := ray2sing.Ray2Singbox(string(content))
|
||||
if err == nil {
|
||||
return validateResult([]byte(v2rayStr), "V2rayParser")
|
||||
}
|
||||
|
||||
fmt.Printf("Convert using clash\n")
|
||||
clashObj := clash.Clash{}
|
||||
if err := yaml.Unmarshal(content, &clashObj); err == nil && clashObj.Proxies != nil {
|
||||
if len(clashObj.Proxies) == 0 {
|
||||
|
||||
4
go.mod
4
go.mod
@@ -3,7 +3,7 @@ module github.com/hiddify/libcore
|
||||
go 1.21.5
|
||||
|
||||
require (
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125183524-4c65b1065c27
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125201255-2626ecb3c77a
|
||||
github.com/sagernet/gomobile v0.1.1
|
||||
github.com/sagernet/sing v0.3.0
|
||||
github.com/sagernet/sing-box v1.8.2
|
||||
@@ -102,6 +102,6 @@ require (
|
||||
lukechampine.com/blake3 v1.2.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125155948-df6318730338
|
||||
replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66
|
||||
|
||||
replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1
|
||||
|
||||
8
go.sum
8
go.sum
@@ -49,10 +49,10 @@ github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5X
|
||||
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
|
||||
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
|
||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125155948-df6318730338 h1:8Sqfq36q1f9La853T/6VnY7IgCvfPL0uhkguyrTl3t8=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125155948-df6318730338/go.mod h1:DnlHl/vlinL9Mn95+qJ3RzgE3E/9pWlAvTsauo7F5HM=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125183524-4c65b1065c27 h1:toSrcgHiLimlQqWaMqN334H8cm7udEsrkwLktko9T58=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125183524-4c65b1065c27/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66 h1:1soOFv4mdCq9OiRN4eo4B0ylDY1EeSnl0M7szOTYNz4=
|
||||
github.com/hiddify/hiddify-sing-box v1.7.9-0.20240125210314-493067cd2d66/go.mod h1:DnlHl/vlinL9Mn95+qJ3RzgE3E/9pWlAvTsauo7F5HM=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125201255-2626ecb3c77a h1:afDHoio+CpOc80Q83ykKsX+aHUQB3BGYj0f3bNybWHs=
|
||||
github.com/hiddify/ray2sing v0.0.0-20240125201255-2626ecb3c77a/go.mod h1:zYKnf7EoPqrk7JOMO9BApTXxfH0sva8AKfoFywN7uuA=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 h1:neOb+wzHbWLNZ2sHFEV4+GTuqORO7/MndQLFW8FjUY8=
|
||||
github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1/go.mod h1:K4J7/npM+VAMUeUmTa2JaA02JmyheP0GpRBOUvn3ecc=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
|
||||
Reference in New Issue
Block a user