peer

package
v0.0.0-...-667e438 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

Variables

View Source
var PeerGlobalParentCtx = context.Background()

Functions

func NewCredQuery

func NewCredQuery() *pb.Message

func NewPeerClientConnectionWithAddress

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

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

func SetLegacyEngine

func SetLegacyEngine(e Engine)

Types

type ChatStream

type ChatStream interface {
	Send(*pb.Message) error
	Recv() (*pb.Message, error)
	Context() context.Context
	//this can be called externally and stop current stream (Recv will be interrupted and
	//return non io.EOF error)
	Close()
}

ChatStream interface supported by stream between Peers

type Discoverer

type Discoverer interface {
	GetDiscHelper() discovery.Discovery
}

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

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
	HandlerFactory(MessageHandler) (LegacyMessageHandler, error)
}

type Handler

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

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

Handler peer handler implementation.

func (*Handler) Credential

func (d *Handler) Credential() cred.PeerCred

func (*Handler) GetStream

func (d *Handler) GetStream() ChatStream

func (*Handler) HandleMessage

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

HandleMessage handles the Openchain messages for the Peer.

func (*Handler) IsGlareWeak

func (d *Handler) IsGlareWeak(self *pb.PeerID) bool

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 Peer.

func (*Handler) To

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

To return the PeerEndpoint this Handler is connected to.

type Impl

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

Impl implementation of the Peer service

func CreateNewPeer

func CreateNewPeer(cred cred.PeerCreds, config *PeerConfig) (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 NewPeer

func NewPeer(self *pb.PeerEndpoint) *Impl

func (*Impl) AddStreamStub

func (p *Impl) AddStreamStub(name string, factory pb.StreamHandlerFactory, opts ...interface{}) error

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) DeregisterHandler

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

DeregisterHandler deregisters an already registered MessageHandler for this coordinator

func (*Impl) EndPeer

func (p *Impl) EndPeer()

func (*Impl) GetACL

func (p *Impl) GetACL() (acl.AccessControl, error)

func (*Impl) GetDiscHelper

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

func (*Impl) GetDiscoverer

func (p *Impl) GetDiscoverer() (Discoverer, error)

func (*Impl) GetNeighbour

func (p *Impl) GetNeighbour() (Neighbour, error)

func (*Impl) GetPeerCtx

func (p *Impl) GetPeerCtx() context.Context

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 which are also in peer discovery list

func (*Impl) GetStreamStub

func (p *Impl) GetStreamStub(name string) *pb.StreamStub

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(context.Context, *pb.Transaction) (*pb.Response, error)

func (*Impl) RegisterHandler

func (p *Impl) RegisterHandler(ctx context.Context, initiated bool, messageHandler MessageHandler) error

RegisterHandler register a MessageHandler with this coordinator

func (*Impl) RunPeer

func (p *Impl) RunPeer(config *PeerConfig)

func (*Impl) SendTransactionsToPeer

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

---- deprecated ----- SendTransactionsToPeer forwards transactions to the specified peer address.

func (*Impl) Unicast

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

Unicast sends a message to a specific peer.

type LegacyMessageHandler

type LegacyMessageHandler interface {
	HandleMessage(msg *pb.Message) error
}

type MessageHandler

type MessageHandler interface {
	LegacyMessageHandler
	SendMessage(msg *pb.Message) error
	GetStream() ChatStream
	To() (pb.PeerEndpoint, error)
	Credential() cred.PeerCred
	//test if current connection is "glare weak", if so, it will be replaced
	//by a "glare strong" incoming connection, a glare weak is determinded
	//in both side (i.e. it is weak in oneside will be also weak in another side)
	IsGlareWeak(self *pb.PeerID) bool
	Stop() error
}

MessageHandler standard interface for handling Openchain messages.

func NewPeerHandler

func NewPeerHandler(coord *Impl, stream ChatStream, initiatedStream bool, peerCred cred.PeerCred) (MessageHandler, error)

NewPeerHandler returns a new Peer handler Is instance of HandlerFactory

type Neighbour

type Neighbour interface {
	Broadcast(*pb.Message, pb.PeerEndpoint_Type) []error
	Unicast(*pb.Message, *pb.PeerID) error
	GetPeerEndpoint() (*pb.PeerEndpoint, error) //for convinient, we also include this method
	GetPeers() (*pb.PeersMessage, error)
	GetDiscoverer() (Discoverer, error)
	GetACL() (acl.AccessControl, error)
}

type Peer

type Peer interface {
	GetPeerEndpoint() (*pb.PeerEndpoint, error)
	GetNeighbour() (Neighbour, error)
	//init stream stubs, with options ...
	AddStreamStub(string, pb.StreamHandlerFactory, ...interface{}) error
	GetStreamStub(string) *pb.StreamStub
	GetPeerCtx() context.Context
}

Peer provides interface for a peer

type PeerConfig

type PeerConfig struct {
	PeerTag      string
	IsValidator  bool
	PeerEndpoint *pb.PeerEndpoint
	Discovery    struct {
		Roots       []string
		Persist     bool
		Hidden      bool
		Disable     bool
		TouchPeriod time.Duration
		MaxNodes    int
	}
	NewPeerClientConn func(string) (*grpc.ClientConn, error)
}

func NewPeerConfig

func NewPeerConfig(forValidator bool, vp *viper.Viper, spec *config.ServerSpec) (*PeerConfig, error)

func (*PeerConfig) Configuration

func (c *PeerConfig) Configuration(vp *viper.Viper, spec *config.ServerSpec) error

type StreamFilter

type StreamFilter interface {
	QualitifiedPeer(*pb.PeerEndpoint) bool
}

type StreamPostHandler

type StreamPostHandler interface {
	NotifyNewPeer(*pb.PeerID, *pb.StreamStub)
}

type TransactionProccesor

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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