cluster

package
v1.4.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRPCTimeout is the default RPC timeout
	// that RPCs use
	DefaultRPCTimeout = time.Second * 5
)
View Source
const (
	// RetryTimeout is the time the block puller retries
	RetryTimeout = time.Second * 10
)

Variables

View Source
var ErrNotInChannel = errors.New("not in the channel")

ErrNotInChannel denotes that an ordering node is not in the channel

Functions

func ConfigFromBlock added in v1.4.0

func ConfigFromBlock(block *common.Block) (*common.ConfigEnvelope, error)

ConfigFromBlock returns a ConfigEnvelope if exists, or a *NotAConfigBlock error. It may also return some other error in case parsing failed.

func DERtoPEM

func DERtoPEM(der []byte) string

DERtoPEM returns a PEM representation of the DER encoded certificate

func IsNewChannelBlock added in v1.4.0

func IsNewChannelBlock(block *common.Block) (string, error)

IsNewChannelBlock returns a name of the channel in case it holds a channel create transaction, or empty string otherwise.

func Participant added in v1.4.0

func Participant(puller ChainPuller, analyzeLastConfBlock selfMembershipPredicate) error

Participant returns whether the caller participates in the chain. It receives a ChainPuller that should already be calibrated for the chain, and a selfMembershipPredicate that is used to detect whether the caller should service the chain. It returns nil if the caller participates in the chain. It may return notInChannelError error in case the caller doesn't participate in the chain.

func SignatureSetFromBlock added in v1.4.0

func SignatureSetFromBlock(block *common.Block) ([]*common.SignedData, error)

SignatureSetFromBlock creates a signature set out of a block.

func VerifyBlockHash added in v1.4.0

func VerifyBlockHash(indexInBuffer int, blockBuff []*common.Block) error

VerifyBlockHash verifies the hash chain of the block with the given index among the blocks of the given block buffer.

func VerifyBlockSignature added in v1.4.0

func VerifyBlockSignature(block *common.Block, verifier BlockVerifier, config *common.ConfigEnvelope) error

VerifyBlockSignature verifies the signature on the block with the given BlockVerifier and the given config.

func VerifyBlocks added in v1.4.0

func VerifyBlocks(blockBuff []*common.Block, signatureVerifier BlockVerifier) error

VerifyBlocks verifies the given consecutive sequence of blocks is valid, and returns nil if it's valid, else an error.

Types

type BlockPuller added in v1.4.0

type BlockPuller struct {
	// Configuration
	MaxTotalBufferBytes int
	Signer              crypto.LocalSigner
	TLSCert             []byte
	Channel             string
	FetchTimeout        time.Duration
	RetryTimeout        time.Duration
	Logger              *flogging.FabricLogger
	Dialer              Dialer
	VerifyBlockSequence BlockSequenceVerifier
	Endpoints           []string
	// contains filtered or unexported fields
}

BlockPuller pulls blocks from remote ordering nodes. Its operations are not thread safe.

func BlockPullerFromConfigBlock added in v1.4.0

func BlockPullerFromConfigBlock(conf PullerConfig, block *common.Block) (*BlockPuller, error)

BlockPullerFromConfigBlock returns a BlockPuller that doesn't verify signatures on blocks.

func (*BlockPuller) Clone added in v1.4.0

func (p *BlockPuller) Clone() *BlockPuller

Clone returns a copy of this BlockPuller initialized for the given channel

func (*BlockPuller) Close added in v1.4.0

func (p *BlockPuller) Close()

Close makes the BlockPuller close the connection and stream with the remote endpoint.

func (*BlockPuller) HeightsByEndpoints added in v1.4.0

func (p *BlockPuller) HeightsByEndpoints() map[string]uint64

HeightsByEndpoints returns the block heights by endpoints of orderers

func (*BlockPuller) PullBlock added in v1.4.0

func (p *BlockPuller) PullBlock(seq uint64) *common.Block

PullBlock blocks until a block with the given sequence is fetched from some remote ordering node.

type BlockSequenceVerifier added in v1.4.0

type BlockSequenceVerifier func([]*common.Block) error

BlockSequenceVerifier verifies that the given consecutive sequence of blocks is valid.

type BlockVerifier added in v1.4.0

