简体   繁体   中英

Where exactly in IPFS.create() or IPFS.add() does my node propagate an updated distributed hash table upon adding a file?

Original question: Does the IPFS.add() method automatically update my local DHT and propagate it to other peers?

In order to test whether the IPFS.add() method alone allows other peers to download content from a my pc, I ran this script on my windows pc:

import * as IPFS from "ipfs";

const node = await IPFS.create();
var file = await node.add("Shiiiiiiiiiiitttt");

and ran this code on my macbook to fetch the file:

import * as IPFS from "ipfs";
const node = await IPFS.create();
//fetching Shiiiiiiiiiiitttt
const stream = node.cat("QmetK5x9nLUG5jDwp7Un25n47exuNjDZ3cKvnKfC6Hebmi")
 
const decoder = new TextDecoder()
let data = ''
 
for await (const chunk of stream) {
 // chunks of data are returned as a Uint8Array, convert it back to a string
 data += decoder.decode(chunk, { stream: true })
 console.log("decoding")
}
 
//At the end, as long as ipfs is running in owner node, there was no need for ipfs.dht.provide method call
 
console.log(data)

What I found out through this test was that as long as I keep running jsipfs daemon or the script itself on the windows pc that adds a file or text, I can retrieve it from other devices using IPFS.cat(). This confuses me deeply, since IPFS also has a separate method, IPFS.dht.provide(), and my current understanding of IPFS dictates that an updated dht propagation to other peers is necessary to enable them to fetch files. However, from my test, I can logically conclude that there has to be some method within IPFS.add() that propagates an updated distributed hash table or at least a similar alternative to other peers so that they know I have the file. I'm having a very difficult time finding these source methods for automatic dht propagation upon adding a file and would appreciate any help on finding the said methods or an under-the-hood explanation of what happens during IPFS.add().

Check out the ipfs docks https://docs.ipfs.tech/concepts/ , far more important than you first think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM