Files

69 lines
1.5 KiB
Go
Raw Permalink Normal View History

2023-02-15 16:07:12 +00:00
package reality
import (
2024-06-29 14:32:57 -04:00
"context"
2024-01-11 14:36:13 +08:00
"io"
"net"
2024-01-11 14:36:13 +08:00
"os"
2023-02-15 16:07:12 +00:00
"time"
"github.com/xtls/reality"
2024-06-29 14:32:57 -04:00
"github.com/xtls/xray-core/common/errors"
2023-02-15 16:07:12 +00:00
"github.com/xtls/xray-core/transport/internet"
)
func (c *Config) GetREALITYConfig() *reality.Config {
var dialer net.Dialer
2023-02-15 16:07:12 +00:00
config := &reality.Config{
DialContext: dialer.DialContext,
2023-02-15 16:07:12 +00:00
Show: c.Show,
Type: c.Type,
Dest: c.Dest,
Xver: byte(c.Xver),
PrivateKey: c.PrivateKey,
MinClientVer: c.MinClientVer,
MaxClientVer: c.MaxClientVer,
MaxTimeDiff: time.Duration(c.MaxTimeDiff) * time.Millisecond,
NextProtos: nil, // should be nil
SessionTicketsDisabled: true,
2024-01-11 14:36:13 +08:00
KeyLogWriter: KeyLogWriterFromConfig(c),
2023-02-15 16:07:12 +00:00
}
config.ServerNames = make(map[string]bool)
for _, serverName := range c.ServerNames {
config.ServerNames[serverName] = true
}
config.ShortIds = make(map[[8]byte]bool)
for _, shortId := range c.ShortIds {
config.ShortIds[*(*[8]byte)(shortId)] = true
}
return config
}
2024-01-11 14:36:13 +08:00
func KeyLogWriterFromConfig(c *Config) io.Writer {
if len(c.MasterKeyLog) <= 0 || c.MasterKeyLog == "none" {
return nil
}
writer, err := os.OpenFile(c.MasterKeyLog, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
if err != nil {
2024-06-29 14:32:57 -04:00
errors.LogErrorInner(context.Background(), err, "failed to open ", c.MasterKeyLog, " as master key log")
2024-01-11 14:36:13 +08:00
}
return writer
}
2023-02-15 16:07:12 +00:00
func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config {
if settings == nil {
return nil
}
config, ok := settings.SecuritySettings.(*Config)
if !ok {
return nil
}
return config
}