peer

package
v0.0.0-...-58d1483 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2017 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSyncSnapshotTimeout time.Duration = 60 * time.Second

Variables

This section is empty.

Functions

func CacheConfiguration

func CacheConfiguration() (err error)

CacheConfiguration computes and caches commonly-used constants and computed constants as package variables. Routines which were previously global have been embedded here to preserve the original abstraction.

func GetLocalAddress

func GetLocalAddress() (string, error)

GetLocalAddress returns the peer.address property

func GetLocalIP

func GetLocalIP() string

GetLocalIP returns the non loopback local IP of the host

func GetPeerEndpoint

func GetPeerEndpoint() (*pb.PeerEndpoint, error)

GetPeerEndpoint returns peerEndpoint from cached configuration

func NewPeerClientConnection

func NewPeerClientConnection() (*grpc.ClientConn, error)

NewPeerClientConnection Returns a new grpc.ClientConn to the configured local PEER.

func NewPeerClientConnectionWithAddress

func NewPeerClientConnectionWithAddress(peerAddress string) (*grpc.ClientConn, error)

NewPeerClientConnectionWithAddress Returns a new grpc.ClientConn to the configured local PEER.

func SecurityEnabled

func SecurityEnabled() bool

SecurityEnabled returns the securityEnabled property from cached configuration

func SyncBlocksChannelSize

func SyncBlocksChannelSize() int

SyncBlocksChannelSize returns the peer.sync.blocks.channelSize property

func SyncStateDeltasChannelSize

func SyncStateDeltasChannelSize() int

SyncStateDeltasChannelSize returns the peer.sync.state.deltas.channelSize property

func SyncStateSnapshotChannelSize

func SyncStateSnapshotChannelSize() int

SyncStateSnapshotChannelSize returns the peer.sync.state.snapshot.channelSize property

func ValidatorEnabled

func ValidatorEnabled() bool

ValidatorEnabled returns the peer.validator.enabled property

Types

type BlockChainAccessor

type BlockChainAccessor interface {
	GetBlockByNumber(blockNumber uint64) (*pb.Block, error)
	GetBlockchainSize() uint64
	GetCurrentStateHash() (stateHash []byte, err error)
}

BlockChainAccessor interface for retreiving blocks by block number

type BlockChainModifier

type BlockChainModifier interface {
	ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error
	RollbackStateDelta(id interface{}) error
	CommitStateDelta(id interface{}) error
	EmptyState() error
	PutBlock(blockNumber uint64, block *pb.Block) error
}

BlockChainModifier interface for applying changes to the block chain

type BlockChainUtil

type BlockChainUtil interface {
	HashBlock(block *pb.Block) ([]byte, error)
	VerifyBlockchain(start, finish uint64) (uint64, error)
}

BlockChainUtil interface for interrogating the block chain

type BlocksRetriever

type BlocksRetriever interface {
	RequestBlocks(*pb.SyncBlockRange) (<-chan *pb.SyncBlocks, error)
}

BlocksRetriever interface for retrieving blocks .

type ChatStream

type ChatStream interface {
	Send(*pb.Message) error
	Recv() (*pb.Message, error)
}

ChatStream interface supported by stream between Peers

type Discoverer

type Discoverer interface {
	DiscoveryAccessor
	DiscoveryPersistor
}

Discoverer enables a peer to access/persist/restore its discovery list

type DiscoveryAccessor

type DiscoveryAccessor interface {
	GetDiscHelper() discovery.Discovery
}

DiscoveryAccessor enables a peer to hand out its discovery object

type DiscoveryPersistor

type DiscoveryPersistor interface {
	LoadDiscoveryList() ([]string, error)
	StoreDiscoveryList() error
}

DiscoveryPersistor enables a peer to persist/restore its discovery list to/from the database

type DuplicateHandlerError

type DuplicateHandlerError struct {
	To pb.PeerEndpoint
}

DuplicateHandlerError returned if attempt to register same chaincodeID while a stream already exists.

func (*DuplicateHandlerError) Error

func (d *DuplicateHandlerError) Error() string

