github.com/imannamdari/v2ray-core/v5@v5.0.5/infra/conf/v5cfg/outbound.go (about)

     1  package v5cfg
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/golang/protobuf/proto"
     7  
     8  	core "github.com/imannamdari/v2ray-core/v5"
     9  	"github.com/imannamdari/v2ray-core/v5/app/proxyman"
    10  	"github.com/imannamdari/v2ray-core/v5/common/serial"
    11  	"github.com/imannamdari/v2ray-core/v5/transport/internet"
    12  )
    13  
    14  func (c OutboundConfig) BuildV5(ctx context.Context) (proto.Message, error) {
    15  	senderSettings := &proxyman.SenderConfig{}
    16  
    17  	if c.SendThrough != nil {
    18  		address := c.SendThrough
    19  		if address.Family().IsDomain() {
    20  			return nil, newError("unable to send through: " + address.String())
    21  		}
    22  		senderSettings.Via = address.Build()
    23  	}
    24  
    25  	if c.StreamSetting != nil {
    26  		ss, err := c.StreamSetting.BuildV5(ctx)
    27  		if err != nil {
    28  			return nil, err
    29  		}
    30  		senderSettings.StreamSettings = ss.(*internet.StreamConfig)
    31  	}
    32  
    33  	if c.ProxySettings != nil {
    34  		ps, err := c.ProxySettings.Build()
    35  		if err != nil {
    36  			return nil, newError("invalid outbound detour proxy settings.").Base(err)
    37  		}
    38  		senderSettings.ProxySettings = ps
    39  	}
    40  
    41  	if c.MuxSettings != nil {
    42  		senderSettings.MultiplexSettings = c.MuxSettings.Build()
    43  	}
    44  
    45  	if c.Settings == nil {
    46  		c.Settings = []byte("{}")
    47  	}
    48  
    49  	outboundConfigPack, err := loadHeterogeneousConfigFromRawJSON("outbound", c.Protocol, c.Settings)
    50  	if err != nil {
    51  		return nil, newError("unable to load outbound protocol config").Base(err)
    52  	}
    53  
    54  	return &core.OutboundHandlerConfig{
    55  		SenderSettings: serial.ToTypedMessage(senderSettings),
    56  		Tag:            c.Tag,
    57  		ProxySettings:  serial.ToTypedMessage(outboundConfigPack),
    58  	}, nil
    59  }