mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-09-20 07:06:01 +00:00
Add files via upload
This commit is contained in:
48
service/controller/outboundbuilder.go
Normal file
48
service/controller/outboundbuilder.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/XrayR-project/XrayR/api"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/infra/conf"
|
||||
)
|
||||
|
||||
//OutboundBuilder build freedom outbund config for addoutbound
|
||||
func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
|
||||
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{ipAddress}
|
||||
}
|
||||
|
||||
// Freedom Protocol setting
|
||||
var domainStrategy string = "Asis"
|
||||
if config.EnableDNS {
|
||||
if config.DNSType != "" {
|
||||
domainStrategy = config.DNSType
|
||||
} else {
|
||||
domainStrategy = "UseIP"
|
||||
}
|
||||
}
|
||||
proxySetting := &conf.FreedomConfig{
|
||||
DomainStrategy: domainStrategy,
|
||||
}
|
||||
// Used for Shadowsocks-Plugin
|
||||
if nodeInfo.NodeType == "dokodemo-door" {
|
||||
proxySetting.Redirect = fmt.Sprintf("127.0.0.1:%d", nodeInfo.Port-1)
|
||||
}
|
||||
var setting json.RawMessage
|
||||
setting, err := json.Marshal(proxySetting)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||
}
|
||||
outboundDetourConfig.Settings = &setting
|
||||
return outboundDetourConfig.Build()
|
||||
}
|
Reference in New Issue
Block a user