type Engine

type Engine interface {
	TransactionProccesor
	// GetHandlerFactory return a handler for an accepted Chat stream
	GetHandlerFactory() HandlerFactory
}

Engine Responsible for managing Peer network communications (Handlers) and processing of Transactions

type EngineFactory

type EngineFactory func(MessageHandlerCoordinator) (Engine, error)

EngineFactory for creating new engines

type Handler

type Handler struct {
	ToPeerEndpoint *pb.PeerEndpoint
	Coordinator    MessageHandlerCoordinator
	ChatStream     ChatStream

	FSM *fsm.FSM
	// contains filtered or unexported fields
}

Handler peer handler implementation.

func (*Handler) HandleMessage

func (d *Handler) HandleMessage(msg *pb.Message) error

HandleMessage handles the Openchain messages for the Peer.

func (*Handler) RequestBlocks

func (d *Handler) RequestBlocks(syncBlockRange *pb.SyncBlockRange) (<-chan *pb.SyncBlocks, error)

RequestBlocks get the blocks from the other PeerEndpoint based upon supplied SyncBlockRange, will provide them through the returned channel. this will also stop writing any received blocks to channels created from Prior calls to RequestBlocks(..)

func (*Handler) RequestStateDeltas

func (d *Handler) RequestStateDeltas(syncBlockRange *pb.SyncBlockRange) (<-chan *pb.SyncStateDeltas, error)

RequestStateDeltas get the state snapshot deltas from the other PeerEndpoint, will provide them through the returned channel. this will also stop writing any received syncStateSnapshot(s) to channels created from Prior calls to GetStateSnapshot()

func (*Handler) RequestStateSnapshot

func (d *Handler) RequestStateSnapshot() (<-chan *pb.SyncStateSnapshot, error)

RequestStateSnapshot request the state snapshot deltas from the other PeerEndpoint, will provide them through the returned channel. this will also stop writing any received syncStateSnapshot(s) to channels created from Prior calls to RequestStateSnapshot()

func (*Handler) SendMessage

func (d *Handler) SendMessage(msg *pb.Message) error

SendMessage sends a message to the remote PEER through the stream

func (*Handler) Stop

func (d *Handler) Stop() error

Stop stops this handler, which will trigger the Deregister from the MessageHandlerCoordinator.

func (*Handler) To

func (d *Handler) To() (pb.PeerEndpoint, error)

To return the PeerEndpoint this Handler is connected to.

type HandlerFactory

HandlerFactory for creating new MessageHandlers

type Impl

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

Impl implementation of the Peer service

func NewPeerWithEngine

func NewPeerWithEngine(secHelperFunc func() crypto.Peer, engFactory EngineFactory) (peer *Impl, err error)

NewPeerWithEngine returns a Peer which uses the supplied handler factory function for creating new handlers on new Chat service invocations.

func NewPeerWithHandler

func NewPeerWithHandler(secHelperFunc func() crypto.Peer, handlerFact HandlerFactory) (*Impl, error)

NewPeerWithHandler returns a Peer which uses the supplied handler factory function for creating new handlers on new Chat service invocations.

func (*Impl) ApplyStateDelta

func (p *Impl) ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error

ApplyStateDelta applies a state delta to the current state The result of this function can be retrieved using GetCurrentStateDelta To commit the result, call CommitStateDelta, or to roll it back call RollbackStateDelta

func (*Impl) Broadcast

func (p *Impl) Broadcast(msg *pb.Message, typ pb.PeerEndpoint_Type) []error

Broadcast broadcast a message to each of the currently registered PeerEndpoints of given type Broadcast will broadcast to all registered PeerEndpoints if the type is PeerEndpoint_UNDEFINED

func (*Impl) Chat

func (p *Impl) Chat(stream pb.Peer_ChatServer) error

Chat implementation of the the Chat bidi streaming RPC function

func (*Impl) CommitStateDelta

func (p *Impl) CommitStateDelta(id interface{}) error

CommitStateDelta makes the result of ApplyStateDelta permanent and releases the resources necessary to rollback the delta

