Skip to content

Commit d5b4dbc

Browse files
committed
Replace Probe method input parameter
As it already exists RemotePeer struct which contains Endpoint and PKIID property, Probe method can use RemotePeer as input parameter directly. See https://jira.hyperledger.org/browse/FAB-1146 Change-Id: Id26077db6360f49087cc8e1d1ab14eefd2c67317 Signed-off-by: grapebaba <[email protected]>
1 parent 97f8584 commit d5b4dbc

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

gossip/comm/comm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Comm interface {
3434
Send(msg *proto.GossipMessage, peers ...*RemotePeer)
3535

3636
// Probe probes a remote node and returns nil if its responsive
37-
Probe(endpoint string, pkiID common.PKIidType) error
37+
Probe(peer *RemotePeer) error
3838

3939
// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.
4040
// Each message from the channel can be used to send a reply back to the sender

gossip/comm/comm_impl.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ func (c *commImpl) isStopping() bool {
250250
return atomic.LoadInt32(&c.stopping) == int32(1)
251251
}
252252

253-
func (c *commImpl) Probe(endpoint string, pkiID common.PKIidType) error {
253+
func (c *commImpl) Probe(peer *RemotePeer) error {
254254
if c.isStopping() {
255255
return fmt.Errorf("Stopping!")
256256
}
257-
c.logger.Debug("Entering, endpoint:", endpoint, "PKIID:", pkiID)
257+
c.logger.Debug("Entering, endpoint:", peer.Endpoint, "PKIID:", peer.PKIID)
258258
var err error
259259

260260
opts := c.opts
261261
if opts == nil {
262262
opts = []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(dialTimeout)}
263263
}
264-
cc, err := grpc.Dial(endpoint, append(opts, grpc.WithBlock())...)
264+
cc, err := grpc.Dial(peer.Endpoint, append(opts, grpc.WithBlock())...)
265265
if err != nil {
266266
c.logger.Debug("Returning", err)
267267
return err

gossip/comm/comm_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,16 @@ func TestProbe(t *testing.T) {
429429
defer comm1.Stop()
430430
comm2, _ := newCommInstance(6612, naiveSec)
431431
time.Sleep(time.Duration(1) * time.Second)
432-
assert.NoError(t, comm1.Probe("localhost:6612", []byte("localhost:6612")))
433-
assert.Error(t, comm1.Probe("localhost:9012", []byte("localhost:9012")))
432+
assert.NoError(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:6612", PKIID: []byte("localhost:6612")}))
433+
assert.Error(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:9012", PKIID: []byte("localhost:9012")}))
434434
comm2.Stop()
435435
time.Sleep(time.Second)
436-
assert.Error(t, comm1.Probe("localhost:6612", []byte("localhost:6612")))
436+
assert.Error(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:6612", PKIID: []byte("localhost:6612")}))
437437
comm2, _ = newCommInstance(6612, naiveSec)
438438
defer comm2.Stop()
439439
time.Sleep(time.Duration(1) * time.Second)
440-
assert.NoError(t, comm2.Probe("localhost:6611", []byte("localhost:6611")))
441-
assert.NoError(t, comm1.Probe("localhost:6612", []byte("localhost:6612")))
440+
assert.NoError(t, comm2.Probe(&RemotePeer{Endpoint: "localhost:6611", PKIID: []byte("localhost:6611")}))
441+
assert.NoError(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:6612", PKIID: []byte("localhost:6612")}))
442442
}
443443

444444
func TestPresumedDead(t *testing.T) {

gossip/gossip/gossip_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ func (da *discoveryAdapter) SendToPeer(peer *discovery.NetworkMember, msg *proto
474474
}
475475

476476
func (da *discoveryAdapter) Ping(peer *discovery.NetworkMember) bool {
477-
return da.c.Probe(peer.Endpoint, peer.PKIid) == nil
477+
return da.c.Probe(&comm.RemotePeer{Endpoint: peer.Endpoint, PKIID: peer.PKIid}) == nil
478478
}
479479

480480
func (da *discoveryAdapter) Accept() <-chan *proto.GossipMessage {

0 commit comments

Comments
 (0)