2023-05-15 21:15:29 -04:00
|
|
|
package node
|
2022-06-01 13:35:41 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-08-16 01:04:33 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/api/panel"
|
2022-07-28 11:00:05 -04:00
|
|
|
conf2 "github.com/Yuzuki616/V2bX/conf"
|
2022-12-18 10:31:06 -05:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2022-10-09 20:59:00 -04:00
|
|
|
// buildOutbound build freedom outbund config for addoutbound
|
|
|
|
func buildOutbound(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, 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)
|
2022-06-04 05:12:28 -04:00
|
|
|
outboundDetourConfig.SendThrough = &conf.Address{Address: ipAddress}
|
2022-06-01 13:35:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Freedom Protocol setting
|
2022-06-04 05:12:28 -04:00
|
|
|
var domainStrategy = "Asis"
|
2022-06-01 13:35:41 -04:00
|
|
|
if config.EnableDNS {
|
|
|
|
if config.DNSType != "" {
|
|
|
|
domainStrategy = config.DNSType
|
|
|
|
} else {
|
|
|
|
domainStrategy = "UseIP"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proxySetting := &conf.FreedomConfig{
|
|
|
|
DomainStrategy: domainStrategy,
|
|
|
|
}
|
|
|
|
var setting json.RawMessage
|
|
|
|
setting, err := json.Marshal(proxySetting)
|
|
|
|
if err != nil {
|
2022-06-04 05:12:28 -04:00
|
|
|
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
2022-06-01 13:35:41 -04:00
|
|
|
}
|
|
|
|
outboundDetourConfig.Settings = &setting
|
|
|
|
return outboundDetourConfig.Build()
|
|
|
|
}
|