func (*Impl) DeregisterHandler

func (p *Impl) DeregisterHandler(messageHandler MessageHandler) error

DeregisterHandler deregisters an already registered MessageHandler for this coordinator

func (*Impl) EmptyState

func (p *Impl) EmptyState() error

EmptyState completely empties the state and prepares it to restore a snapshot

func (*Impl) ExecuteTransaction

func (p *Impl) ExecuteTransaction(transaction *pb.Transaction) (response *pb.Response)

ExecuteTransaction executes transactions decides to do execute in dev or prod mode

func (*Impl) GetBlockByNumber

func (p *Impl) GetBlockByNumber(blockNumber uint64) (*pb.Block, error)

GetBlockByNumber return a block by block number

func (*Impl) GetBlockchainSize

func (p *Impl) GetBlockchainSize() uint64

GetBlockchainSize returns the height/length of the blockchain

func (*Impl) GetCurrentStateHash

func (p *Impl) GetCurrentStateHash() (stateHash []byte, err error)

GetCurrentStateHash returns the current non-committed hash of the in memory state

func (*Impl) GetDiscHelper

func (p *Impl) GetDiscHelper() discovery.Discovery

GetDiscHelper enables a peer to retrieve its discovery object

func (*Impl) GetPeerEndpoint

func (p *Impl) GetPeerEndpoint() (*pb.PeerEndpoint, error)

GetPeerEndpoint returns the endpoint for this peer

func (*Impl) GetPeers

func (p *Impl) GetPeers() (*pb.PeersMessage, error)

GetPeers returns the currently registered PeerEndpoints

func (*Impl) GetRemoteLedger

func (p *Impl) GetRemoteLedger(receiverHandle *pb.PeerID) (RemoteLedger, error)

GetRemoteLedger returns the RemoteLedger interface for the remote Peer Endpoint

func (*Impl) GetSecHelper

func (p *Impl) GetSecHelper() crypto.Peer

GetSecHelper returns the crypto.Peer

func (*Impl) GetStateDelta

func (p *Impl) GetStateDelta(blockNumber uint64) (*statemgmt.StateDelta, error)

GetStateDelta return the state delta for the requested block number

func (*Impl) GetStateSnapshot

func (p *Impl) GetStateSnapshot() (*state.StateSnapshot, error)

GetStateSnapshot return the state snapshot

func (*Impl) HashBlock

func (p *Impl) HashBlock(block *pb.Block) ([]byte, error)

HashBlock returns the hash of the included block, useful for mocking

func (*Impl) Load

func (p *Impl) Load(key string) ([]byte, error)

Load enables a peer to read the value that corresponds to the given database key

func (*Impl) LoadDiscoveryList

func (p *Impl) LoadDiscoveryList() ([]string, error)

LoadDiscoveryList enables a peer to load the discovery list from the database

func (*Impl) NewOpenchainDiscoveryHello

func (p *Impl) NewOpenchainDiscoveryHello() (*pb.Message, error)

NewOpenchainDiscoveryHello constructs a new HelloMessage for sending

func (*Impl) PeersDiscovered

func (p *Impl) PeersDiscovered(peersMessage *pb.PeersMessage) error

PeersDiscovered used by MessageHandlers for notifying this coordinator of discovered PeerEndoints. May include this Peer's PeerEndpoint.

func (*Impl) ProcessTransaction

func (p *Impl) ProcessTransaction(ctx context.Context, tx *pb.Transaction) (response *pb.Response, err error)

ProcessTransaction implementation of the ProcessTransaction RPC function

func (*Impl) PutBlock

func (p *Impl) PutBlock(blockNumber uint64, block *pb.Block) error

PutBlock inserts a raw block into the blockchain at the specified index, nearly no error checking is performed

func (*Impl) RegisterHandler

func (p *Impl) RegisterHandler(messageHandler MessageHandler) error

RegisterHandler register a MessageHandler with this coordinator

func (*Impl) RollbackStateDelta

func (p *Impl) RollbackStateDelta(id interface{}) error

