@@ -17,38 +17,63 @@ limitations under the License.
17
17
package comm
18
18
19
19
import (
20
+ "fmt"
21
+
20
22
"github.com/hyperledger/fabric/gossip/proto"
21
- "sync "
23
+ "github.com/hyperledger/fabric/gossip/util "
22
24
)
23
25
24
- type CommModule interface {
25
- // Send sends a message to endpoints
26
- Send (msg * proto.GossipMessage , endpoints ... string )
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 () PKIidType
27
32
28
- // SetPKIid asserts that pkiId is the PKI_id of endpoint
29
- SetPKIid ( endpoint , pkiId [] byte )
33
+ // Send sends a message to remote peers
34
+ Send ( msg * proto. GossipMessage , peers ... * RemotePeer )
30
35
31
36
// Probe probes a remote node and returns nil if its responsive
32
- Probe (endpoint string ) error
37
+ Probe (endpoint string , pkiID PKIidType ) error
33
38
34
39
// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
35
40
// Each message from the channel can be used to send a reply back to the sender
36
- Accept (MessageAcceptor ) <- chan * ReceivedMessage
41
+ Accept (util. MessageAcceptor ) <- chan ReceivedMessage
37
42
38
43
// PresumedDead returns a read-only channel for node endpoints that are suspected to be offline
39
- PresumedDead () <- chan string
44
+ PresumedDead () <- chan PKIidType
40
45
41
46
// CloseConn closes a connection to a certain endpoint
42
- CloseConn (endpoint string )
47
+ CloseConn (peer * RemotePeer )
43
48
44
49
// Stop stops the module
45
50
Stop ()
51
+
52
+ // BlackListPKIid prohibits the module communicating with the given PKIid
53
+ BlackListPKIid (PKIid PKIidType )
54
+ }
55
+
56
+ // PKIidType defines the type that holds the PKI-id
57
+ // which is the security identifier of a peer
58
+ type PKIidType []byte
59
+
60
+ // RemotePeer defines a peer's endpoint and its PKIid
61
+ type RemotePeer struct {
62
+ Endpoint string
63
+ PKIID PKIidType
64
+ }
65
+
66
+ // String converts a RemotePeer to a string
67
+ func (p * RemotePeer ) String () string {
68
+ return fmt .Sprintf ("%s, PKIid:%v" , p .Endpoint , p .PKIID )
46
69
}
47
70
71
+ // SecurityProvider enables the communication module to perform
72
+ // a handshake that authenticates the client to the server and vice versa
48
73
type SecurityProvider interface {
49
74
50
75
// isEnabled returns whether this
51
- isEnabled () bool
76
+ IsEnabled () bool
52
77
53
78
// Sign signs msg with this peers signing key and outputs
54
79
// the signature if no error occurred.
@@ -60,12 +85,14 @@ type SecurityProvider interface {
60
85
Verify (vkID , signature , message []byte ) error
61
86
}
62
87
88
+ // ReceivedMessage is a GossipMessage wrapper that
89
+ // enables the user to send a message to the origin from which
90
+ // the ReceivedMessage was sent from
91
+ type ReceivedMessage interface {
63
92
64
- type MessageAcceptor func (* proto.GossipMessage ) bool
93
+ // Respond sends a GossipMessage to the origin from which this ReceivedMessage was sent from
94
+ Respond (msg * proto.GossipMessage )
65
95
66
- type ReceivedMessage struct {
67
- * proto.GossipMessage
68
- lock * sync.Mutex
69
- srvStream proto.Gossip_GossipStreamServer
70
- clStream proto.Gossip_GossipStreamClient
96
+ // GetGossipMessage returns the underlying GossipMessage
97
+ GetGossipMessage () * proto.GossipMessage
71
98
}
0 commit comments