github.com/xmplusdev/xray-core@v1.8.10/infra/conf/grpc.go (about)

     1  package conf
     2  
     3  import (
     4  	"github.com/xmplusdev/xray-core/transport/internet/grpc"
     5  	"google.golang.org/protobuf/proto"
     6  )
     7  
     8  type GRPCConfig struct {
     9  	Authority           string `json:"authority"`
    10  	ServiceName         string `json:"serviceName"`
    11  	MultiMode           bool   `json:"multiMode"`
    12  	IdleTimeout         int32  `json:"idle_timeout"`
    13  	HealthCheckTimeout  int32  `json:"health_check_timeout"`
    14  	PermitWithoutStream bool   `json:"permit_without_stream"`
    15  	InitialWindowsSize  int32  `json:"initial_windows_size"`
    16  	UserAgent           string `json:"user_agent"`
    17  }
    18  
    19  func (g *GRPCConfig) Build() (proto.Message, error) {
    20  	if g.IdleTimeout <= 0 {
    21  		g.IdleTimeout = 0
    22  	}
    23  	if g.HealthCheckTimeout <= 0 {
    24  		g.HealthCheckTimeout = 0
    25  	}
    26  	if g.InitialWindowsSize < 0 {
    27  		// default window size of gRPC-go
    28  		g.InitialWindowsSize = 0
    29  	}
    30  
    31  	return &grpc.Config{
    32  		Authority:           g.Authority,
    33  		ServiceName:         g.ServiceName,
    34  		MultiMode:           g.MultiMode,
    35  		IdleTimeout:         g.IdleTimeout,
    36  		HealthCheckTimeout:  g.HealthCheckTimeout,
    37  		PermitWithoutStream: g.PermitWithoutStream,
    38  		InitialWindowsSize:  g.InitialWindowsSize,
    39  		UserAgent:           g.UserAgent,
    40  	}, nil
    41  }