Skip to content

Commit

Permalink
Gossip internal API changes, and discovery refact
Browse files Browse the repository at this point in the history
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 <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Oct 31, 2016
1 parent 18a44d0 commit 8249ddd
Show file tree
Hide file tree
Showing 9 changed files with 551 additions and 499 deletions.
61 changes: 44 additions & 17 deletions gossip/comm/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,63 @@ limitations under the License.
package comm

import (
"fmt"

"github.com/hyperledger/fabric/gossip/proto"
"sync"
"github.com/hyperledger/fabric/gossip/util"
)

type CommModule interface {
// Send sends a message to endpoints
Send(msg *proto.GossipMessage, endpoints ...string)
// Comm is an object that enables to communicate with other peers
// that also embed a CommModule.
type Comm interface {

// GetPKIid returns this instance's PKI id
GetPKIid() PKIidType

// SetPKIid asserts that pkiId is the PKI_id of endpoint
SetPKIid(endpoint, pkiId []byte)
// Send sends a message to remote peers
Send(msg *proto.GossipMessage, peers ...*RemotePeer)

// Probe probes a remote node and returns nil if its responsive
Probe(endpoint string) error
Probe(endpoint string, pkiID PKIidType) error

// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
// Each message from the channel can be used to send a reply back to the sender
Accept(MessageAcceptor) <-chan *ReceivedMessage
Accept(util.MessageAcceptor) <-chan ReceivedMessage

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

// CloseConn closes a connection to a certain endpoint
CloseConn(endpoint string)
CloseConn(peer *RemotePeer)

// Stop stops the module
Stop()

// BlackListPKIid prohibits the module communicating with the given PKIid
BlackListPKIid(PKIid PKIidType)
}

// PKIidType defines the type that holds the PKI-id
// which is the security identifier of a peer
type PKIidType []byte

// RemotePeer defines a peer's endpoint and its PKIid
type RemotePeer struct {
Endpoint string
PKIID PKIidType
}

// String converts a RemotePeer to a string
func (p *RemotePeer) String() string {
return fmt.Sprintf("%s, PKIid:%v", p.Endpoint, p.PKIID)
}

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

// isEnabled returns whether this
isEnabled() bool
IsEnabled() bool

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

// ReceivedMessage is a GossipMessage wrapper that
// enables the user to send a message to the origin from which
// the ReceivedMessage was sent from
type ReceivedMessage interface {

type MessageAcceptor func(*proto.GossipMessage) bool
// Respond sends a GossipMessage to the origin from which this ReceivedMessage was sent from
Respond(msg *proto.GossipMessage)

type ReceivedMessage struct {
*proto.GossipMessage
lock *sync.Mutex
srvStream proto.Gossip_GossipStreamServer
clStream proto.Gossip_GossipStreamClient
// GetGossipMessage returns the underlying GossipMessage
GetGossipMessage() *proto.GossipMessage
}
21 changes: 0 additions & 21 deletions gossip/discovery/consts.go

This file was deleted.

18 changes: 9 additions & 9 deletions gossip/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ type CommService interface {
Ping(peer *NetworkMember) bool

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

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

// CloseConn orders to close the connection with a certain peer
CloseConn(id string)
CloseConn(peer *NetworkMember)
}

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

// NetworkMember is a peer's representation
type NetworkMember struct {
Id string
Endpoint string
Metadata []byte
PKIid []byte
PKIid PKIidType
}

type DiscoveryService interface {
// Discovery is the interface that represents a discovery module
type Discovery interface {

// Self returns this instance's membership information
Self() NetworkMember
Expand Down

0 comments on commit 8249ddd

Please sign in to comment.