If two users upload the same file onto IPFS at the exactly same time from 2 end devices on the same internal network (for example, same office sharing the internet link), are the CIDs of those two files different? If CID is different, then what makes the difference?
1 Answers
The time a file is uploaded to IPFS doesn't effect what the CID turns out to be. As long as the users are uploading the exact same file (ie, the files do not have a single different byte), then the CID that is produced from the two users adding the file will be the same, providing that the users used the same settings when adding that file to IPFS.
You can get different CIDs for the same content however depending on the Multihash that was used, and what CID version you used. For example, if you add a file using CIDv1, and sha2-256, and I added that same file using CIDv0, and sha3-512, the resulting CID will be completely different. Now if I also add that same file using CIDV1 and sha2-256, the produced CID will be the same. Additionally if users add the same content, but use different chunking parameters the resulting CID will also be different.
Now I'll showcase some examples using ipfs add
on the same file "cat.jpg"
ipfs add --cid-version 1 cat.jpg
bafkreicdkwsgwgotjdoc6v6ai34o6y6ukohlxe3aadz4t3uvjitumdoymu
ipfs add --cid-version 0 cat.jpg
QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v
Now you can also try adjusting the multihash:
ipfs add --cid-version 1 --hash sha2-256 cat.jpg
bafkreicdkwsgwgotjdoc6v6ai34o6y6ukohlxe3aadz4t3uvjitumdoymu
ipfs add --cid-version 1 --hash sha3-512 cat.jpg
bafkriqcr4cvbwfxzjp4thqp5n35klda6vpukgae5drqjn6yatg5lj5jnw2phcozcibephttjhob3fkhi3zgklqn2tiemkjrgkntkishw2bl2i
And finally lets try one with a different chunk size
ipfs add --cid-version 1 --chunker=size-1 cat.jpg
bafybeigmitjgwhpx2vgrzp7knbqdu2ju5ytyibfybll7tfb7eqjqujtd3y cat.jpg
ipfs add --cid-version 1 --chunker=size-2 cat.jpg
bafkreicdkwsgwgotjdoc6v6ai34o6y6ukohlxe3aadz4t3uvjitumdoymu cat.jpg

- 341
- 2
- 6
-
2Using `--raw-leaves` (implied by `--nocopy`, iirc) or `--inline` should also change the CID (but it might depend on the file content). – Caesar Dec 05 '19 at 01:41