github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/app/subscription/subscriptionmanager/serverspec_materialize.go (about)

     1  package subscriptionmanager
     2  
     3  import (
     4  	core "github.com/v2fly/v2ray-core/v5"
     5  	"github.com/v2fly/v2ray-core/v5/app/proxyman"
     6  	"github.com/v2fly/v2ray-core/v5/app/subscription/specs"
     7  	"github.com/v2fly/v2ray-core/v5/common/serial"
     8  	"github.com/v2fly/v2ray-core/v5/transport/internet"
     9  )
    10  
    11  func (s *SubscriptionManagerImpl) materialize(subscriptionName, tagName string, serverSpec *specs.SubscriptionServerConfig) (*core.OutboundHandlerConfig, error) {
    12  	outboundConf, err := s.getOutboundTemplateForSubscriptionName(subscriptionName)
    13  	if err != nil {
    14  		return nil, newError("failed to get outbound template for subscription name: ", err)
    15  	}
    16  
    17  	senderSettingsIfcd, err := serial.GetInstanceOf(outboundConf.SenderSettings)
    18  	if err != nil {
    19  		return nil, newError("failed to get sender settings: ", err)
    20  	}
    21  	senderSettings := senderSettingsIfcd.(*proxyman.SenderConfig)
    22  
    23  	if serverSpec.Configuration.Transport != "" {
    24  		senderSettings.StreamSettings.ProtocolName = serverSpec.Configuration.Transport
    25  		senderSettings.StreamSettings.TransportSettings = append(senderSettings.StreamSettings.TransportSettings,
    26  			&internet.TransportConfig{ProtocolName: serverSpec.Configuration.Transport, Settings: serverSpec.Configuration.TransportSettings})
    27  	}
    28  
    29  	if serverSpec.Configuration.Security != "" {
    30  		senderSettings.StreamSettings.SecurityType = serverSpec.Configuration.Security
    31  		senderSettings.StreamSettings.SecuritySettings = append(senderSettings.StreamSettings.SecuritySettings,
    32  			serverSpec.Configuration.SecuritySettings)
    33  	}
    34  
    35  	outboundConf.SenderSettings = serial.ToTypedMessage(senderSettings)
    36  
    37  	outboundConf.ProxySettings = serverSpec.Configuration.ProtocolSettings
    38  
    39  	outboundConf.Tag = tagName
    40  
    41  	return outboundConf, nil
    42  }
    43  
    44  func (s *SubscriptionManagerImpl) getOutboundTemplateForSubscriptionName(subscriptionName string) (*core.OutboundHandlerConfig, error) { //nolint: unparam
    45  	senderSetting := &proxyman.SenderConfig{
    46  		DomainStrategy: proxyman.SenderConfig_AS_IS, StreamSettings: &internet.StreamConfig{},
    47  	}
    48  
    49  	return &core.OutboundHandlerConfig{SenderSettings: serial.ToTypedMessage(senderSetting)}, nil
    50  }