diff --git a/gossip/comm/comm.go b/gossip/comm/comm.go index d69eac19345..25a63784ec8 100644 --- a/gossip/comm/comm.go +++ b/gossip/comm/comm.go @@ -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 diff --git a/gossip/comm/comm_impl.go b/gossip/comm/comm_impl.go index f1508d12d03..5a0222b4bae 100644 --- a/gossip/comm/comm_impl.go +++ b/gossip/comm/comm_impl.go @@ -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 diff --git a/gossip/comm/comm_test.go b/gossip/comm/comm_test.go index 284d239e314..e78a97c6710 100644 --- a/gossip/comm/comm_test.go +++ b/gossip/comm/comm_test.go @@ -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) { diff --git a/gossip/gossip/gossip_impl.go b/gossip/gossip/gossip_impl.go index 3b8e568b62e..a0e658f0e4d 100644 --- a/gossip/gossip/gossip_impl.go +++ b/gossip/gossip/gossip_impl.go @@ -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 {