Xray-core/transport/internet/memory_settings.go

50 lines
1.2 KiB
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package internet
import "github.com/xtls/xray-core/common/net"
2024-07-11 22:20:06 +00:00
// MemoryStreamConfig is a parsed form of StreamConfig. This is used to reduce the number of Protobuf parsings.
2020-11-25 11:01:53 +00:00
type MemoryStreamConfig struct {
Destination *net.Destination
2020-11-25 11:01:53 +00:00
ProtocolName string
ProtocolSettings interface{}
SecurityType string
SecuritySettings interface{}
SocketSettings *SocketConfig
DownloadSettings *MemoryStreamConfig
2020-11-25 11:01:53 +00:00
}
// ToMemoryStreamConfig converts a StreamConfig to MemoryStreamConfig. It returns a default non-nil MemoryStreamConfig for nil input.
func ToMemoryStreamConfig(s *StreamConfig) (*MemoryStreamConfig, error) {
ets, err := s.GetEffectiveTransportSettings()
if err != nil {
return nil, err
}
mss := &MemoryStreamConfig{
ProtocolName: s.GetEffectiveProtocol(),
ProtocolSettings: ets,
}
if s != nil {
if s.Address != nil {
mss.Destination = &net.Destination{
Address: s.Address.AsAddress(),
Port: net.Port(s.Port),
Network: net.Network_TCP,
}
}
2020-11-25 11:01:53 +00:00
mss.SocketSettings = s.SocketSettings
}
if s != nil && s.HasSecuritySettings() {
ess, err := s.GetEffectiveSecuritySettings()
if err != nil {
return nil, err
}
mss.SecurityType = s.SecurityType
mss.SecuritySettings = ess
}
return mss, nil
}