V2bX/common/builder/outbound.go

44 lines
1.2 KiB
Go
Raw Normal View History

2023-05-22 09:01:31 -04:00
package builder
2022-06-01 13:35:41 -04:00
import (
"fmt"
conf2 "github.com/Yuzuki616/V2bX/conf"
"github.com/goccy/go-json"
2022-06-01 13:35:41 -04:00
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/infra/conf"
)
2023-05-22 09:01:31 -04:00
// BuildOutbound build freedom outbund config for addoutbound
func BuildOutbound(config *conf2.ControllerConfig, tag string) (*core.OutboundHandlerConfig, error) {
2022-06-01 13:35:41 -04:00
outboundDetourConfig := &conf.OutboundDetourConfig{}
outboundDetourConfig.Protocol = "freedom"
outboundDetourConfig.Tag = tag
// Build Send IP address
if config.SendIP != "" {
ipAddress := net.ParseAddress(config.SendIP)
outboundDetourConfig.SendThrough = &conf.Address{Address: ipAddress}
2022-06-01 13:35:41 -04:00
}
// Freedom Protocol setting
var domainStrategy = "Asis"
if config.XrayOptions.EnableDNS {
if config.XrayOptions.DNSType != "" {
domainStrategy = config.XrayOptions.DNSType
2022-06-01 13:35:41 -04: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-01 13:35:41 -04:00
}
outboundDetourConfig.Settings = &setting
return outboundDetourConfig.Build()
}