IPFS百问:仓库的PeerID与ipfs链上存储的文件有何关系?丢失PeerID后如何恢复文件?
问题:
仓库的PeerID与ipfs链上存储的文件有何关系?
丢失PeerID后如何恢复文件?
推导结论
结论1:ipfs将文件存储在~/.ipfs/block文件中
结论2:ipfs将文件存储在block目录,且与config中的ID和Key无关
定期备份好block目录,即为备份ipfs
结论3:存储文件本身的Hash值和目录的CID最重要,不会因为PeerID变化而变化
引申问题(文件安全性)
问题1:ipfs daemon 过程中是否可篡改config和block?答案:可以篡改
运行时覆盖config文件,无法访问,再覆盖block目录,即可访问test
运行时覆盖block文件,即可访问test
问题2:该结论会导致本仓库的Block文件被任意权限访问、篡改,是否有办法给文件加密绑定唯一的PeerID?
待下一篇文章,进行测试推导结论。
测试过程
1.存储一个test文件在当前仓库
获得目录Hash:Qme7aKg1QbsGgwKWJqqobUUa5iWLb4ihnvqx7RDjTqyfEC
获得文件Hash:added QmQiNx6otNyjowGrSYDRD4bw4sShX2SqnTf1L5r1USps6e test
echo 666 > test
ipfs add test
ipfs add test -w
2.通过文件、目录,分别获取文件内容
ipfs ls /ipfs/Qme7aKg1QbsGgwKWJqqobUUa5iWLb4ihnvqx7RDjTqyfEC
ipfs cat QmQiNx6otNyjowGrSYDRD4bw4sShX2SqnTf1L5r1USps6e
3.查看记录上次初始化ID与Key
可以进入文件夹~/.ipfs/config直接查看,通过命令ipfs config show看不到Identity信息。
js { "Identity": { "PeerID": "QmNp61tANNHRmtQ73ajrS94CxPYPBHwNEm7FbuhaybugUv", "PrivKey": "CAASqAkwggSkAgEAAoIBAQCn+GsqaaMJVpNQImidVDueutwnmPwiyEwbr5lMQnshRAMCF9JhsmLwowd4diiq1dwa3MB+kgUkE7LsxQjT12aTRxxhn9TJU7nrfH9bu6lRREKOw5bAa18vpM5EJAv1Wazqkiw6TLHygPnwWO0eYBMy0krX9O/O54tk2QVv/qNF70EIah4crrjV7Z74um+NFg8ODxkOUx+9kSU/uLtw83MV6ujSs5ozqfGK8KDStVzYZbvIgCJ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z1lbeD4hgiAA+brLEzj4Q8GbgmFFXanBoQclyxJO286VbTc3Ozx9IdzCRMrj45WPKmDiaNQQ63wDOmxYjGuSHOdu/ibmuARwQKBgEiCMqjvqxS6hw11a+EBQHctc9tKb2wkpTwtFnTQtlWr32613U1s20RHPbZj/z7p73sxXwqW7mJRaV1QsRnJbUxICKUBmREZYv7Mb2TOK8WoahOgRsMw1/0FSFibNyWEs5ySglTt/ZySOTe6Xz7/ghextWZ6OwPNgA8/s+TqOm1u" } }
4.备份并删除现有.ipfs/目录,重新执行ipfs init,再启动ipfs daemon
PeerID,变化了
readme文件的目录Hash还是同一个
# PS D:\workspace\ipfs\nova.ipfs> ipfs init # initializing IPFS node at C:\Users\ipfsapp\.ipfs # generating 2048-bit RSA keypair...done # peer identity: QmUD5RRDiZLWzYu3FsTdFAhFpDeHJViPZonRFFV2KfNgm6 # to get started, enter: ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
5.再次获取刚才存储过的test文件,已经无法获取
ipfs ls /ipfs/Qme7aKg1QbsGgwKWJqqobUUa5iWLb4ihnvqx7RDjTqyfEC ##==> Error: Post http://127.0.0.1:5001/api/v0/ls?arg=%2Fipfs%2FQme7aKg1QbsGgwKWJqqobUUa5iWLb4ihnvqx7RDjTqyfEC&encoding=json&resolve-type=true&size=true&stream-channels=true: context canceled ipfs cat QmQiNx6otNyjowGrSYDRD4bw4sShX2SqnTf1L5r1USps6e ##==> 无响应
6.尝试将Identity信息恢复,再尝试获取test文件【失败】
进入文件夹~/.ipfs/config直接修改
依然无法访问,无响应
7.尝试恢复备份的.ipfs文件,再次获取test文件【成功】
- 点赞
- 收藏
- 关注作者
评论(0)