I did a test to see what would happen if I try getting a CID that doesn't exist, to see if I could continuously ask every peer in IPFS. It doesn't seem to work. I "connect" to around 10 peers, then it gives up. I'm not sure I'm actually "connecting" though. I'm not really sure what going on. I don't know that I'm actually connecting to any peer and asking them for a CID. I seem to connect to a star server, and see a list a peer, but not sure I ever connect to any of those peers.
Are there other events I should be listening to to debug what's going on? How can I listen to the messages I'm sending to peers?
My assumption from how Bittorrent DHT works is that, if a CID doesn't exist, I should eventually be asking every single peer on the network if they have this CID. Is there only 10 peers in the entire network? Or only 10 peers on that star server? Is there no star server discovery? How do I find a "busy" star server?
<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>
<script>
(async () => {
window.node = await Ipfs.create()
window.node.libp2p.on('peer:discovery', (peer) => console.log('peer:discovery', peer))
window.node.libp2p.on('peer:connect', peerInfo => console.log('peer:connect', peerInfo))
window.node.libp2p.on('peer:disconnect', peerInfo => console.log('peer:disconnect', peerInfo))
window.node.libp2p.peerStore.on('peer', (peerId) => console.log('peer', peerId))
window.node.libp2p.peerStore.on('change:multiaddrs', ({ peerId, multiaddrs}) => {
const addresses = []
for (const multiaddr of multiaddrs) {
addresses.push(multiaddr.buffer.toString())
}
console.log('change:multiaddrs', {peerId, multiaddrs, addresses})
})
window.node.libp2p.peerStore.on('change:protocols', ({ peerId, protocols}) => console.log('change:protocols', {peerId, protocols}))
window.node.libp2p.on('error', (err) => console.log('error', err))
window.node.libp2p.connectionManager.on('peer:connect', (connection) => {
console.log('connectionManager:peer:connect', {connection, remoteAddr: connection.remoteAddr.buffer.toString()})
})
window.node.libp2p.connectionManager.on('peer:disconnect', (connection) => console.log('connectionManager:peer:disconnect', connection))
// fake CID does not exist
results = window.node.get("QmZbj5ruYneZb8FuR9wnLuJCpCXMQudhSdWhdhp5U1oPWJ")
for await (res of results) {
for await (content of res.content) {
window.content = content
console.log(content.toString())
}
}
})()
</script>