Add PartialMessagesHandler API and GroupState container (step 2)#461
Draft
lucassaldanha wants to merge 6 commits into
Draft
Add PartialMessagesHandler API and GroupState container (step 2)#461lucassaldanha wants to merge 6 commits into
lucassaldanha wants to merge 6 commits into
Conversation
Captures the MVP scope, jvm-libp2p/client responsibility boundary, client-facing API, routing semantics, per-group lifecycle and DoS caps, and the implementation plan for the gossipsub partial-messages extension. Lands ahead of implementation so sub-issues of libp2p#435 can reference a stable design anchor.
Step 1 of the partial-messages extension: plumb SubOpts.requestsPartial / SubOpts.supportsSendingPartial through subscribe announcements in both directions, and track the per-peer-per-topic receive state. - AbstractRouter parses the flags with the spec-mandated coercion (supportsSendingPartial := requestsPartial || supportsSendingPartial) and zeroes them on subscribe=false. - New enqueueSubscribe hook unifies outbound subscribe enqueueing so GossipRouter can attach per-topic flags in a single override. - GossipRouter exposes setTopicPartialFlags(topic, ...) to configure flags advertised for a locally-subscribed topic, and stores inbound flags in a new PartialSubscriptionState (plain HashMap on the pubsub event loop). State is cleaned on peer disconnect, topic unsubscribe, and per-peer unsubscribe. - Outbound unsubscribe MUST NOT carry partial flags; enforced at the SubscriptionPart wire-build site. No routing behaviour changes yet. See docs/partial-messages.md §4.5, §5, §6.1 for context.
…t addSubscription overload
- `PartialSubscriptionWireTest`: route reads of `partialSubscriptionState`
through `submitOnEventThread { ... }.join()`. The state container is
not thread-safe; direct access from the JUnit thread races the event
loop and can surface as `ConcurrentModificationException` or stale
reads. Two helpers (`peerFlagsOnEventLoop`, `snapshotPartialStateOnEventLoop`)
establish the happens-before barrier.
- `RpcPartsQueue`: remove the 2-arg `addSubscription(topic, status)`
default overload. The remaining 4-arg abstract method is the single
source of truth; `addSubscribe` / `addUnsubscribe` remain the
convenience entry points.
- `PartialSubFlags.coerce(requestsPartial, supportsSendingPartial)`: single source of truth for the spec coercion rule `supportsSendingPartial := requestsPartial || supportsSendingPartial`. Used from `GossipRouter.setTopicPartialFlags` for the outbound side. AbstractRouter keeps the inline expression for the receive side to avoid a reverse layering dependency (pubsub -> gossip); a comment notes the rule is applied on both sides. - `PartialSubscriptionState.setPeerFlags`: document that passing `PartialSubFlags.NONE` (or any equivalent all-false flags) is treated as a removal. Makes the set-sometimes-deletes invariant explicit for readers. - `AbstractRouter.handleMessageSubscriptions`: add Kdoc now that the method is `protected open`. Documents the "call super" contract for overrides (GossipRouter relies on this to keep peersTopics and partialSubscriptionState in sync) and the flag-normalisation precondition.
…ure/partial-messages-support
Introduces the public partial-messages API surface and the internal state management layer required before any routing logic lands: Public API (io.libp2p.pubsub.gossip.partialmessages): - PartialMessagesHandler<PeerState> — onIncomingRpc + onEmitGossip; PartialMessagesPeerFeedback passed per-call (resolves open question from design doc §9) - PublishAction<PeerState> / PublishActionsFn<PeerState> - PartialMessagesPeerFeedback interface + FeedbackKind enum Internal state management: - GroupId — content-equality ByteArray wrapper for use as map key - GroupState<PeerState> — per-(topic,groupId) container with mutable TTL and app-opaque peerStates - PartialGroupStateStore<PeerState> — TTL countdown, GC on ttl≤0 or empty peerStates, DoS caps (255/topic, 8/topic/peer, matching go-libp2p defaults), onPeerDisconnected, onTopicUnsubscribed - PartialMessagesAdapter (internal interface) / PartialMessagesAdapterImpl<PeerState> — erases PeerState at the GossipRouter boundary via a single @Suppress("UNCHECKED_CAST") in the builder Wiring: - GossipRouterBuilder: partialMessagesHandler field; build-time error if PARTIAL_MESSAGES extension enabled without a handler - GossipRouter: internal var partialMessages: PartialMessagesAdapter? No routing changes in this step.
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
Step 2 of the partial-messages implementation (tracking issue #435, design doc).
This PR introduces the public API surface and internal state management layer. No routing changes.
New — public API (
io.libp2p.pubsub.gossip.partialmessages)PartialMessagesHandler<PeerState>—onIncomingRpc+onEmitGossipcallbacks;PartialMessagesPeerFeedbackpassed per-call (resolves open question from design doc §9: context-object-per-callback rather than constructor injection)PublishAction<PeerState>/PublishActionsFn<PeerState>PartialMessagesPeerFeedbackinterface +FeedbackKindenumNew — internal state management
GroupId— content-equalityByteArraywrapper safe asHashMapkeyGroupState<PeerState>— per-(topic, groupId)container with mutable TTL and app-opaquepeerStatesPartialGroupStateStore<PeerState>— TTL countdown + GC (onttl ≤ 0or emptypeerStates), DoS caps (255/topic, 8/topic/peer — matching go-libp2p defaults),onPeerDisconnected,onTopicUnsubscribedPartialMessagesAdapter(internal) /PartialMessagesAdapterImpl<PeerState>— erasesPeerStateat theGossipRouterboundary via a single@Suppress("UNCHECKED_CAST")in the builderWiring
GossipRouterBuilder: newpartialMessagesHandlerfield; build-timeIllegalStateExceptionifPARTIAL_MESSAGESextension is enabled without a handlerGossipRouter:internal var partialMessages: PartialMessagesAdapter?(set post-construction by the builder)Tests
PartialGroupStateStorecovering:GroupIdequality, local/peer group creation, both DoS caps, TTL countdown + GC,resetTtl,onPeerDisconnected,onTopicUnsubscribedGossipExtension.PARTIAL_MESSAGESto supply the now-requiredpartialMessagesHandler(vianopPartialMessagesHandlerinGossipTestsBase)Test plan
PartialGroupStateStoreTest— 21 tests, all passspotlessCheck+detekt— clean