mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 03:17:43 +08:00
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:
parent
f4fd369d86
commit
aa95dcbdf2
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user