Skip to content

Commit

Permalink
Replace Probe method input parameter
Browse files Browse the repository at this point in the history
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 <281165273@qq.com>
  • Loading branch information
GrapeBaBa committed Nov 18, 2016
1 parent 97f8584 commit d5b4dbc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gossip/comm/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Comm interface {
Send(msg *proto.GossipMessage, peers ...*RemotePeer)

// Probe probes a remote node and returns nil if its responsive
Probe(endpoint string, pkiID common.PKIidType) error
Probe(peer *RemotePeer) 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
Expand Down
6 changes: 3 additions & 3 deletions gossip/comm/comm_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ func (c *commImpl) isStopping() bool {
return atomic.LoadInt32(&c.stopping) == int32(1)
}

func (c *commImpl) Probe(endpoint string, pkiID common.PKIidType) error {
func (c *commImpl) Probe(peer *RemotePeer) error {
if c.isStopping() {
return fmt.Errorf("Stopping!")
}
c.logger.Debug("Entering, endpoint:", endpoint, "PKIID:", pkiID)
c.logger.Debug("Entering, endpoint:", peer.Endpoint, "PKIID:", peer.PKIID)
var err error

opts := c.opts
if opts == nil {
opts = []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(dialTimeout)}
}
cc, err := grpc.Dial(endpoint, append(opts, grpc.WithBlock())...)
cc, err := grpc.Dial(peer.Endpoint, append(opts, grpc.WithBlock())...)
if err != nil {
c.logger.Debug("Returning", err)
return err
Expand Down
10 changes: 5 additions & 5 deletions gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,16 @@ func TestProbe(t *testing.T) {
defer comm1.Stop()
comm2, _ := newCommInstance(6612, naiveSec)
time.Sleep(time.Duration(1) * time.Second)
assert.NoError(t, comm1.Probe("localhost:6612", []byte("localhost:6612")))
assert.Error(t, comm1.Probe("localhost:9012", []byte("localhost:9012")))
assert.NoError(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:6612", PKIID: []byte("localhost:6612")}))
assert.Error(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:9012", PKIID: []byte("localhost:9012")}))
comm2.Stop()
time.Sleep(time.Second)
assert.Error(t, comm1.Probe("localhost:6612", []byte("localhost:6612")))
assert.Error(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:6612", PKIID: []byte("localhost:6612")}))
comm2, _ = newCommInstance(6612, naiveSec)
defer comm2.Stop()
time.Sleep(time.Duration(1) * time.Second)
assert.NoError(t, comm2.Probe("localhost:6611", []byte("localhost:6611")))
assert.NoError(t, comm1.Probe("localhost:6612", []byte("localhost:6612")))
assert.NoError(t, comm2.Probe(&RemotePeer{Endpoint: "localhost:6611", PKIID: []byte("localhost:6611")}))
assert.NoError(t, comm1.Probe(&RemotePeer{Endpoint: "localhost:6612", PKIID: []byte("localhost:6612")}))
}

func TestPresumedDead(t *testing.T) {
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 @@ -474,7 +474,7 @@ func (da *discoveryAdapter) SendToPeer(peer *discovery.NetworkMember, msg *proto
}

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

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

0 comments on commit d5b4dbc

Please sign in to comment.