ping: add a useful error message when pinging self

We don't allow dialing self for many (very good) reasons.

fixes #4542

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen 2018-01-04 10:23:00 -08:00
parent f4fd369d86
commit aa95dcbdf2

View File

@ -3,6 +3,7 @@ package commands
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"strings"
@ -26,6 +27,9 @@ type PingResult struct {
Text string
}
// ErrPingSelf is returned when the user attempts to ping themself.
var ErrPingSelf = errors.New("error: can't ping self")
var PingCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Send echo request packets to IPFS hosts.",
@ -84,6 +88,11 @@ trip latency information.
return
}
if peerID == n.Identity {
res.SetError(ErrPingSelf, cmdkit.ErrNormal)
return
}
if addr != nil {
n.Peerstore.AddAddr(peerID, addr, pstore.TempAddrTTL) // temporary
}