V2bX/core/xray/outbound.go

43 lines
1.1 KiB
Go
Raw Normal View History

2023-07-13 01:44:15 +08:00
package xray
2022-06-02 01:35:41 +08:00
import (
"fmt"
2023-07-28 09:13:11 +08:00
2023-07-29 19:27:15 +08:00
conf2 "github.com/InazumaV/V2bX/conf"
"github.com/goccy/go-json"
2022-06-02 01:35:41 +08:00
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/infra/conf"
)
2023-05-22 21:01:31 +08:00
// BuildOutbound build freedom outbund config for addoutbound
2023-07-29 18:47:47 +08:00
func buildOutbound(config *conf2.Options, tag string) (*core.OutboundHandlerConfig, error) {
2022-06-02 01:35:41 +08:00
outboundDetourConfig := &conf.OutboundDetourConfig{}
outboundDetourConfig.Protocol = "freedom"
outboundDetourConfig.Tag = tag
// Build Send IP address
if config.SendIP != "" {
2024-06-13 00:06:22 +09:00
outboundDetourConfig.SendThrough = &config.SendIP
2022-06-02 01:35:41 +08:00
}
// Freedom Protocol setting
var domainStrategy = "Asis"
if config.XrayOptions.EnableDNS {
if config.XrayOptions.DNSType != "" {
domainStrategy = config.XrayOptions.DNSType
2022-06-02 01:35:41 +08:00
} else {
domainStrategy = "UseIP"
}
}
proxySetting := &conf.FreedomConfig{
DomainStrategy: domainStrategy,
}
var setting json.RawMessage
setting, err := json.Marshal(proxySetting)
if err != nil {
return nil, fmt.Errorf("marshal proxy config error: %s", err)
2022-06-02 01:35:41 +08:00
}
outboundDetourConfig.Settings = &setting
return outboundDetourConfig.Build()
}