How can i check the file is not in IPFS quickly?

I am impressed by the concepts and resolutions of IPFS. And now i have two questions:

  1. It’s a good way to use ipfs dht findprovs <key> to find the providers by key-hash. But when i use a fake key-hash to exec this command, it’ll take a very very long time to query. Is there any better ways to solve the problem?
  2. Why the API /api/v0/dht/findprovs returns a lot of response body like
    while the command ipfs dht findprovs just return peer-ID that i actually care?

Thank you!

It’s a good way to use ipfs dht findprovs to find the providers by key-hash. But when i use a fake key-hash to exec this command, it’ll take a very very long time to query. Is there any better ways to solve the problem?

Not really, non-existence is actually impossible; we just give up after we’re pretty sure nobody has the file (nobody we can contact, anyways). If you’re using linux, you can use the timeout command to cancel the request after a some period of time if it doesn’t complete.

In case this is an X-Y problem, what are you actually trying to accomplish?

Why the API /api/v0/dht/findprovs returns a lot of response body like…

So applications can show some progress information and learn about the actual IP addresses of the providing peers. That’s basically a full trace of the query (who we’re asking and what they’re telling us). If you want the same output as you get on the command line, add ?encoding=text to the end of that command.

Thanks very much for replying!
I just wanna check whether the resource has been added to IPFS or not, quickly.
Do we have a better way to accomplish it?

It’s the case like CDN. The responding time is the most important thing, and i need to decide whether to fetch from IPFS or fetch from source site for a short time.

It’s the case like CDN. The responding time is the most important thing, and i need to decide whether to fetch from IPFS or fetch from source site for a short time.

In that case, I’d just set a lower timeout. Also, if you end up downloading the file from the source site, I’d add it to IPFS (and verify the hash). You can also try racing. That is, ask both IPFS and the website (but maybe give IPFS 75ms to return a response before asking the website). If the website is under heavy load, it can start rejecting requests and you can wait for IPFS to return the file.

Do we have a better way to accomplish it?

Set a lower timeout, that’s the only way to do this. As we make content routing faster and faster (we’re working on it) you’ll be able to lower that timeout more and more.

However, we’ll likely keep our timeouts where they are. In most cases, you want to keep trying until you find something and there’s no way to be completely sure that nobody has the content in question (there’s no way to know if you’ve asked every node in the network).

That’s very clear. Thanks very much!!

On macOS you can install the GNU Core Utilities with Homebrew: brew install coreutils

They will put gtimeout into /usr/local/bin

There are also scripted ways to kill a process after a specified time; see e.g. here: https://superuser.com/a/153762/628346

That’s good. Thank you~