RollbackStateDelta undoes the results of ApplyStateDelta to revert the current state back to the state before ApplyStateDelta was invoked

func (*Impl) SendTransactionsToPeer

func (p *Impl) SendTransactionsToPeer(peerAddress string, transaction *pb.Transaction) (response *pb.Response)

SendTransactionsToPeer forwards transactions to the specified peer address.

func (*Impl) Store

func (p *Impl) Store(key string, value []byte) error

Store enables a peer to persist the given key,value pair to the database

func (*Impl) StoreDiscoveryList

func (p *Impl) StoreDiscoveryList() error

StoreDiscoveryList enables a peer to persist the discovery list to the database

func (*Impl) Unicast

func (p *Impl) Unicast(msg *pb.Message, receiverHandle *pb.PeerID) error

Unicast sends a message to a specific peer.

func (*Impl) VerifyBlockchain

func (p *Impl) VerifyBlockchain(start, finish uint64) (uint64, error)

VerifyBlockchain checks the integrity of the blockchain between indices start and finish, returning the first block who's PreviousBlockHash field does not match the hash of the previous block

type MessageHandler

type MessageHandler interface {
	RemoteLedger
	HandleMessage(msg *pb.Message) error
	SendMessage(msg *pb.Message) error
	To() (pb.PeerEndpoint, error)
	Stop() error
}

MessageHandler standard interface for handling Openchain messages.

func NewPeerHandler

func NewPeerHandler(coord MessageHandlerCoordinator, stream ChatStream, initiatedStream bool) (MessageHandler, error)

NewPeerHandler returns a new Peer handler Is instance of HandlerFactory

type MessageHandlerCoordinator

type MessageHandlerCoordinator interface {
	Peer
	SecurityAccessor
	BlockChainAccessor
	BlockChainModifier
	BlockChainUtil
	StateAccessor
	RegisterHandler(messageHandler MessageHandler) error
	DeregisterHandler(messageHandler MessageHandler) error
	Broadcast(*pb.Message, pb.PeerEndpoint_Type) []error
	Unicast(*pb.Message, *pb.PeerID) error
	GetPeers() (*pb.PeersMessage, error)
	GetRemoteLedger(receiver *pb.PeerID) (RemoteLedger, error)
	PeersDiscovered(*pb.PeersMessage) error
	ExecuteTransaction(transaction *pb.Transaction) *pb.Response
	Discoverer
}

MessageHandlerCoordinator responsible for coordinating between the registered MessageHandler's

type Peer

type Peer interface {
	GetPeerEndpoint() (*pb.PeerEndpoint, error)
	NewOpenchainDiscoveryHello() (*pb.Message, error)
}

Peer provides interface for a peer

type Persistor

type Persistor interface {
	Store(key string, value []byte) error
	Load(key string) ([]byte, error)
}

Persistor enables a peer to persist and restore data to the database TODO Move over the persist package from consensus down to the peer level

type RemoteLedger

type RemoteLedger interface {
	BlocksRetriever
	StateRetriever
}

RemoteLedger interface for retrieving remote ledger data.

type SecurityAccessor

type SecurityAccessor interface {
	GetSecHelper() crypto.Peer
}

SecurityAccessor interface enables a Peer to hand out the crypto object for Peer

type StateAccessor

type StateAccessor interface {
	GetStateSnapshot() (*state.StateSnapshot, error)
	GetStateDelta(blockNumber uint64) (*statemgmt.StateDelta, error)
}

StateAccessor interface for retreiving blocks by block number

type StateRetriever

type StateRetriever interface {
	RequestStateSnapshot() (<-chan *pb.SyncStateSnapshot, error)
	RequestStateDeltas(syncBlockRange *pb.SyncBlockRange) (<-chan *pb.SyncStateDeltas, error)
}

StateRetriever interface for retrieving state deltas, etc.

type TransactionProccesor

type TransactionProccesor interface {
	ProcessTransactionMsg(*pb.Message, *pb.Transaction) *pb.Response
}

TransactionProccesor responsible for processing of Transactions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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