From aa95dcbdf2eb1943da09dc731af0823ffab97d33 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 4 Jan 2018 10:23:00 -0800 Subject: [PATCH] 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 --- core/commands/ping.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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 }