mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 21:26:07 +03:00
gRPC: add keepalive option for server
This commit is contained in:
parent
d9d04a230f
commit
57b9006d26
@ -2,9 +2,11 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
|
"google.golang.org/grpc/keepalive"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
@ -75,12 +77,19 @@ func Listen(ctx context.Context, address net.Address, port net.Port, settings *i
|
|||||||
|
|
||||||
config := tls.ConfigFromStreamSettings(settings)
|
config := tls.ConfigFromStreamSettings(settings)
|
||||||
|
|
||||||
|
var options []grpc.ServerOption
|
||||||
var s *grpc.Server
|
var s *grpc.Server
|
||||||
if config == nil {
|
if config != nil {
|
||||||
s = grpc.NewServer()
|
options = append(options, grpc.Creds(credentials.NewTLS(config.GetTLSConfig(tls.WithNextProto("h2")))))
|
||||||
} else {
|
|
||||||
s = grpc.NewServer(grpc.Creds(credentials.NewTLS(config.GetTLSConfig(tls.WithNextProto("h2")))))
|
|
||||||
}
|
}
|
||||||
|
if grpcSettings.IdleTimeout > 0 || grpcSettings.HealthCheckTimeout > 0 {
|
||||||
|
options = append(options, grpc.KeepaliveParams(keepalive.ServerParameters{
|
||||||
|
Time: time.Second * time.Duration(grpcSettings.IdleTimeout),
|
||||||
|
Timeout: time.Second * time.Duration(grpcSettings.HealthCheckTimeout),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
s = grpc.NewServer(options...)
|
||||||
listener.s = s
|
listener.s = s
|
||||||
|
|
||||||
if settings.SocketSettings != nil && settings.SocketSettings.AcceptProxyProtocol {
|
if settings.SocketSettings != nil && settings.SocketSettings.AcceptProxyProtocol {
|
||||||
|
Loading…
Reference in New Issue
Block a user