mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
added V5 config builder for outbound
This commit is contained in:
parent
9f145b4265
commit
2560e79ef0
53
infra/conf/v5cfg/outbound.go
Normal file
53
infra/conf/v5cfg/outbound.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package v5cfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
core "github.com/v2fly/v2ray-core/v4"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/proxyman"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/common/serial"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/transport/internet"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c OutboundConfig) BuildV5(ctx context.Context) (proto.Message, error) {
|
||||||
|
senderSettings := &proxyman.SenderConfig{}
|
||||||
|
|
||||||
|
if c.SendThrough != nil {
|
||||||
|
address := c.SendThrough
|
||||||
|
if address.Family().IsDomain() {
|
||||||
|
return nil, newError("unable to send through: " + address.String())
|
||||||
|
}
|
||||||
|
senderSettings.Via = address.Build()
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.StreamSetting != nil {
|
||||||
|
ss, err := c.StreamSetting.BuildV5(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
senderSettings.StreamSettings = ss.(*internet.StreamConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.ProxySettings != nil {
|
||||||
|
ps, err := c.ProxySettings.Build()
|
||||||
|
if err != nil {
|
||||||
|
return nil, newError("invalid outbound detour proxy settings.").Base(err)
|
||||||
|
}
|
||||||
|
senderSettings.ProxySettings = ps
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.MuxSettings != nil {
|
||||||
|
senderSettings.MultiplexSettings = c.MuxSettings.Build()
|
||||||
|
}
|
||||||
|
|
||||||
|
outboundConfigPack, err := loadHeterogeneousConfigFromRawJson("outbound", c.Protocol, c.Settings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, newError("unable to load outbound protocol config").Base(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &core.OutboundHandlerConfig{
|
||||||
|
SenderSettings: serial.ToTypedMessage(senderSettings),
|
||||||
|
Tag: c.Tag,
|
||||||
|
ProxySettings: serial.ToTypedMessage(outboundConfigPack),
|
||||||
|
}, nil
|
||||||
|
}
|
@ -35,7 +35,7 @@ type OutboundConfig struct {
|
|||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
SendThrough *cfgcommon.Address `json:"sendThrough"`
|
SendThrough *cfgcommon.Address `json:"sendThrough"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Settings *json.RawMessage `json:"settings"`
|
Settings json.RawMessage `json:"settings"`
|
||||||
StreamSetting *StreamConfig `json:"streamSettings"`
|
StreamSetting *StreamConfig `json:"streamSettings"`
|
||||||
ProxySettings *proxycfg.ProxyConfig `json:"proxySettings"`
|
ProxySettings *proxycfg.ProxyConfig `json:"proxySettings"`
|
||||||
MuxSettings *muxcfg.MuxConfig `json:"mux"`
|
MuxSettings *muxcfg.MuxConfig `json:"mux"`
|
||||||
|
Loading…
Reference in New Issue
Block a user