server.go 821 B

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