github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/gossip/comm/comm.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8                   http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package comm
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/hyperledger/fabric/gossip/api"
    23  	"github.com/hyperledger/fabric/gossip/common"
    24  	proto "github.com/hyperledger/fabric/protos/gossip"
    25  )
    26  
    27  // Comm is an object that enables to communicate with other peers
    28  // that also embed a CommModule.
    29  type Comm interface {
    30  
    31  	// GetPKIid returns this instance's PKI id
    32  	GetPKIid() common.PKIidType
    33  
    34  	// Send sends a message to remote peers
    35  	Send(msg *proto.SignedGossipMessage, peers ...*RemotePeer)
    36  
    37  	// Probe probes a remote node and returns nil if its responsive,
    38  	// and an error if it's not.
    39  	Probe(peer *RemotePeer) error
    40  
    41  	// Handshake authenticates a remote peer and returns
    42  	// (its identity, nil) on success and (nil, error)
    43  	Handshake(peer *RemotePeer) (api.PeerIdentityType, error)
    44  
    45  	// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
    46  	// Each message from the channel can be used to send a reply back to the sender
    47  	Accept(common.MessageAcceptor) <-chan proto.ReceivedMessage
    48  
    49  	// PresumedDead returns a read-only channel for node endpoints that are suspected to be offline
    50  	PresumedDead() <-chan common.PKIidType
    51  
    52  	// CloseConn closes a connection to a certain endpoint
    53  	CloseConn(peer *RemotePeer)
    54  
    55  	// Stop stops the module
    56  	Stop()
    57  }
    58  
    59  // RemotePeer defines a peer's endpoint and its PKIid
    60  type RemotePeer struct {
    61  	Endpoint string
    62  	PKIID    common.PKIidType
    63  }
    64  
    65  // String converts a RemotePeer to a string
    66  func (p *RemotePeer) String() string {
    67  	return fmt.Sprintf("%s, PKIid:%v", p.Endpoint, p.PKIID)
    68  }