type BlockVerifier interface {
	// VerifyBlockSignature verifies a signature of a block.
	// It has an optional argument of a configuration envelope
	// which would make the block verification to use validation rules
	// based on the given configuration in the ConfigEnvelope.
	// If the config envelope passed is nil, then the validation rules used
	// are the ones that were applied at commit of previous blocks.
	VerifyBlockSignature(sd []*common.SignedData, config *common.ConfigEnvelope) error
}

BlockVerifier verifies block signatures.

type ChainInspector added in v1.4.0

type ChainInspector struct {
	Logger          *flogging.FabricLogger
	Puller          ChainPuller
	LastConfigBlock *common.Block
}

ChainInspector walks over a chain

func (*ChainInspector) Channels added in v1.4.0

func (ci *ChainInspector) Channels() []string

Channels returns the list of channels that exist in the chain

func (*ChainInspector) Close added in v1.4.0

func (ci *ChainInspector) Close()

Close closes the ChainInspector

type ChainPuller added in v1.4.0

type ChainPuller interface {
	// PullBlock pulls the given block from some orderer node
	PullBlock(seq uint64) *common.Block

	// HeightsByEndpoints returns the block heights by endpoints of orderers
	HeightsByEndpoints() map[string]uint64

	// Close closes the ChainPuller
	Close()
}

ChainPuller pulls blocks from a chain

type ChannelExtractor

type ChannelExtractor interface {
	TargetChannel(message proto.Message) string
}

ChannelExtractor extracts the channel of a given message, or returns an empty string if that's not possible

type ChannelLister added in v1.4.0

type ChannelLister interface {
	// Channels returns a list of channels
	Channels() []string
	// Close closes the ChannelLister
	Close()
}

ChannelLister returns a list of channels

type Client

type Client interface {
	// Submit submits transactions to a cluster member
	Submit(ctx context.Context, opts ...grpc.CallOption) (orderer.Cluster_SubmitClient, error)
	// Step passes an implementation-specific message to another cluster member.
	Step(ctx context.Context, in *orderer.StepRequest, opts ...grpc.CallOption) (*orderer.StepResponse, error)
}

Client is the definition of operations that the Cluster gRPC service exposes to cluster nodes.

type Comm

type Comm struct {
	Lock         sync.RWMutex
	Logger       *flogging.FabricLogger
	ChanExt      ChannelExtractor
	H            Handler
	Connections  *ConnectionStore
	Chan2Members MembersByChannel
	RPCTimeout   time.Duration
	// contains filtered or unexported fields
}

Comm implements Communicator

func (*Comm) Configure

func (c *Comm) Configure(channel string, newNodes []RemoteNode)

Configure configures the channel with the given RemoteNodes

func (*Comm) DispatchStep

func (c *Comm) DispatchStep(ctx context.Context, request *orderer.StepRequest) (*orderer.StepResponse, error)

DispatchStep identifies the channel and sender of the step request and passes it to the underlying Handler

func (*Comm) DispatchSubmit

func (c *Comm) DispatchSubmit(ctx context.Context, request *orderer.SubmitRequest) (*orderer.SubmitResponse, error)

DispatchSubmit identifies the channel and sender of the submit request and passes it to the underlying Handler

func (*Comm) Remote

func (c *Comm) Remote(channel string, id uint64) (*RemoteContext, error)

Remote obtains a RemoteContext linked to the destination node on the context of a given channel

func (*Comm) Shutdown

func (c *Comm) Shutdown()

Shutdown shuts down the instance

type Communicator

type Communicator interface {
	// Remote returns a RemoteContext for the given RemoteNode ID in the context
	// of the given channel, or error if connection cannot be established, or
	// the channel wasn't configured
	Remote(channel string, id uint64) (*RemoteContext, error)
	// Configure configures the communication to connect to all
	// given members, and disconnect from any members not among the given
	// members.
	Configure(channel string, members []RemoteNode)
	// Shutdown shuts down the communicator
	Shutdown()
}

Communicator defines communication for a consenter

type ConnByCertMap

type ConnByCertMap map[string]*grpc.ClientConn

ConnByCertMap maps certificates represented as strings to gRPC connections

func (ConnByCertMap) Lookup

func (cbc ConnByCertMap) Lookup(cert []byte) (*grpc.ClientConn, bool)

