Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ping API a bit by returning failure in case of only failure #2813

Merged
merged 1 commit into from
Jun 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions core/commands/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func pingPeer(ctx context.Context, n *core.IpfsNode, pid peer.ID, numPings int)
if len(n.Peerstore.Addrs(pid)) == 0 {
// Make sure we can find the node in question
outChan <- &PingResult{
Text: fmt.Sprintf("Looking up peer %s", pid.Pretty()),
Text: fmt.Sprintf("Looking up peer %s", pid.Pretty()),
Success: true,
}

ctx, cancel := context.WithTimeout(ctx, kPingTimeout)
Expand All @@ -131,14 +132,20 @@ func pingPeer(ctx context.Context, n *core.IpfsNode, pid peer.ID, numPings int)
n.Peerstore.AddAddrs(p.ID, p.Addrs, pstore.TempAddrTTL)
}

outChan <- &PingResult{Text: fmt.Sprintf("PING %s.", pid.Pretty())}
outChan <- &PingResult{
Text: fmt.Sprintf("PING %s.", pid.Pretty()),
Success: true,
}

ctx, cancel := context.WithTimeout(ctx, kPingTimeout*time.Duration(numPings))
defer cancel()
pings, err := n.Ping.Ping(ctx, pid)
if err != nil {
log.Debugf("Ping error: %s", err)
outChan <- &PingResult{Text: fmt.Sprintf("Ping error: %s", err)}
outChan <- &PingResult{
Success: false,
Text: fmt.Sprintf("Ping error: %s", err),
}
return
}

Expand All @@ -165,7 +172,8 @@ func pingPeer(ctx context.Context, n *core.IpfsNode, pid peer.ID, numPings int)
}
averagems := total.Seconds() * 1000 / float64(numPings)
outChan <- &PingResult{
Text: fmt.Sprintf("Average latency: %.2fms", averagems),
Success: true,
Text: fmt.Sprintf("Average latency: %.2fms", averagems),
}
}()
return outChan
Expand Down