1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-27 20:46:51 -05:00
v2fly/transport/internet/memory_settings.go

39 lines
978 B
Go
Raw Normal View History

2018-09-07 08:50:25 -04:00
package internet
2018-10-14 02:23:49 -04:00
// MemoryStreamConfig is a parsed form of StreamConfig. This is used to reduce number of Protobuf parsing.
2018-09-07 08:50:25 -04:00
type MemoryStreamConfig struct {
ProtocolName string
ProtocolSettings interface{}
SecurityType string
SecuritySettings interface{}
SocketSettings *SocketConfig
}
2018-10-14 02:23:49 -04:00
// ToMemoryStreamConfig converts a StreamConfig to MemoryStreamConfig. It returns a default non-nil MemoryStreamConfig for nil input.
2018-09-07 08:50:25 -04:00
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 {
mss.SocketSettings = s.SocketSettings
2018-09-07 08:50:25 -04:00
}
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
}