ping: switch to the ping service enabled in the libp2p constructor
We now configure the ping service in go-libp2p by default. Instead of creating a new (duplicate) ping service, we can now just (a) rely on this to handle incoming pings and (b) use the "Ping" function to ping peers. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Oct 30, 2018 at 06:55 UTC
cc0d6d73383b43b46dd16bd131224518f6b7de75
2 files changed
+3
-7
core/commands/ping.go
+2
-1
@@ -14,6 +14,7 @@ import (
14
ma "gx/ipfs/QmT4U94DnD8FRfqr21obWY32HLM5VExccPKMjQHofeYqr9/go-multiaddr"
15
"gx/ipfs/QmTRhk7cgjUf2gfQ3p2M9KPECNZEW9XUrmHcFCgog4cPgB/go-libp2p-peer"
16
pstore "gx/ipfs/QmTTJcDL3gsnGDALjh2fDGg1onGRUdVgNL2hU2WEZcVrMX/go-libp2p-peerstore"
17
+ ping "gx/ipfs/QmUDTcnDp2WssbmiDLC6aYurUeyt7QeRakHUQMxA2mZ5iB/go-libp2p/p2p/protocol/ping"
18
iaddr "gx/ipfs/QmZc5PLgxW61uTPG24TroxHDF6xzgbhZZQf5i53ciQC47Y/go-ipfs-addr"
19
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
20
)
@@ -104,7 +105,7 @@ trip latency information.
105
106
ctx, cancel := context.WithTimeout(req.Context, kPingTimeout*time.Duration(numPings))
107
defer cancel()
107
- pings, err := n.Ping.Ping(ctx, pid)
108
+ pings, err := ping.Ping(ctx, n.PeerHost, pid)
109
if err != nil {
110
return res.Emit(&PingResult{
111
Success: false,
core/core.go
+1
-6
@@ -52,7 +52,6 @@ import (
52
p2pbhost "gx/ipfs/QmUDTcnDp2WssbmiDLC6aYurUeyt7QeRakHUQMxA2mZ5iB/go-libp2p/p2p/host/basic"
53
rhost "gx/ipfs/QmUDTcnDp2WssbmiDLC6aYurUeyt7QeRakHUQMxA2mZ5iB/go-libp2p/p2p/host/routed"
54
identify "gx/ipfs/QmUDTcnDp2WssbmiDLC6aYurUeyt7QeRakHUQMxA2mZ5iB/go-libp2p/p2p/protocol/identify"
55
- ping "gx/ipfs/QmUDTcnDp2WssbmiDLC6aYurUeyt7QeRakHUQMxA2mZ5iB/go-libp2p/p2p/protocol/ping"
55
psrouter "gx/ipfs/QmUhJjacEW7gDGsvxzn8NqyfCWRksgTtYeaGvQmgYvrmWH/go-libp2p-pubsub-router"
56
quic "gx/ipfs/QmVX7uSFmFLZRFsN9QNPDJf7Pmhuv4GdedrKYrt2xXm5ag/go-libp2p-quic-transport"
57
circuit "gx/ipfs/QmVYDvJjiKb9iFEyHxx4i1TJSRBLkQhGb5Fc8XpmDuNCEA/go-libp2p-circuit"
@@ -133,8 +132,7 @@ type IpfsNode struct {
132
Routing routing.IpfsRouting // the routing system. recommend ipfs-dht
133
Exchange exchange.Interface // the block exchange + strategy (bitswap)
134
Namesys namesys.NameSystem // the name system, resolves paths to hashes
136
- Ping *ping.PingService
137
- Reprovider *rp.Reprovider // the value reprovider system
135
+ Reprovider *rp.Reprovider // the value reprovider system
136
IpnsRepub *ipnsrp.Republisher
137
138
PubSub *pubsub.PubSub
@@ -464,9 +462,6 @@ func (n *IpfsNode) HandlePeerFound(p pstore.PeerInfo) {
462
// startOnlineServicesWithHost is the set of services which need to be
463
// initialized with the host and _before_ we start listening.
464
func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost.Host, routingOption RoutingOption, enablePubsub bool, enableIpnsps bool) error {
467
- // setup diagnostics service
468
- n.Ping = ping.NewPingService(host)
469
-
465
if enablePubsub || enableIpnsps {
466
cfg, err := n.Repo.Config()
467
if err != nil {