Documentation ¶
Index ¶
- Constants
- Variables
- func ClientKeepaliveOptions(ka KeepaliveOptions) []grpc.DialOption
- func ServerKeepaliveOptions(ka KeepaliveOptions) []grpc.ServerOption
- type ClientConfig
- type ContractArgs
- type ContractStream
- type ContractSupport
- type GRPCServer
- type Handler
- func (h *Handler) Execute(msg *pb.ContractMessage, timeout time.Duration) (*pb.ContractMessage, error)
- func (h *Handler) HandleRegister(msg *pb.ContractMessage)
- func (h *Handler) Notify(msg *pb.ContractMessage)
- func (h *Handler) ProcessStream(stream ContractStream) error
- func (h *Handler) State() State
- type HandlerRegistry
- type KeepaliveOptions
- type Metrics
- type Registry
- type SecureOptions
- type ServerConfig
- type ServerStatsHandler
- func (h *ServerStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)
- func (h *ServerStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)
- func (h *ServerStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context
- func (h *ServerStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
- type State
Constants ¶
View Source
const ( CodeTypeOK uint32 = 0 CodeTypeEncodingError uint32 = 1 CodeTypeBadFunction uint32 = 2 CodeTypeUnknownError uint32 = 4 )
Variables ¶
View Source
var ( // Max send and receive bytes for contractserver clients and servers MaxRecvMsgSize = 100 * 1024 * 1024 MaxSendMsgSize = 100 * 1024 * 1024 // Default peer keepalive options DefaultKeepaliveOptions = KeepaliveOptions{ ClientInterval: time.Duration(1) * time.Minute, ClientTimeout: time.Duration(20) * time.Second, ServerInterval: time.Duration(2) * time.Hour, ServerTimeout: time.Duration(20) * time.Second, ServerMinInterval: time.Duration(1) * time.Minute, } // strong TLS cipher suites DefaultTLSCipherSuites = []uint16{ tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_RSA_WITH_AES_256_GCM_SHA384, } // default connection timeout DefaultConnectionTimeout = 5 * time.Second )
Configuration defaults
Functions ¶
func ClientKeepaliveOptions ¶
func ClientKeepaliveOptions(ka KeepaliveOptions) []grpc.DialOption
ClientKeepaliveOptions returns gRPC keepalive options for clients.
func ServerKeepaliveOptions ¶
func ServerKeepaliveOptions(ka KeepaliveOptions) []grpc.ServerOption
ServerKeepaliveOptions returns gRPC keepalive options for server.
Types ¶
type ClientConfig ¶
type ClientConfig struct { // SecOpts defines the security parameters SecOpts SecureOptions // KaOpts defines the keepalive parameters KaOpts KeepaliveOptions // Timeout specifies how long the client will block when attempting to // establish a connection Timeout time.Duration // AsyncConnect makes connection creation non blocking AsyncConnect bool }
ClientConfig defines the parameters for configuring a GRPCClient instance
func (ClientConfig) Clone ¶
func (cc ClientConfig) Clone() ClientConfig
Clone clones this ClientConfig
type ContractArgs ¶
type ContractArgs [][]byte
type ContractStream ¶
type ContractStream interface { Send(*pb.ContractMessage) error Recv() (*pb.ContractMessage, error) }
type ContractSupport ¶
type ContractSupport struct { ExecuteTimeout time.Duration KeepAlive time.Duration Log log.Logger HandlerRegistry *HandlerRegistry }
func (*ContractSupport) Execute ¶
func (cs *ContractSupport) Execute(contractId string, args ContractArgs) (*pb.ContractMessage, error)
func (*ContractSupport) HandleContractStream ¶
func (cs *ContractSupport) HandleContractStream(stream ContractStream) error
func (*ContractSupport) Register ¶
func (cs *ContractSupport) Register(stream pb.ContractSupport_RegisterServer) error
type GRPCServer ¶
type GRPCServer struct {
// contains filtered or unexported fields
}
func NewGRPCServer ¶
func NewGRPCServer(address string, serverConfig ServerConfig) (*GRPCServer, error)
func NewGRPCServerFromListener ¶
func NewGRPCServerFromListener(listener net.Listener, serverConfig ServerConfig) (*GRPCServer, error)
func (*GRPCServer) Address ¶
func (gs *GRPCServer) Address() string
func (*GRPCServer) Listener ¶
func (gs *GRPCServer) Listener() net.Listener
func (*GRPCServer) Server ¶
func (gs *GRPCServer) Server() *grpc.Server
func (*GRPCServer) Start ¶
func (gs *GRPCServer) Start() error
func (*GRPCServer) Stop ¶
func (gs *GRPCServer) Stop()
type Handler ¶
type Handler struct { KeepAlive time.Duration Registry Registry ResponseNotifier chan *pb.ContractMessage // contains filtered or unexported fields }
func (*Handler) Execute ¶
func (h *Handler) Execute(msg *pb.ContractMessage, timeout time.Duration) (*pb.ContractMessage, error)
func (*Handler) HandleRegister ¶
func (h *Handler) HandleRegister(msg *pb.ContractMessage)
func (*Handler) Notify ¶
func (h *Handler) Notify(msg *pb.ContractMessage)
func (*Handler) ProcessStream ¶
func (h *Handler) ProcessStream(stream ContractStream) error
type HandlerRegistry ¶
type HandlerRegistry struct {
// contains filtered or unexported fields
}
HandlerRegistry maintains contract handler instance
func NewHandlerRegistry ¶
func NewHandlerRegistry(log log.Logger) *HandlerRegistry
func (*HandlerRegistry) Deregister ¶
func (r *HandlerRegistry) Deregister(cID string) error
func (*HandlerRegistry) Handler ¶
func (r *HandlerRegistry) Handler(cID string) *Handler
func (*HandlerRegistry) Register ¶
func (r *HandlerRegistry) Register(handler *Handler) error
type KeepaliveOptions ¶
type KeepaliveOptions struct { // ClientInterval is the duration after which if the client does not see // any activity from the server it pings the server to see if it is alive ClientInterval time.Duration // ClientTimeout is the duration the client waits for a response // from the server after sending a ping before closing the connection ClientTimeout time.Duration // ServerInterval is the duration after which if the server does not see // any activity from the client it pings the client to see if it is alive ServerInterval time.Duration // ServerTimeout is the duration the server waits for a response // from the client after sending a ping before closing the connection ServerTimeout time.Duration // ServerMinInterval is the minimum permitted time between client pings. // If clients send pings more frequently, the server will disconnect them ServerMinInterval time.Duration }
KeepaliveOptions is used to set the gRPC keepalive settings for both clients and servers
type SecureOptions ¶
type SecureOptions struct { // VerifyCertificate, if not nil, is called after normal // certificate verification by either a TLS client or server. // If it returns a non-nil error, the handshake is aborted and that error results. VerifyCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error // PEM-encoded X509 public key to be used for TLS communication Certificate []byte // PEM-encoded private key to be used for TLS communication Key []byte // Set of PEM-encoded X509 certificate authorities used by clients to // verify server certificates ServerRootCAs [][]byte // Set of PEM-encoded X509 certificate authorities used by servers to // verify client certificates ClientRootCAs [][]byte // Whether or not to use TLS for communication UseTLS bool // Whether or not TLS client must present certificates for authentication RequireClientCert bool // CipherSuites is a list of supported cipher suites for TLS CipherSuites []uint16 // TimeShift makes TLS handshakes time sampling shift to the past by a given duration TimeShift time.Duration }
SecureOptions defines the security parameters (e.g. TLS) for a GRPCServer or GRPCClient instance
type ServerConfig ¶
type ServerConfig struct { // ConnectionTimeout specifies the timeout for connection establishment // for all new connections ConnectionTimeout time.Duration // SecOpts defines the security parameters SecOpts SecureOptions // KaOpts defines the keepalive parameters KaOpts KeepaliveOptions // StreamInterceptors specifies a list of interceptors to apply to // streaming RPCs. They are executed in order. StreamInterceptors []grpc.StreamServerInterceptor // UnaryInterceptors specifies a list of interceptors to apply to unary // RPCs. They are executed in order. UnaryInterceptors []grpc.UnaryServerInterceptor // Logger specifies the logger the server will use Logger *log.Logger // HealthCheckEnabled enables the gRPC Health Checking Protocol for the server HealthCheckEnabled bool // ServerStatsHandler should be set if metrics on connections are to be reported. ServerStatsHandler *ServerStatsHandler }
ServerConfig defines the parameters for configuring a GRPCServer instance
type ServerStatsHandler ¶
type ServerStatsHandler struct { OpenConnCounter metrics.Counter ClosedConnCounter metrics.Counter }
func (*ServerStatsHandler) HandleConn ¶
func (h *ServerStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)
func (*ServerStatsHandler) HandleRPC ¶
func (h *ServerStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)
func (*ServerStatsHandler) TagConn ¶
func (h *ServerStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context
func (*ServerStatsHandler) TagRPC ¶
func (h *ServerStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
Click to show internal directories.
Click to hide internal directories.