github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/common/tls/server.go (about)

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