Add health check support for http-based v2ray transport
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
)
|
||||
|
||||
var _ adapter.V2RayClientTransport = (*Client)(nil)
|
||||
@@ -40,6 +41,13 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
|
||||
} else {
|
||||
dialOptions = append(dialOptions, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
}
|
||||
if options.IdleTimeout > 0 {
|
||||
dialOptions = append(dialOptions, grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
||||
Time: time.Duration(options.IdleTimeout),
|
||||
Timeout: time.Duration(options.PingTimeout),
|
||||
PermitWithoutStream: options.PermitWithoutStream,
|
||||
}))
|
||||
}
|
||||
dialOptions = append(dialOptions, grpc.WithConnectParams(grpc.ConnectParams{
|
||||
Backoff: backoff.Config{
|
||||
BaseDelay: 500 * time.Millisecond,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/tls"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
gM "google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/peer"
|
||||
)
|
||||
@@ -31,6 +33,12 @@ func NewServer(ctx context.Context, options option.V2RayGRPCOptions, tlsConfig t
|
||||
tlsConfig.SetNextProtos([]string{"h2"})
|
||||
serverOptions = append(serverOptions, grpc.Creds(NewTLSTransportCredentials(tlsConfig)))
|
||||
}
|
||||
if options.IdleTimeout > 0 {
|
||||
serverOptions = append(serverOptions, grpc.KeepaliveParams(keepalive.ServerParameters{
|
||||
Time: time.Duration(options.IdleTimeout),
|
||||
Timeout: time.Duration(options.PingTimeout),
|
||||
}))
|
||||
}
|
||||
server := &Server{ctx, handler, grpc.NewServer(serverOptions...)}
|
||||
RegisterGunServiceCustomNameServer(server.server, server, options.ServiceName)
|
||||
return server, nil
|
||||
|
||||
Reference in New Issue
Block a user