From b7e22269705aca9c510d79a881fe237700d618df Mon Sep 17 00:00:00 2001 From: YACOVM Date: Wed, 10 May 2017 11:40:45 +0300 Subject: [PATCH] [FAB-3755] Gossip:Add remote peer endpoint to ConnInfo 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 --- gossip/comm/comm_impl.go | 1 + gossip/gossip/channel/channel.go | 4 ++-- gossip/gossip/gossip_impl.go | 2 +- protos/gossip/extensions.go | 12 ++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gossip/comm/comm_impl.go b/gossip/comm/comm_impl.go index b50fdabc9d8..5eb2e9a25da 100644 --- a/gossip/comm/comm_impl.go +++ b/gossip/comm/comm_impl.go @@ -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 diff --git a/gossip/gossip/channel/channel.go b/gossip/gossip/channel/channel.go index 5ea5d01b679..7b116d63b06 100644 --- a/gossip/gossip/channel/channel.go +++ b/gossip/gossip/channel/channel.go @@ -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 } diff --git a/gossip/gossip/gossip_impl.go b/gossip/gossip/gossip_impl.go index 6a950f5f939..8b921a3c123 100644 --- a/gossip/gossip/gossip_impl.go +++ b/gossip/gossip/gossip_impl.go @@ -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) { diff --git a/protos/gossip/extensions.go b/protos/gossip/extensions.go index e8574fa79c0..e83c1103aa9 100644 --- a/protos/gossip/extensions.go +++ b/protos/gossip/extensions.go @@ -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