Skip to content

Commit

Permalink
[FAB-3755] Gossip:Add remote peer endpoint to ConnInfo
Browse files Browse the repository at this point in the history
In gossip we have the following struct that can be extracted
from a point-to-point message:

type ConnectionInfo struct {
    ID       common.PKIidType
    Auth     *AuthInfo
    Identity api.PeerIdentityType
}

In the logs we write the ID of the peer but it's a byte slice,
and doesn't tell much about the peer.

On the other hand, when a remote peer connects to a peer,
we extract its endpoint anyway.

I added the endpoint to the struct and added an assignment
at the handshake time.

Change-Id: If29abda09f2b066332099a45328c26027641215b
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed May 10, 2017
1 parent 5a27382 commit b7e2226
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (*proto.ConnectionInfo,
connInfo := &proto.ConnectionInfo{
ID: receivedMsg.PkiId,
Identity: receivedMsg.Cert,
Endpoint: remoteAddress,
}

// if TLS is enabled and detected, verify remote peer
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ func (gc *gossipChannel) HandleMessage(msg proto.ReceivedMessage) {
}
orgID := gc.GetOrgOfPeer(msg.GetConnectionInfo().ID)
if len(orgID) == 0 {
gc.logger.Debug("Couldn't find org identity of peer", msg.GetConnectionInfo().ID)
gc.logger.Debug("Couldn't find org identity of peer", msg.GetConnectionInfo())
return
}
if !gc.IsOrgInChannel(orgID) {
gc.logger.Warning("Point to point message came from", msg.GetConnectionInfo().ID,
gc.logger.Warning("Point to point message came from", msg.GetConnectionInfo(),
", org(", string(orgID), ") but it's not eligible for the channel", string(gc.chainID))
return
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (g *gossipServiceImpl) handleMessage(m proto.ReceivedMessage) {

msg := m.GetGossipMessage()

g.logger.Debug("Entering,", m.GetConnectionInfo().ID, "sent us", msg)
g.logger.Debug("Entering,", m.GetConnectionInfo(), "sent us", msg)
defer g.logger.Debug("Exiting")

if !g.validateMsg(m) {
Expand Down
12 changes: 10 additions & 2 deletions protos/gossip/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,18 @@ type ConnectionInfo struct {
ID common.PKIidType
Auth *AuthInfo
Identity api.PeerIdentityType
Endpoint string
}

func (connInfo *ConnectionInfo) IsAuthenticated() bool {
return connInfo.Auth != nil
// String returns a string representation of this ConnectionInfo
func (c *ConnectionInfo) String() string {
return fmt.Sprintf("%s %v", c.Endpoint, c.ID)
}

// IsAuthenticated returns whether the connection to the remote peer
// was authenticated when the handshake took place
func (c *ConnectionInfo) IsAuthenticated() bool {
return c.Auth != nil
}

// AuthInfo represents the authentication
Expand Down

0 comments on commit b7e2226

Please sign in to comment.