comm

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MSPID

func MSPID(cfg fab.EndpointConfig, org string) (string, bool)

MSPID returns the MSP ID for the requested organization

func NetworkPeerConfig

func NetworkPeerConfig(cfg fab.EndpointConfig, key string) (*fab.NetworkPeer, error)

NetworkPeerConfig fetches the peer configuration based on a key (name or URL).

func OptsFromPeerConfig

func OptsFromPeerConfig(peerCfg *fab.PeerConfig) []options.Opt

OptsFromPeerConfig returns a set of connection options from the given peer config

func SearchPeerConfigFromURL

func SearchPeerConfigFromURL(cfg fab.EndpointConfig, url string) (*fab.PeerConfig, error)

SearchPeerConfigFromURL searches for the peer configuration based on a URL.

func WithCertificate

func WithCertificate(value *sm2.Certificate) options.Opt

WithCertificate sets the sm2 certificate used for the TLS connection

func WithConnectTimeout

func WithConnectTimeout(value time.Duration) options.Opt

WithConnectTimeout sets the GRPC connection timeout

func WithFailFast

func WithFailFast(value bool) options.Opt

WithFailFast sets the GRPC fail-fast parameter

func WithHostOverride

func WithHostOverride(value string) options.Opt

WithHostOverride sets the host name that will be used to resolve the TLS certificate

func WithInsecure

func WithInsecure() options.Opt

WithInsecure indicates to fall back to an insecure connection if the connection URL does not specify a protocol

func WithKeepAliveParams

func WithKeepAliveParams(value keepalive.ClientParameters) options.Opt

WithKeepAliveParams sets the GRPC keep-alive parameters

func WithParentContext

func WithParentContext(value context.Context) options.Opt

WithParentContext sets the parent context

Types

type CachingConnector

type CachingConnector struct {
	// contains filtered or unexported fields
}

CachingConnector provides the ability to cache GRPC connections. It provides a GRPC compatible Context Dialer interface via the "DialContext" method. Connections provided by this component are monitored for becoming idle or entering shutdown state. When connections has its usages closed for longer than "idleTime", the connection is closed and removed from the connection cache. Callers must release connections by calling the "ReleaseConn" method. The Close method will flush all remaining open connections. This component should be considered unusable after calling Close.

This component has been designed to be safe for concurrency.

func NewCachingConnector

func NewCachingConnector(sweepTime time.Duration, idleTime time.Duration) *CachingConnector

NewCachingConnector creates a GRPC connection cache. The cache is governed by sweepTime and idleTime.

func (*CachingConnector) Close

func (cc *CachingConnector) Close()

Close cleans up cached connections.

func (*CachingConnector) DialContext

func (cc *CachingConnector) DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialContext is a wrapper for grpc.DialContext where connections are cached.

func (*CachingConnector) ReleaseConn

func (cc *CachingConnector) ReleaseConn(conn *grpc.ClientConn)

ReleaseConn notifies the cache that the connection is no longer in use.

type GRPCConnection

type GRPCConnection struct {
	// contains filtered or unexported fields
}

GRPCConnection manages the GRPC connection and client stream

func NewConnection

func NewConnection(ctx fabcontext.Client, url string, opts ...options.Opt) (*GRPCConnection, error)

NewConnection creates a new connection

func (*GRPCConnection) ClientConn

func (c *GRPCConnection) ClientConn() *grpc.ClientConn

ClientConn returns the underlying GRPC connection

func (*GRPCConnection) Close

func (c *GRPCConnection) Close()

Close closes the connection

func (*GRPCConnection) Closed

func (c *GRPCConnection) Closed() bool

Closed returns true if the connection has been closed

func (*GRPCConnection) Context

func (c *GRPCConnection) Context() fabcontext.Client

Context returns the context of the client establishing the connection

func (*GRPCConnection) TLSCertHash

func (c *GRPCConnection) TLSCertHash() []byte

TLSCertHash returns the hash of the TLS cert

type MockCommManager

type MockCommManager struct {
}

MockCommManager is a non-caching comm manager used for unit testing

func (*MockCommManager) DialContext

func (m *MockCommManager) DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialContext creates a connection

func (*MockCommManager) ReleaseConn

func (m *MockCommManager) ReleaseConn(conn *grpc.ClientConn)

ReleaseConn closes the connection

type MockInfraProvider

type MockInfraProvider struct {
	fabmocks.MockInfraProvider
}

MockInfraProvider overrides the comm manager to return the MockCommManager

func NewMockInfraProvider

func NewMockInfraProvider() *MockInfraProvider

NewMockInfraProvider return a new MockInfraProvider

func (*MockInfraProvider) CommManager

func (f *MockInfraProvider) CommManager() fab.CommManager

CommManager returns the MockCommManager

type StreamConnection

type StreamConnection struct {
	*GRPCConnection
	// contains filtered or unexported fields
}

StreamConnection manages the GRPC connection and client stream

func NewStreamConnection

func NewStreamConnection(ctx fabcontext.Client, chConfig fab.ChannelCfg, streamProvider StreamProvider, url string, opts ...options.Opt) (*StreamConnection, error)

NewStreamConnection creates a new connection with stream

func (*StreamConnection) ChannelConfig

func (c *StreamConnection) ChannelConfig() fab.ChannelCfg

ChannelConfig returns the channel configuration

func (*StreamConnection) Close

func (c *StreamConnection) Close()

Close closes the connection

func (*StreamConnection) Stream

func (c *StreamConnection) Stream() grpc.ClientStream

Stream returns the GRPC stream

type StreamProvider

type StreamProvider func(conn *grpc.ClientConn) (grpc.ClientStream, func(), error)

StreamProvider creates a GRPC stream

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL