// NetworkStack is used to retrieve network info and send messages
type NetworkStack interface {
Communicator
Inquirer
}
type communicator interface {
consensus.Communicator
consensus.Inquirer
}
type NetworkStack interface {
Communicator
Inquirer
}
engine.helper = NewHelper(coord)
// Helper contains the reference to the peer's MessageHandlerCoordinator
type Helper struct {
consenter consensus.Consenter
coordinator peer.MessageHandlerCoordinator
secOn bool
valid bool // Whether we believe the state is up to date
secHelper crypto.Peer
curBatch []*pb.Transaction // TODO, remove after issue 579
curBatchErrs []*pb.TransactionResult // TODO, remove after issue 579
persist.Helper
executor consensus.Executor
}
// GetNetworkInfo returns the PeerEndpoints of the current validator and the entire validating network
func (h *Helper) GetNetworkInfo() (self *pb.PeerEndpoint, network []*pb.PeerEndpoint, err error) {
ep, err := h.coordinator.GetPeerEndpoint()
if err != nil {
return self, network, fmt.Errorf("Couldn't retrieve own endpoint: %v", err)
}
self = ep
peersMsg, err := h.coordinator.GetPeers()
if err != nil {
return self, network, fmt.Errorf("Couldn't retrieve list of peers: %v", err)
}
peers := peersMsg.GetPeers()
for _, endpoint := range peers {
if endpoint.Type == pb.PeerEndpoint_VALIDATOR {
network = append(network, endpoint)
}
}
network = append(network, self)
return
}