github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/gossip/comm/comm.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package comm
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/hyperledger/fabric/gossip/api"
    13  	"github.com/hyperledger/fabric/gossip/common"
    14  	proto "github.com/hyperledger/fabric/protos/gossip"
    15  )
    16  
    17  // Comm is an object that enables to communicate with other peers
    18  // that also embed a CommModule.
    19  type Comm interface {
    20  
    21  	// GetPKIid returns this instance's PKI id
    22  	GetPKIid() common.PKIidType
    23  
    24  	// Send sends a message to remote peers
    25  	Send(msg *proto.SignedGossipMessage, peers ...*RemotePeer)
    26  
    27  	// Probe probes a remote node and returns nil if its responsive,
    28  	// and an error if it's not.
    29  	Probe(peer *RemotePeer) error
    30  
    31  	// Handshake authenticates a remote peer and returns
    32  	// (its identity, nil) on success and (nil, error)
    33  	Handshake(peer *RemotePeer) (api.PeerIdentityType, error)
    34  
    35  	// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
    36  	// Each message from the channel can be used to send a reply back to the sender
    37  	Accept(common.MessageAcceptor) <-chan proto.ReceivedMessage
    38  
    39  	// PresumedDead returns a read-only channel for node endpoints that are suspected to be offline
    40  	PresumedDead() <-chan common.PKIidType
    41  
    42  	// CloseConn closes a connection to a certain endpoint
    43  	CloseConn(peer *RemotePeer)
    44  
    45  	// Stop stops the module
    46  	Stop()
    47  }
    48  
    49  // RemotePeer defines a peer's endpoint and its PKIid
    50  type RemotePeer struct {
    51  	Endpoint string
    52  	PKIID    common.PKIidType
    53  }
    54  
    55  // String converts a RemotePeer to a string
    56  func (p *RemotePeer) String() string {
    57  	return fmt.Sprintf("%s, PKIid:%v", p.Endpoint, p.PKIID)
    58  }