Skip to content

Commit 8249ddd

Browse files
committed
Gossip internal API changes, and discovery refact
This commit prepares the gossip component to disregard a peer's ID, and to use only PKI-ID as identification instead, since it's the only thing that can be tied to its identity. This commit also contains some additional protobuf messages needed for further commits, and also has a partial refactoring of the discovery module to accomodate the internal API changes. Change-Id: I6c12bee5fbb072bba0ab34fb4a09f5025b106161 Signed-off-by: Yacov Manevich <[email protected]>
1 parent 18a44d0 commit 8249ddd

File tree

9 files changed

+551
-499
lines changed

9 files changed

+551
-499
lines changed

gossip/comm/comm.go

+44-17
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,63 @@ limitations under the License.
1717
package comm
1818

1919
import (
20+
"fmt"
21+
2022
"github.com/hyperledger/fabric/gossip/proto"
21-
"sync"
23+
"github.com/hyperledger/fabric/gossip/util"
2224
)
2325

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
2732

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)
3035

3136
// Probe probes a remote node and returns nil if its responsive
32-
Probe(endpoint string) error
37+
Probe(endpoint string, pkiID PKIidType) error
3338

3439
// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
3540
// 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
3742

3843
// PresumedDead returns a read-only channel for node endpoints that are suspected to be offline
39-
PresumedDead() <-chan string
44+
PresumedDead() <-chan PKIidType
4045

4146
// CloseConn closes a connection to a certain endpoint
42-
CloseConn(endpoint string)
47+
CloseConn(peer *RemotePeer)
4348

4449
// Stop stops the module
4550
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)
4669
}
4770

71+
// SecurityProvider enables the communication module to perform
72+
// a handshake that authenticates the client to the server and vice versa
4873
type SecurityProvider interface {
4974

5075
// isEnabled returns whether this
51-
isEnabled() bool
76+
IsEnabled() bool
5277

5378
// Sign signs msg with this peers signing key and outputs
5479
// the signature if no error occurred.
@@ -60,12 +85,14 @@ type SecurityProvider interface {
6085
Verify(vkID, signature, message []byte) error
6186
}
6287

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 {
6392

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)
6595

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
7198
}

gossip/discovery/consts.go

-21
This file was deleted.

gossip/discovery/discovery.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ type CommService interface {
4040
Ping(peer *NetworkMember) bool
4141

4242
// Accept returns a read-only channel for membership messages sent from remote peers
43-
Accept() <-chan GossipMsg
43+
Accept() <-chan *proto.GossipMessage
4444

4545
// PresumedDead returns a read-only channel for peers that are presumed to be dead
46-
PresumedDead() <-chan string
46+
PresumedDead() <-chan PKIidType
4747

4848
// CloseConn orders to close the connection with a certain peer
49-
CloseConn(id string)
49+
CloseConn(peer *NetworkMember)
5050
}
5151

52-
type GossipMsg interface {
53-
GetGossipMessage() *proto.GossipMessage
54-
}
52+
// PKIidType represents a peer's security identity
53+
type PKIidType []byte
5554

55+
// NetworkMember is a peer's representation
5656
type NetworkMember struct {
57-
Id string
5857
Endpoint string
5958
Metadata []byte
60-
PKIid []byte
59+
PKIid PKIidType
6160
}
6261

63-
type DiscoveryService interface {
62+
// Discovery is the interface that represents a discovery module
63+
type Discovery interface {
6464

6565
// Self returns this instance's membership information
6666
Self() NetworkMember

0 commit comments

Comments
 (0)