which libp2p module do I use to broadcast data to peers in the network e.g blockchain? do I use mdns or kademlia for blockchain?

I am trying to understand lib2p2 Rust by looking at the rust libp2p examples in the rust libp2p github repo and substrate network module as well. My question is, If I am building a peer to peer network such as a blockchain using libp2p.

  1. If I am correct , do I use both kadamlia and mdns for peer discovery ? or I can use only mdns or only kadamlia since both can be used for peer discovery according to the libp2p documentation
  2. If I used kademlia for discovery and routing, does this mean my network will also connect with the ipfs network? I came across information mentioning that ipfs is coupled with the kademlia protocol. how do I use rust libp2p such that the peers in my protocol network (e.g blockhain) only connect with other peers running my own protocol such as a blockchain network? is there a code sample for this ?
  3. What libp2p behavior or module to I use for broadcasting information to other peers in the network ? such as broadcasting blocks as in a blockchain network ? is it gossipsub? I looked into the substrate network crate Cargo.toml but i saw that the gossipsub feature is not enabled

Hello @ykel,

Thanks for your post. This is a technical question best asked in the rust-libp2p technical forum on Github: libp2p/rust-libp2p · Discussions · GitHub

However, I can give you some answers right now:

  1. MDNS uses UDP broadcast packets on your local LAN to discover peers on your local network that speak libp2p. Kademlia is a method for doing peer discovery at global scale but usually requires bootstrap nodes that all new peers talk to initially to join the Kademlia network.

  2. Your network will only connect to the IPFS network if you choose to include peers from the IPFS network either by using the IPFS bootstrap peers or by attempting to connect to IPFS peers you know about. Even then, if you specify your protocols with their own protocol string, you won’t necessarily be “a part of the IPFS network”. You may be talking to peers but your protocol strings won’t match those of IPFS peers so they won’t try to talk to you using their protocols. Nor will they accept connections from your peers advertised as using your blockchain’s protocol.

  3. Gossipsub is a way to broadcast messages to peers based on “topic”. Clients listing for a specific topic receive the associated broadcast messages. Pubsub is a way to broadcast messages to peers that subscribe to messages from a peer.

I hope this helps.

Cheers!