I was exploring Kademlia protocol (in Rust) and came across with methods start_providing
, stop_providing
, get_providers
. I’m totally confused what these methods do and what they are for, its use case. I had a look at examples folder, bit didn’t help. Could someone please clarify it?
A provider is someone that claim to has the thing.
Whatever that means.
Different protocols use that in different ways.
With bitswap, a provider is someone that host the block that is the key.
So first a host do a start_provide("Qmfoo")
then
if you do get_providers("Qmfoo")
for example, and it will return you a list of nodes that should host this block, so you can contact them and download it.
Pubsub use this to list nodes interresed in the topic.
The mechanism is the same, first nodes do start_provide(key)
, that adds it to the list of node that are attached to that key, then other people can find nodes that have done start_provide(key)
by doing get_providers(key)
.
And stop_provide(key)
remove you from that list.
@Jorropo Thanks for your answer.
So, assume peers on a network distribute video files (streams). Then say nodes A, B, C (three nodes) start to provide a new film Matrix. They should call start_provide("Matrix")
.
Next, a client joins the network, invokes get_providers("Matrix")
and gets nodes (providers) A,B,C
. Then you again ask one of these nodes, say B, for a record by calling get_record(B_ID)
and get the value corresponding to B_ID
, e.g. this value is a URL for downloading. Right?
If so, why do we need to do two requests: get_providers
and then get_record
? Why not simply get_record("Matrix")
and a node holding the “Matrix” will return the corresponding URL?
Is it live or playback ?
IPFS already do playback very well just because it support seeking using HTTP Ranged Requests.
Because that not how the DHT is meant to be used.
The biggest issue is that what proves you that the returned “URL” (we don’t use URL) is the right one ?
What if someone replaced mattrix with my little poney ?
DHT values require using validators, there are currently two:
PK
which is a public key hash → public key mapping, the validator is canonical, the DHT server just hash the public key and verify it match.ipns
? (I don’t actually remember the ID, but it’s the IPNS one). This one verify that the record is signed by the PeerID that is the key (so it’s aPeerID -> Record signed by the key
mapping).
No current application use both values and providers.
Bitswap for example doesn’t store files in the DHT, the file exchange is an other protocol (bitswap), the DHT is only used to find partners.
No, I give just an example how to use it. Actually, I’m not writing any app using libp2p, just trying to understand Kademlia protocol in Rust.
Got you. Security is the main concern.