sing-box/common/tls/server.go

30 lines
821 B
Go
Raw Normal View History

2022-09-10 02:27:00 +00:00
package tls
import (
"context"
2022-09-30 03:27:18 +00:00
"net"
2022-09-10 02:27:00 +00:00
2023-02-21 06:53:00 +00:00
"github.com/sagernet/sing-box/adapter"
2022-09-30 03:27:18 +00:00
C "github.com/sagernet/sing-box/constant"
2022-09-10 02:27:00 +00:00
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
2023-02-28 03:30:46 +00:00
aTLS "github.com/sagernet/sing/common/tls"
2022-09-10 02:27:00 +00:00
)
2023-02-21 06:53:00 +00:00
func NewServer(ctx context.Context, router adapter.Router, logger log.Logger, options option.InboundTLSOptions) (ServerConfig, error) {
2022-11-13 03:24:37 +00:00
if !options.Enabled {
return nil, nil
}
if options.Reality != nil && options.Reality.Enabled {
return NewRealityServer(ctx, router, logger, options)
} else {
return NewSTDServer(ctx, router, logger, options)
}
2022-09-10 02:27:00 +00:00
}
2022-09-30 03:27:18 +00:00
func ServerHandshake(ctx context.Context, conn net.Conn, config ServerConfig) (Conn, error) {
ctx, cancel := context.WithTimeout(ctx, C.TCPTimeout)
defer cancel()
2023-02-28 03:30:46 +00:00
return aTLS.ServerHandshake(ctx, conn, config)
2022-09-30 03:27:18 +00:00
}