Lookup looks up a certificate and returns the connection that was mapped to the certificate, and whether it was found or not

func (ConnByCertMap) Put

func (cbc ConnByCertMap) Put(cert []byte, conn *grpc.ClientConn)

Put associates the given connection to the certificate

func (ConnByCertMap) Remove

func (cbc ConnByCertMap) Remove(cert []byte)

Remove removes the connection that is associated to the given certificate

type ConnectionMapper

type ConnectionMapper interface {
	Lookup(cert []byte) (*grpc.ClientConn, bool)
	Put(cert []byte, conn *grpc.ClientConn)
	Remove(cert []byte)
}

ConnectionMapper maps certificates to connections

type ConnectionStore

type ConnectionStore struct {
	Connections ConnectionMapper
	// contains filtered or unexported fields
}

ConnectionStore stores connections to remote nodes

func NewConnectionStore

func NewConnectionStore(dialer SecureDialer) *ConnectionStore

NewConnectionStore creates a new ConnectionStore with the given SecureDialer

func (*ConnectionStore) Connection

func (c *ConnectionStore) Connection(endpoint string, expectedServerCert []byte) (*grpc.ClientConn, error)

Connection obtains a connection to the given endpoint and expects the given server certificate to be presented by the remote node

func (*ConnectionStore) Disconnect

func (c *ConnectionStore) Disconnect(expectedServerCert []byte)

Disconnect closes the gRPC connection that is mapped to the given certificate

type Dialer added in v1.4.0

type Dialer interface {
	Dial(address string) (*grpc.ClientConn, error)
}

Dialer creates a gRPC connection to a remote address

type Dispatcher

type Dispatcher interface {
	DispatchSubmit(ctx context.Context, request *orderer.SubmitRequest) (*orderer.SubmitResponse, error)
	DispatchStep(ctx context.Context, request *orderer.StepRequest) (*orderer.StepResponse, error)
}

Dispatcher dispatches requests

type EndpointConfig added in v1.4.0

type EndpointConfig struct {
	TLSRootCAs [][]byte
	Endpoints  []string
}

EndpointConfig defines a configuration of endpoints of ordering service nodes

func EndpointconfigFromConfigBlock added in v1.4.0

func EndpointconfigFromConfigBlock(block *common.Block) (*EndpointConfig, error)

EndpointconfigFromConfigBlock retrieves TLS CA certificates and endpoints from a config block.

type Handler

type Handler interface {
	OnStep(channel string, sender uint64, req *orderer.StepRequest) (*orderer.StepResponse, error)
	OnSubmit(channel string, sender uint64, req *orderer.SubmitRequest) (*orderer.SubmitResponse, error)
}

Handler handles Step() and Submit() requests and returns a corresponding response

type ImpatientStream added in v1.4.0

type ImpatientStream struct {
	orderer.AtomicBroadcast_DeliverClient
	// contains filtered or unexported fields
}

ImpatientStream aborts the stream if it waits for too long for a message.

func (*ImpatientStream) Recv added in v1.4.0

func (stream *ImpatientStream) Recv() (*orderer.DeliverResponse, error)

Recv blocks until a response is received from the stream or the timeout expires.

type ImpatientStreamCreator added in v1.4.0

type ImpatientStreamCreator func() (*ImpatientStream, error)

ImpatientStreamCreator creates an ImpatientStream

func NewImpatientStream added in v1.4.0

func NewImpatientStream(conn *grpc.ClientConn, waitTimeout time.Duration) ImpatientStreamCreator

NewImpatientStream returns a ImpatientStreamCreator that creates impatientStreams.

type LedgerFactory added in v1.4.0

type LedgerFactory interface {
	// GetOrCreate gets an existing ledger (if it exists)
	// or creates it if it does not
	GetOrCreate(chainID string) (LedgerWriter, error)
}

LedgerFactory retrieves or creates new ledgers by chainID

type LedgerWriter added in v1.4.0

type LedgerWriter interface {
	// Append a new block to the ledger
	Append(block *common.Block) error

	// Height returns the number of blocks on the ledger
	Height() uint64
}

LedgerWriter allows the caller to write blocks and inspect the height

type MemberMapping

type MemberMapping map[uint64]*Stub

MemberMapping defines NetworkMembers by their ID

