Phase C2: neighbor discovery (Handshaker, NeighborFinder, NeighborUpdateManager)#85
Merged
Conversation
…ateManager) Ports the seven neighbor-discovery classes of the content-delivery layer from the TS pin, with all seven TS test files: - HandshakeRpcRemote/HandshakeRpcLocal/Handshaker: stream-part neighbor handshakes with parallel target selection from the four contact views and the interleaving protocol (a full node accepts the requester and hands one existing neighbor over). The TS detached interleave continuation becomes a time-bounded GuardedAsyncScope task. - NeighborFinder: repeated doFindNeighbors rounds (two concurrent chains, 250 ms apart) until minCount neighbors or contacts exhausted; INeighborFinder seam for the TS-style test doubles. - NeighborUpdateRpcRemote/RpcLocal/NeighborUpdateManager: periodic neighbor-list exchange with rtt recording (setRtt/getRtt added to ContentDeliveryRpcRemote) and removeMe pruning. - NodeList: public getLast(exclude) added (TS parity; only a static helper existed). - CoroutineHelper: export folly's collectAllTryRange (Promise.allSettled equivalent). - TestUtils: createMockContentDeliveryRpcRemote/createMockHandshakeRpcRemote factories over a transportless communicator whose sends fail fast. Local: trackerless-network unit 43/43 (21 new C2 tests). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the seven neighbor-discovery classes of the content-delivery layer from the TS pin (
src/content-delivery-layer/neighbor-discovery/), with all seven TS test files. Rebased onto current main (over the parallel-session phases C4/C7) with no conflicts.What's ported
HandshakeRpcRemote/HandshakeRpcLocal/Handshaker— stream-part neighbor handshakes: parallel target selection from the four contact views (ring left/right, Kademlia-nearby, random; websocket-node preference when neighborless), up to two handshakes in parallel, and the full interleaving protocol (a full node accepts the requester and hands one existing neighbor over, with the ongoing-interleave accounting that keeps ≥2 neighbors during churn). The TS detached interleave continuation (.then()without await) becomes a time-boundedGuardedAsyncScopetask.NeighborFinder— repeateddoFindNeighborsrounds (two concurrent chains, 250 ms apart) untilminCountneighbors or the contact views are exhausted; self-stops and can be restarted. AnINeighborFinderseam supports the TS-style{ start: jest.fn() }test doubles.NeighborUpdateRpcRemote/NeighborUpdateRpcLocal/NeighborUpdateManager— periodic neighbor-list exchange: learns new contacts from callers, records round-trip times (setRtt/getRttadded toContentDeliveryRpcRemote), prunes withremoveMewhen both sides exceed the target count.NodeListgains the publicgetLast(exclude)(TS parity — only a static helper existed);CoroutineHelperexports folly'scollectAllTryRange(thePromise.allSettledequivalent); TestUtils gains the mock remote factories.A bug this phase found and fixed in its own code
The first version of the mock-remote factory deliberately leaked its transportless communicator (to dodge static-destruction concerns). That leak held a folly KeepAlive on the shared worker pool forever, so the pool's static destructor blocked at process exit — the test binary printed PASSED and then never terminated (stack-sampled:
~CPUThreadPoolExecutor → joinKeepAlive → Baton::tryWaitSlow). Fixed by making it a function-local static object: constructed after the pool, destroyed before it, KeepAlive released in order. Verified: the three affected fixtures and the full suite now exit cleanly. Lesson recorded for future phases.Tests (all ported from the pin)
unit/HandshakeRpcLocal.test.ts(7 tests)HandshakeRpcLocalTestunit/Handshaker.test.tsHandshakerTest(FakeTransport with failing sends instead of simulator — same observable outcome, no timeout waits)unit/NeighborFinder.test.tsNeighborFinderTestunit/NeighborUpdateRpcLocal.test.ts(6 tests)NeighborUpdateRpcLocalTestintegration/HandshakeRpcRemote.test.tsHandshakeRpcRemoteTest(house two-communicator pattern)integration/NeighborUpdateRpcRemote.test.tsNeighborUpdateRpcRemoteTest(same)integration/Handshakes.test.ts(3 tests incl. interleaving)HandshakesTestover real dhtSimulator/SimulatorTransportsResults (local, arm64 mac)
trackerless-network unit 54/54 with clean process exit, streamr-dht unit 181/181, full-tree build green, package and root lint rc=0.
With C2 in, the remaining milestone-C phases are C3 (
ContentDeliveryLayerNode, which composes these classes), C5, C6, and C8.🤖 Generated with Claude Code