github.com/sagernet/sing-box@v1.2.7/common/tls/server.go (about) 1 package tls 2 3 import ( 4 "context" 5 "net" 6 7 "github.com/sagernet/sing-box/adapter" 8 C "github.com/sagernet/sing-box/constant" 9 "github.com/sagernet/sing-box/log" 10 "github.com/sagernet/sing-box/option" 11 aTLS "github.com/sagernet/sing/common/tls" 12 ) 13 14 func NewServer(ctx context.Context, router adapter.Router, logger log.Logger, options option.InboundTLSOptions) (ServerConfig, error) { 15 if !options.Enabled { 16 return nil, nil 17 } 18 if options.Reality != nil && options.Reality.Enabled { 19 return NewRealityServer(ctx, router, logger, options) 20 } else { 21 return NewSTDServer(ctx, router, logger, options) 22 } 23 } 24 25 func ServerHandshake(ctx context.Context, conn net.Conn, config ServerConfig) (Conn, error) { 26 ctx, cancel := context.WithTimeout(ctx, C.TCPTimeout) 27 defer cancel() 28 return aTLS.ServerHandshake(ctx, conn, config) 29 }