serverspec_materialize.go 2.1 KB

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