github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/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/common" 23 proto "github.com/hyperledger/fabric/protos/gossip" 24 ) 25 26 // Comm is an object that enables to communicate with other peers 27 // that also embed a CommModule. 28 type Comm interface { 29 30 // GetPKIid returns this instance's PKI id 31 GetPKIid() common.PKIidType 32 33 // Send sends a message to remote peers 34 Send(msg *proto.SignedGossipMessage, peers ...*RemotePeer) 35 36 // Probe probes a remote node and returns nil if its responsive 37 Probe(peer *RemotePeer) error 38 39 // Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate. 40 // Each message from the channel can be used to send a reply back to the sender 41 Accept(common.MessageAcceptor) <-chan proto.ReceivedMessage 42 43 // PresumedDead returns a read-only channel for node endpoints that are suspected to be offline 44 PresumedDead() <-chan common.PKIidType 45 46 // CloseConn closes a connection to a certain endpoint 47 CloseConn(peer *RemotePeer) 48 49 // Stop stops the module 50 Stop() 51 52 // BlackListPKIid prohibits the module communicating with the given PKIid 53 BlackListPKIid(PKIid common.PKIidType) 54 } 55 56 // RemotePeer defines a peer's endpoint and its PKIid 57 type RemotePeer struct { 58 Endpoint string 59 PKIID common.PKIidType 60 } 61 62 // String converts a RemotePeer to a string 63 func (p *RemotePeer) String() string { 64 return fmt.Sprintf("%s, PKIid:%v", p.Endpoint, p.PKIID) 65 }