Skip to content

dht: enforce query timeouts and implement periodic per-bucket bootstrap refresh #256

Description

@adust09

Spec

specs/kad-dht/README.md, Bootstrap process:

  • run once on startup and periodically (default 10 minutes);
  • perform a self lookup;
  • generate and look up a random peer ID for every non-empty k-bucket;
  • abort each run at QueryTimeout (default 10 seconds).

Implementations may vary in algorithm, but must keep the table healthy and make progress despite unresponsive peers.

Current state

DHT.Lookup.bootstrap is a one-shot function that:

  • has no timeout;
  • is not scheduled at startup or periodically;
  • refreshes at most ten existing peer IDs instead of one random target per non-empty bucket.

The test named bootstrap respects timeout (completes even with slow peers) uses an immediately responding mock and contains no delay or timeout assertion, so it does not exercise the claimed behavior.

Iterative lookup requests also have no query-level deadline, allowing an unresponsive dhtSendRequest to stall the lookup indefinitely.

Scope

  • Add a configurable query/bootstrap timeout with a 10-second default.
  • Cancel outstanding lookup work when the deadline expires.
  • Refresh every non-empty bucket using a random target in that bucket's key range.
  • Retain the self lookup.
  • Provide a managed periodic bootstrap loop with configurable interval and clean cancellation on shutdown.
  • Decide and document whether startup bootstrap is explicit or part of DHT registration/construction.
  • Replace the misleading timeout test with a genuinely blocking mock.

Acceptance tests

  • A permanently blocked peer cannot hold bootstrap past the configured deadline.
  • Outstanding async queries are cancelled on timeout.
  • Every non-empty bucket receives an appropriate refresh lookup.
  • Periodic refresh runs more than once under a short test interval.
  • Shutdown terminates the bootstrap worker without leaking threads.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions