github.com/xmplusdev/xray-core@v1.8.10/transport/internet/reality/config.go (about)

     1  package reality
     2  
     3  import (
     4  	"io"
     5  	"net"
     6  	"os"
     7  	"time"
     8  
     9  	"github.com/xtls/reality"
    10  	"github.com/xmplusdev/xray-core/transport/internet"
    11  )
    12  
    13  func (c *Config) GetREALITYConfig() *reality.Config {
    14  	var dialer net.Dialer
    15  	config := &reality.Config{
    16  		DialContext: dialer.DialContext,
    17  
    18  		Show: c.Show,
    19  		Type: c.Type,
    20  		Dest: c.Dest,
    21  		Xver: byte(c.Xver),
    22  
    23  		PrivateKey:   c.PrivateKey,
    24  		MinClientVer: c.MinClientVer,
    25  		MaxClientVer: c.MaxClientVer,
    26  		MaxTimeDiff:  time.Duration(c.MaxTimeDiff) * time.Millisecond,
    27  
    28  		NextProtos:             nil, // should be nil
    29  		SessionTicketsDisabled: true,
    30  
    31  		KeyLogWriter: KeyLogWriterFromConfig(c),
    32  	}
    33  	config.ServerNames = make(map[string]bool)
    34  	for _, serverName := range c.ServerNames {
    35  		config.ServerNames[serverName] = true
    36  	}
    37  	config.ShortIds = make(map[[8]byte]bool)
    38  	for _, shortId := range c.ShortIds {
    39  		config.ShortIds[*(*[8]byte)(shortId)] = true
    40  	}
    41  	return config
    42  }
    43  
    44  func KeyLogWriterFromConfig(c *Config) io.Writer {
    45  	if len(c.MasterKeyLog) <= 0 || c.MasterKeyLog == "none" {
    46  		return nil
    47  	}
    48  
    49  	writer, err := os.OpenFile(c.MasterKeyLog, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644)
    50  	if err != nil {
    51  		newError("failed to open ", c.MasterKeyLog, " as master key log").AtError().Base(err).WriteToLog()
    52  	}
    53  
    54  	return writer
    55  }
    56  
    57  func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config {
    58  	if settings == nil {
    59  		return nil
    60  	}
    61  	config, ok := settings.SecuritySettings.(*Config)
    62  	if !ok {
    63  		return nil
    64  	}
    65  	return config
    66  }