Skip to content

Commit 2dc89f9

Browse files
committed
[FAB-14198] ConnectionInfo, AuthInfo out of protos
Relocate to gossip proto extensions for now. Change-Id: I5ad993896988e3ab43283c0dae8dd7f724e2645e Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 2a8bdea commit 2dc89f9

File tree

12 files changed

+65
-59
lines changed

12 files changed

+65
-59
lines changed

gossip/comm/comm_impl.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT
130130
var cc *grpc.ClientConn
131131
var stream proto.Gossip_GossipStreamClient
132132
var pkiID common.PKIidType
133-
var connInfo *proto.ConnectionInfo
133+
var connInfo *protoext.ConnectionInfo
134134
var dialOpts []grpc.DialOption
135135

136136
c.logger.Debug("Entering", endpoint, expectedPKIID)
@@ -395,7 +395,7 @@ func extractRemoteAddress(stream stream) string {
395395
return remoteAddress
396396
}
397397

398-
func (c *commImpl) authenticateRemotePeer(stream stream, initiator bool) (*proto.ConnectionInfo, error) {
398+
func (c *commImpl) authenticateRemotePeer(stream stream, initiator bool) (*protoext.ConnectionInfo, error) {
399399
ctx := stream.Context()
400400
remoteAddress := extractRemoteAddress(stream)
401401
remoteCertHash := extractCertificateHashFromContext(ctx)
@@ -452,11 +452,11 @@ func (c *commImpl) authenticateRemotePeer(stream stream, initiator bool) (*proto
452452
return nil, err
453453
}
454454

455-
connInfo := &proto.ConnectionInfo{
455+
connInfo := &protoext.ConnectionInfo{
456456
ID: receivedMsg.PkiId,
457457
Identity: receivedMsg.Identity,
458458
Endpoint: remoteAddress,
459-
Auth: &proto.AuthInfo{
459+
Auth: &protoext.AuthInfo{
460460
Signature: m.Signature,
461461
SignedData: m.Payload,
462462
},

gossip/comm/conn.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/hyperledger/fabric/gossip/common"
1616
"github.com/hyperledger/fabric/gossip/metrics"
17+
"github.com/hyperledger/fabric/gossip/protoext"
1718
"github.com/hyperledger/fabric/gossip/util"
1819
proto "github.com/hyperledger/fabric/protos/gossip"
1920
"github.com/pkg/errors"
@@ -165,7 +166,7 @@ func (cs *connectionStore) shutdown() {
165166
}
166167

167168
func (cs *connectionStore) onConnected(serverStream proto.Gossip_GossipStreamServer,
168-
connInfo *proto.ConnectionInfo, metrics *metrics.CommMetrics) *connection {
169+
connInfo *protoext.ConnectionInfo, metrics *metrics.CommMetrics) *connection {
169170
cs.Lock()
170171
defer cs.Unlock()
171172

@@ -176,7 +177,7 @@ func (cs *connectionStore) onConnected(serverStream proto.Gossip_GossipStreamSer
176177
return cs.registerConn(connInfo, serverStream, metrics)
177178
}
178179

179-
func (cs *connectionStore) registerConn(connInfo *proto.ConnectionInfo,
180+
func (cs *connectionStore) registerConn(connInfo *protoext.ConnectionInfo,
180181
serverStream proto.Gossip_GossipStreamServer, metrics *metrics.CommMetrics) *connection {
181182
conn := newConnection(nil, nil, nil, serverStream, metrics, cs.config)
182183
conn.pkiID = connInfo.ID
@@ -221,7 +222,7 @@ type connection struct {
221222
recvBuffSize int
222223
metrics *metrics.CommMetrics
223224
cancel context.CancelFunc
224-
info *proto.ConnectionInfo
225+
info *protoext.ConnectionInfo
225226
outBuff chan *msgSending
226227
logger util.Logger // logger
227228
pkiID common.PKIidType // pkiID of the remote endpoint

gossip/comm/mock/mock_comm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (packet *packetMock) GetGossipMessage() *proto.SignedGossipMessage {
104104

105105
// GetConnectionInfo returns information about the remote peer
106106
// that sent the message
107-
func (packet *packetMock) GetConnectionInfo() *proto.ConnectionInfo {
107+
func (packet *packetMock) GetConnectionInfo() *protoext.ConnectionInfo {
108108
return nil
109109
}
110110

gossip/comm/msg.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package comm
99
import (
1010
"sync"
1111

12+
"github.com/hyperledger/fabric/gossip/protoext"
1213
proto "github.com/hyperledger/fabric/protos/gossip"
1314
"github.com/pkg/errors"
1415
)
@@ -18,7 +19,7 @@ type ReceivedMessageImpl struct {
1819
*proto.SignedGossipMessage
1920
lock sync.Locker
2021
conn *connection
21-
connInfo *proto.ConnectionInfo
22+
connInfo *protoext.ConnectionInfo
2223
}
2324

2425
// GetSourceEnvelope Returns the Envelope the ReceivedMessage was
@@ -45,7 +46,7 @@ func (m *ReceivedMessageImpl) GetGossipMessage() *proto.SignedGossipMessage {
4546

4647
// GetConnectionInfo returns information about the remote peer
4748
// that send the message
48-
func (m *ReceivedMessageImpl) GetConnectionInfo() *proto.ConnectionInfo {
49+
func (m *ReceivedMessageImpl) GetConnectionInfo() *protoext.ConnectionInfo {
4950
return m.connInfo
5051
}
5152

gossip/discovery/discovery_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func init() {
4949

5050
type dummyReceivedMessage struct {
5151
msg *proto.SignedGossipMessage
52-
info *proto.ConnectionInfo
52+
info *protoext.ConnectionInfo
5353
}
5454

5555
func (*dummyReceivedMessage) Respond(msg *proto.GossipMessage) {
@@ -64,7 +64,7 @@ func (*dummyReceivedMessage) GetSourceEnvelope() *proto.Envelope {
6464
panic("implement me")
6565
}
6666

67-
func (rm *dummyReceivedMessage) GetConnectionInfo() *proto.ConnectionInfo {
67+
func (rm *dummyReceivedMessage) GetConnectionInfo() *protoext.ConnectionInfo {
6868
return rm.info
6969
}
7070

@@ -275,7 +275,7 @@ func (g *gossipInstance) GossipStream(stream proto.Gossip_GossipStreamServer) er
275275
lgr.Debug(g.Discovery.Self().Endpoint, "Got message:", gMsg)
276276
g.comm.incMsgs <- &dummyReceivedMessage{
277277
msg: gMsg,
278-
info: &proto.ConnectionInfo{
278+
info: &protoext.ConnectionInfo{
279279
ID: common.PKIidType("testID"),
280280
},
281281
}
@@ -461,7 +461,7 @@ func TestBadInput(t *testing.T) {
461461
}).NoopSign()
462462
inst.Discovery.(*gossipDiscoveryImpl).handleMsgFromComm(&dummyReceivedMessage{
463463
msg: s,
464-
info: &proto.ConnectionInfo{
464+
info: &protoext.ConnectionInfo{
465465
ID: common.PKIidType("testID"),
466466
},
467467
})
@@ -533,7 +533,7 @@ func TestValidation(t *testing.T) {
533533
wrapReceivedMessage := func(msg *proto.SignedGossipMessage) protoext.ReceivedMessage {
534534
return &dummyReceivedMessage{
535535
msg: msg,
536-
info: &proto.ConnectionInfo{
536+
info: &protoext.ConnectionInfo{
537537
ID: common.PKIidType("testID"),
538538
},
539539
}
@@ -1212,7 +1212,7 @@ func TestMsgStoreExpirationWithMembershipMessages(t *testing.T) {
12121212
for k := 0; k < peersNum; k++ {
12131213
instances[i].discoveryImpl().handleMsgFromComm(&dummyReceivedMessage{
12141214
msg: aliveMsgs[k],
1215-
info: &proto.ConnectionInfo{
1215+
info: &protoext.ConnectionInfo{
12161216
ID: common.PKIidType(fmt.Sprintf("d%d", i)),
12171217
},
12181218
})
@@ -1279,7 +1279,7 @@ func TestMsgStoreExpirationWithMembershipMessages(t *testing.T) {
12791279
for k := 0; k < peersNum; k++ {
12801280
instances[i].discoveryImpl().handleMsgFromComm(&dummyReceivedMessage{
12811281
msg: newAliveMsgs[k],
1282-
info: &proto.ConnectionInfo{
1282+
info: &protoext.ConnectionInfo{
12831283
ID: common.PKIidType(fmt.Sprintf("d%d", i)),
12841284
},
12851285
})
@@ -1319,7 +1319,7 @@ func TestMsgStoreExpirationWithMembershipMessages(t *testing.T) {
13191319
func(k int) {
13201320
instances[i].discoveryImpl().handleMsgFromComm(&dummyReceivedMessage{
13211321
msg: memReqMsgs[k],
1322-
info: &proto.ConnectionInfo{
1322+
info: &protoext.ConnectionInfo{
13231323
ID: common.PKIidType(fmt.Sprintf("d%d", i)),
13241324
},
13251325
})
@@ -1336,7 +1336,7 @@ func TestMsgStoreExpirationWithMembershipMessages(t *testing.T) {
13361336
for k := 0; k < peersNum; k++ {
13371337
instances[i].discoveryImpl().handleMsgFromComm(&dummyReceivedMessage{
13381338
msg: aliveMsgs[k],
1339-
info: &proto.ConnectionInfo{
1339+
info: &protoext.ConnectionInfo{
13401340
ID: common.PKIidType(fmt.Sprintf("d%d", i)),
13411341
},
13421342
})
@@ -1362,7 +1362,7 @@ func TestMsgStoreExpirationWithMembershipMessages(t *testing.T) {
13621362
}).NoopSign()
13631363
instances[i].discoveryImpl().handleMsgFromComm(&dummyReceivedMessage{
13641364
msg: sMsg,
1365-
info: &proto.ConnectionInfo{
1365+
info: &protoext.ConnectionInfo{
13661366
ID: common.PKIidType(fmt.Sprintf("d%d", i)),
13671367
},
13681368
})

gossip/gossip/certstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *sentMsg) GetGossipMessage() *proto.SignedGossipMessage {
6666
return s.msg
6767
}
6868

69-
func (s *sentMsg) GetConnectionInfo() *proto.ConnectionInfo {
69+
func (s *sentMsg) GetConnectionInfo() *protoext.ConnectionInfo {
7070
return nil
7171
}
7272

gossip/gossip/channel/channel_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ func (m *receivedMsg) Ack(err error) {
179179

180180
}
181181

182-
func (m *receivedMsg) GetConnectionInfo() *proto.ConnectionInfo {
183-
return &proto.ConnectionInfo{
182+
func (m *receivedMsg) GetConnectionInfo() *protoext.ConnectionInfo {
183+
return &protoext.ConnectionInfo{
184184
ID: m.PKIID,
185185
}
186186
}

gossip/gossip/pull/pullstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (pm *pullMsg) GetGossipMessage() *proto.SignedGossipMessage {
5656
return pm.msg
5757
}
5858

59-
func (pm *pullMsg) GetConnectionInfo() *proto.ConnectionInfo {
59+
func (pm *pullMsg) GetConnectionInfo() *protoext.ConnectionInfo {
6060
return nil
6161
}
6262

gossip/privdata/pull_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ func (msg *receivedMsg) GetSourceEnvelope() *proto.Envelope {
193193
panic("implement me")
194194
}
195195

196-
func (msg *receivedMsg) GetConnectionInfo() *proto.ConnectionInfo {
197-
return &proto.ConnectionInfo{
196+
func (msg *receivedMsg) GetConnectionInfo() *protoext.ConnectionInfo {
197+
return &protoext.ConnectionInfo{
198198
Identity: api.PeerIdentityType(msg.RemotePeer.PKIID),
199-
Auth: &proto.AuthInfo{
199+
Auth: &protoext.AuthInfo{
200200
SignedData: []byte{},
201201
Signature: []byte{},
202202
},

gossip/protoext/receivedmessage.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ SPDX-License-Identifier: Apache-2.0
66

77
package protoext
88

9-
import "github.com/hyperledger/fabric/protos/gossip"
9+
import (
10+
"fmt"
11+
12+
"github.com/hyperledger/fabric/gossip/api"
13+
"github.com/hyperledger/fabric/gossip/common"
14+
"github.com/hyperledger/fabric/protos/gossip"
15+
)
1016

1117
// ReceivedMessage is a GossipMessage wrapper that
1218
// enables the user to send a message to the origin from which
@@ -27,10 +33,32 @@ type ReceivedMessage interface {
2733

2834
// GetConnectionInfo returns information about the remote peer
2935
// that sent the message
30-
GetConnectionInfo() *gossip.ConnectionInfo
36+
GetConnectionInfo() *ConnectionInfo
3137

3238
// Ack returns to the sender an acknowledgement for the message
3339
// An ack can receive an error that indicates that the operation related
3440
// to the message has failed
3541
Ack(err error)
3642
}
43+
44+
// ConnectionInfo represents information about
45+
// the remote peer that sent a certain ReceivedMessage
46+
type ConnectionInfo struct {
47+
ID common.PKIidType
48+
Auth *AuthInfo
49+
Identity api.PeerIdentityType
50+
Endpoint string
51+
}
52+
53+
// String returns a string representation of this ConnectionInfo
54+
func (c *ConnectionInfo) String() string {
55+
return fmt.Sprintf("%s %v", c.Endpoint, c.ID)
56+
}
57+
58+
// AuthInfo represents the authentication
59+
// data that was provided by the remote peer
60+
// at the connection time
61+
type AuthInfo struct {
62+
SignedData []byte
63+
Signature []byte
64+
}

0 commit comments

Comments
 (0)