Using IPFS DHT for custom key/value - ipfs

I would like to know if I can use the DHT of IPFS as a kind of registry to find information related to a CID.
Example:
I have merkle trees that consist of roughly 2000-5000 file hashes. Those merkle trees (XML Format) should be put on IPFS where i get a CID back. Now I want to be able to find the CID which contains the corresponding merkle tree only by the file hash.
So I would get the CID of the merkle tree, if I look for my file hash on IPFS.
The entry for the DHT would look something like this: {key,value}:{file hash, IPFS-CID}.
I know that I could build my own hash table where I map the file hashes to a CID. My first thoughts were to store this hash table also in IPFS and let a DNS point to it, so its the single source of truth and could easily be found. But as I want to keep everything as decentralized as possible, my thoughts where that I could maybe use the DHT of IPFS to do something similar. Is there a way of doing this or something closely related?

Related

Possible to determine if a file is present on IPFS by calculating its hash?

If I have a file, and I want to see if it is present on IPFS, is there some obvious way to compute its hash then see if a file is returned from the a url including that hash?
You can check out how a CID is created from a file here or check out libraries for your languages such as this one for Rust to encode your file into a CID and compare it with those retrieved from IPFS.
Note that CID is not the same as a file's hash. CID is derived from a process called multihash and encoded in base-58 encoding. If you have a hash of a file (like sha-256 or keccak256) that isn't CID and you don't know the file, then it is not possible to retrieve the file from IPFS since the hash or checksum is only useful for validating the file, but not possible to retrieve the file content.
See also: CID decoding algorithm

Upload files under same CID to IPFS

I'm looking to create an NFT project with 10k pieces, each piece should be made available as soon as the token was minted, therefore I want to call upload the JSON object to IPFS under the same hash as I've seen in other projects.
This means that when the item was minted a new file will be uploaded to:
ipfs://<CID>/1
the seconds minting will create token 2 and then a new file will be uploaded to
ipfs://<CID>/2
How is it possible to be done with ipfs or pinata api?
Wrap it into a .car Web 3 Storage How to Work With Car Files
Update: I just reread the last part of the question.
I found this here (https://docs.pinata.cloud/api-pinning/pin-file) :
wrapWithDirectory - Wrap your content inside of a directory when adding to IPFS. This allows users to retrieve content via a filename instead of just a hash. For a more detailed explanation, see this informative blogpost. Valid options are: true or false
I'm pretty sure that you can do this with ipfs add /PATH/TO/CONTENT/* -w
I'm still exploring with IPFS, but this sounds like what you are looking for.

How to create an ipfs CID with paths?

How do I upload data to IPFS such that they are all accessible via a base CID? For example the CID ipfs://bafybeihpjhkeuiq3k6nqa3fkgeigeri7iebtrsuyuey5y6vy36n345xmbi on its own does not load any content but suffixed with a certain sub-path like 0 or 23 it will load a distinct document: ipfs://bafybeihpjhkeuiq3k6nqa3fkgeigeri7iebtrsuyuey5y6vy36n345xmbi/23. Also I'd be curious to learn how this works. I'm sorry if I'm getting some of the terminology wrong I'm still quite new to IPFS.
Thanks again!
IPFS allows the uploading of directories. The root CID without a path is how you address the entire folder and the path just fetches some sub-document. These have their own CID but can be also indirectly be accessed via parent CID and a connected path.

IPFS: Symbolic links in MFS

Is there a symlink equivalent for IPFS's Mutable File System? For example, if I have a file:
/source/file.txt
and I copy it another folder:
ipfs files cp /source/file.txt /reference/file.txt
the two files will refer to the same object. If I make a change to /source/file.txt the copy in /reference/file.txt will still point to the old version. Is there a good way to make it point to the current version of the file in /source/?
I could keep track of all the copies and update them whenever I change the original, but that doesn't sound fun. I could also store the string "/source/file.txt" in /reference/file.txt and manually dereference each time I want to access the file. Better, but still cumbersome. Are there any other options?
For the time being, there is no support for symnlinks in MFS: you need to track and update them manually in userland. Current MFS implementation uses immutable identifiers (CID) and each directory's CID is based on hashes of its children, so storing string in a file sounds like the most optimal way, as it does not trigger DAG recalculation every time you update the target file.

Is there any easy way to get folderID based on a given path?

Box api is implemented to be RESTful. and most supported methods are based on ids, folder_id or file_id.
As a very beginning start point, a root folder id, 0, stands for the root directory /All Files/.
from there (fold_id = 0), I can loop through all sub folders and find folder id for certain target folder.
or I can send search request to "https://api.box.com/2.0/search?query=target_folder_name", and process the response to locate target folder.
The former approach may need multiple list-folder-item requests, and the latter approach might be slow because the search is not just for folder/file name but also for other attributes of folder/file and even file content.
I am wondering if there is an easy way to find folder id for certain folder with a given path, such as "/All Files/MyFolder_A/Project_11".
Thank you very much for any help.
To the best of my knowledge, walking the folder tree (as you've suggested) is still the fastest way to get the ID of a particular file/folder. (See also this question: Get file ID of a given path.)