2020-11-25 19:01:53 +08:00
|
|
|
package internet
|
|
|
|
|
|
2026-01-13 21:31:51 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
|
"github.com/xtls/xray-core/transport/internet/finalmask"
|
|
|
|
|
)
|
2024-11-04 05:00:18 +00:00
|
|
|
|
2024-11-06 17:27:06 +03:00
|
|
|
// MemoryStreamConfig is a parsed form of StreamConfig. It is used to reduce the number of Protobuf parses.
|
2020-11-25 19:01:53 +08:00
|
|
|
type MemoryStreamConfig struct {
|
2024-11-04 05:00:18 +00:00
|
|
|
Destination *net.Destination
|
2020-11-25 19:01:53 +08:00
|
|
|
ProtocolName string
|
|
|
|
|
ProtocolSettings interface{}
|
|
|
|
|
SecurityType string
|
|
|
|
|
SecuritySettings interface{}
|
2026-01-13 21:31:51 +08:00
|
|
|
TcpmaskManager *finalmask.TcpmaskManager
|
|
|
|
|
UdpmaskManager *finalmask.UdpmaskManager
|
2026-03-07 16:46:40 +04:00
|
|
|
QuicParams *QuicParams
|
2020-11-25 19:01:53 +08:00
|
|
|
SocketSettings *SocketConfig
|
2024-11-03 07:25:41 +00:00
|
|
|
DownloadSettings *MemoryStreamConfig
|
2020-11-25 19:01:53 +08: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 {
|
2024-11-04 05:00:18 +00:00
|
|
|
if s.Address != nil {
|
|
|
|
|
mss.Destination = &net.Destination{
|
|
|
|
|
Address: s.Address.AsAddress(),
|
|
|
|
|
Port: net.Port(s.Port),
|
|
|
|
|
Network: net.Network_TCP,
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-25 19:01:53 +08: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
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 21:31:51 +08:00
|
|
|
if s != nil && len(s.Tcpmasks) > 0 {
|
|
|
|
|
var masks []finalmask.Tcpmask
|
|
|
|
|
for _, msg := range s.Tcpmasks {
|
|
|
|
|
instance, err := msg.GetInstance()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
masks = append(masks, instance.(finalmask.Tcpmask))
|
|
|
|
|
}
|
|
|
|
|
mss.TcpmaskManager = finalmask.NewTcpmaskManager(masks)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 16:46:40 +04:00
|
|
|
if s != nil && s.QuicParams != nil {
|
|
|
|
|
mss.QuicParams = s.QuicParams
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 21:31:51 +08:00
|
|
|
if s != nil && len(s.Udpmasks) > 0 {
|
|
|
|
|
var masks []finalmask.Udpmask
|
|
|
|
|
for _, msg := range s.Udpmasks {
|
|
|
|
|
instance, err := msg.GetInstance()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
masks = append(masks, instance.(finalmask.Udpmask))
|
|
|
|
|
}
|
|
|
|
|
mss.UdpmaskManager = finalmask.NewUdpmaskManager(masks)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 19:01:53 +08:00
|
|
|
return mss, nil
|
|
|
|
|
}
|