func (MemberMapping) ByID

func (mp MemberMapping) ByID(ID uint64) *Stub

ByID retrieves the Stub with the given ID from the MemberMapping

func (MemberMapping) LookupByClientCert

func (mp MemberMapping) LookupByClientCert(cert []byte) *Stub

LookupByClientCert retrieves a Stub with the given client certificate

func (MemberMapping) Put

func (mp MemberMapping) Put(stub *Stub)

Put inserts the given stub to the MemberMapping

func (MemberMapping) ServerCertificates

func (mp MemberMapping) ServerCertificates() StringSet

ServerCertificates returns a set of the server certificates represented as strings

type MembersByChannel

type MembersByChannel map[string]MemberMapping

MembersByChannel is a mapping from channel name to MemberMapping

type NoopBlockVerifier added in v1.4.0

type NoopBlockVerifier struct{}

NoopBlockVerifier doesn't verify block signatures

func (*NoopBlockVerifier) VerifyBlockSignature added in v1.4.0

func (*NoopBlockVerifier) VerifyBlockSignature(sd []*common.SignedData, config *common.ConfigEnvelope) error

VerifyBlockSignature accepts all signatures over blocks.

type PredicateDialer

type PredicateDialer struct {
	Config atomic.Value
}

PredicateDialer creates gRPC connections that are only established if the given predicate is fulfilled

func NewTLSPinningDialer

func NewTLSPinningDialer(config comm.ClientConfig) *PredicateDialer

NewTLSPinningDialer creates a new PredicateDialer

func (*PredicateDialer) ClientConfig added in v1.4.0

func (dialer *PredicateDialer) ClientConfig() (comm.ClientConfig, error)

ClientConfig returns the comm.ClientConfig, or an error if they cannot be extracted.

func (*PredicateDialer) Dial

func (dialer *PredicateDialer) Dial(address string, verifyFunc RemoteVerifier) (*grpc.ClientConn, error)

Dial creates a new gRPC connection that can only be established, if the remote node's certificate chain satisfy verifyFunc

func (*PredicateDialer) SetConfig

func (dialer *PredicateDialer) SetConfig(config comm.ClientConfig)

SetConfig sets the configuration of the PredicateDialer

type PullerConfig added in v1.4.0

type PullerConfig struct {
	TLSKey              []byte
	TLSCert             []byte
	Timeout             time.Duration
	Signer              crypto.LocalSigner
	Channel             string
	MaxTotalBufferBytes int
}

PullerConfig configures a BlockPuller.

func PullerConfigFromTopLevelConfig added in v1.4.0

func PullerConfigFromTopLevelConfig(systemChannel string, conf *localconfig.TopLevel, tlsKey, tlsCert []byte, signer crypto.LocalSigner) PullerConfig

PullerConfigFromTopLevelConfig creates a PullerConfig from a TopLevel config, and from a signer and TLS key cert pair. The PullerConfig's channel is initialized to be the system channel.

type RPC

type RPC struct {
	Channel string
	Comm    Communicator

	DestinationToStream map[uint64]orderer.Cluster_SubmitClient
	// contains filtered or unexported fields
}

RPC performs remote procedure calls to remote cluster nodes.

func (*RPC) ReceiveSubmitResponse

func (s *RPC) ReceiveSubmitResponse(destination uint64) (*orderer.SubmitResponse, error)

ReceiveSubmitResponse receives a SubmitResponse from the given destination node

func (*RPC) SendSubmit

func (s *RPC) SendSubmit(destination uint64, request *orderer.SubmitRequest) error

SendSubmit sends a SubmitRequest to the given destination node

func (*RPC) Step

func (s *RPC) Step(destination uint64, msg *orderer.StepRequest) (*orderer.StepResponse, error)

Step sends a StepRequest to the given destination node and returns the response

type RemoteContext

type RemoteContext struct {
	RPCTimeout time.Duration

	Client orderer.ClusterClient
	// contains filtered or unexported fields
}

RemoteContext interacts with remote cluster nodes. Every call can be aborted via call to Abort()

func (*RemoteContext) Abort

func (rc *RemoteContext) Abort()

Abort aborts the contexts the RemoteContext uses, thus effectively causes all operations on the embedded ClusterClient to end.

func (*RemoteContext) Step

