mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 20:37:53 +08:00
fix: 'ipfs routing findpeer' explicitly fails when searching for self (#9903)
This commit is contained in:
parent
dfd244816a
commit
6eef0b4eef
@ -17,6 +17,7 @@ import (
|
||||
var log = logging.Logger("core/commands")
|
||||
|
||||
var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")
|
||||
var ErrSelfUnsupported = errors.New("finding your own node in the DHT is currently not supported")
|
||||
|
||||
const (
|
||||
RepoDirOption = "repo-dir"
|
||||
|
||||
@ -301,6 +301,10 @@ var findPeerRoutingCmd = &cmds.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
if pid == nd.Identity {
|
||||
return ErrSelfUnsupported
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(req.Context)
|
||||
ctx, events := routing.RegisterForQueryEvents(ctx)
|
||||
|
||||
|
||||
@ -117,7 +117,23 @@ func testRoutingDHT(t *testing.T, enablePubsub bool) {
|
||||
})
|
||||
}
|
||||
|
||||
func testSelfFindDHT(t *testing.T) {
|
||||
t.Run("ipfs routing findpeer fails for self", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
nodes := harness.NewT(t).NewNodes(1).Init()
|
||||
nodes.ForEachPar(func(node *harness.Node) {
|
||||
node.IPFS("config", "Routing.Type", "dht")
|
||||
})
|
||||
|
||||
nodes.StartDaemons()
|
||||
|
||||
res := nodes[0].RunIPFS("dht", "findpeer", nodes[0].PeerID().String())
|
||||
assert.Equal(t, 1, res.ExitCode())
|
||||
})
|
||||
}
|
||||
|
||||
func TestRoutingDHT(t *testing.T) {
|
||||
testRoutingDHT(t, false)
|
||||
testRoutingDHT(t, true)
|
||||
testSelfFindDHT(t)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user