diff --git a/core/commands/ping.go b/core/commands/ping.go index 5d48f260a..68dda837f 100644 --- a/core/commands/ping.go +++ b/core/commands/ping.go @@ -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 }