Step passes an implementation-specific message to another cluster member.

func (*RemoteContext) SubmitStream

func (rc *RemoteContext) SubmitStream() (orderer.Cluster_SubmitClient, error)

SubmitStream creates a new Submit stream

type RemoteNode

type RemoteNode struct {
	// ID is unique among all members, and cannot be 0.
	ID uint64
	// Endpoint is the endpoint of the node, denoted in %s:%d format
	Endpoint string
	// ServerTLSCert is the DER encoded TLS server certificate of the node
	ServerTLSCert []byte
	// ClientTLSCert is the DER encoded TLS client certificate of the node
	ClientTLSCert []byte
}

RemoteNode represents a cluster member

func (RemoteNode) String

func (rm RemoteNode) String() string

String returns a string representation of this RemoteNode

type RemoteVerifier

type RemoteVerifier func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error

RemoteVerifier verifies the connection to the remote host

type Replicator added in v1.4.0

type Replicator struct {
	SystemChannel    string
	ChannelLister    ChannelLister
	Logger           *flogging.FabricLogger
	Puller           *BlockPuller
	BootBlock        *common.Block
	AmIPartOfChannel selfMembershipPredicate
	LedgerFactory    LedgerFactory
}

Replicator replicates chains

func (*Replicator) IsReplicationNeeded added in v1.4.0

func (r *Replicator) IsReplicationNeeded() (bool, error)

IsReplicationNeeded returns whether replication is needed, or the cluster node can resume standard boot flow.

func (*Replicator) PullChannel added in v1.4.0

func (r *Replicator) PullChannel(channel string) error

PullChannel pulls the given channel from some orderer, and commits it to the ledger.

func (*Replicator) ReplicateChains added in v1.4.0

func (r *Replicator) ReplicateChains()

ReplicateChains pulls chains and commits them.

type SecureDialer

type SecureDialer interface {
	Dial(address string, verifyFunc RemoteVerifier) (*grpc.ClientConn, error)
}

SecureDialer connects to a remote address

type Service

type Service struct {
	Dispatcher Dispatcher
	Logger     *flogging.FabricLogger
	StepLogger *flogging.FabricLogger
}

Service defines the raft Service

func (*Service) Step

func (s *Service) Step(ctx context.Context, request *orderer.StepRequest) (*orderer.StepResponse, error)

Step forwards a message to a raft FSM located in this server

func (*Service) Submit

func (s *Service) Submit(stream orderer.Cluster_SubmitServer) error

Submit accepts transactions

type StandardDialer added in v1.4.0

type StandardDialer struct {
	Dialer *PredicateDialer
}

StandardDialer wraps a PredicateDialer to a standard cluster.Dialer that passes in a nil verify function

func (*StandardDialer) Dial added in v1.4.0

func (bdp *StandardDialer) Dial(address string) (*grpc.ClientConn, error)

Dial dials to the given address

type StringSet

type StringSet map[string]struct{}

StringSet is a set of strings

type Stub

type Stub struct {
	RemoteNode
	*RemoteContext
	// contains filtered or unexported fields
}

Stub holds all information about the remote node, including the RemoteContext for it, and serializes some operations on it.

func (*Stub) Activate

func (stub *Stub) Activate(createRemoteContext func() (*RemoteContext, error)) error

Activate creates a remote context with the given function callback in an atomic manner - if two parallel invocations are invoked on this Stub, only a single invocation of createRemoteStub takes place.

func (*Stub) Active

func (stub *Stub) Active() bool

Active returns whether the Stub is active or not

func (*Stub) Deactivate

func (stub *Stub) Deactivate()

Deactivate deactivates the Stub and ceases all communication operations invoked on it.

type SubmitClient

type SubmitClient interface {
	Send(request *orderer.SubmitRequest) error
	Recv() (*orderer.SubmitResponse, error)
	grpc.ClientStream
}

SubmitClient is the Submit gRPC stream

type SubmitStream

type SubmitStream interface {
	Send(response *orderer.SubmitResponse) error
	Recv() (*orderer.SubmitRequest, error)
	grpc.ServerStream
}

SubmitStream defines the gRPC stream for sending transactions, and receiving corresponding responses

Directories

Path Synopsis
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.

Jump to

Keyboard shortcuts

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