server.go 841 B

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