holepunchto / hyperdht

The DHT powering Hyperswarm
https://docs.holepunch.to
MIT License
323 stars 46 forks source link

Prune the exploration branch with user functions #30

Closed KrishnaPG closed 3 years ago

KrishnaPG commented 4 years ago

When a value or peer is being looked-up, at the application level (e.g. through hyper-discovery etc.) it is required to blacklist / whitelist the discovered peers and referrals.

For example, a node that is constantly giving the wrong reference values (or spoofing keys) should be banned for some time (or maybe permanently) at the app level. Or a node that is constantly trying to propagate mutable values that are failing the sign-verifications repeatedly should be banned for some time (app policy, say).

To facilitate this, if the DHT can expose a function (during the peer discovery phase) to check if a peer is allowed in the lookup process, the application can implement their own blacklist functionality to control which k-buckets can be further queried. This can efficiently prune the wrong exploration branches during the lookup itself.

Before adding a peer/node to the k-bucket, this said user function can be invoked to check if it is allowed to be added to the k-bucket (as per the app-policy).

mafintosh commented 4 years ago

SGTM, wanna add a hook for that in dht-rpc?