generated from MetaMask/metamask-module-template
-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(transport): split transport.ts for separation of concerns #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sirtimid
wants to merge
7
commits into
main
Choose a base branch
from
sirtimid/split-transport-concerns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Move transport-related constants to constants.ts: - DEFAULT_MAX_CONCURRENT_CONNECTIONS - DEFAULT_MAX_MESSAGE_SIZE_BYTES - DEFAULT_CLEANUP_INTERVAL_MS - DEFAULT_STALE_PEER_TIMEOUT_MS - DEFAULT_WRITE_TIMEOUT_MS - SCTP_USER_INITIATED_ABORT Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move peer state management to dedicated PeerStateManager class: - Encapsulates peerStates, lastConnectionTime, intentionallyClosed - Provides methods: getState, countActiveConnections, updateConnectionTime - Handles intentional close tracking (mark, check, clear) - Location hints management (addLocationHints) - Stale peer detection and removal Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move the writeWithTimeout utility function to a dedicated channel-utils.ts module for better separation of concerns. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create factory functions for validators: - makeMessageSizeValidator: validates message size limits - makeConnectionLimitChecker: validates connection limits Both use ResourceLimitError with structured data for error handling. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add factory function for creating error logging functions with peer context, reducing boilerplate in transport.ts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move handleConnectionLoss and attemptReconnection to reconnection-lifecycle.ts: - Creates makeReconnectionLifecycle factory function - Uses holder pattern to break circular dependency - Encapsulates reconnection orchestration logic This significantly reduces transport.ts complexity while keeping the reconnection logic cohesive and testable. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for the newly extracted modules: - validators.test.ts: Tests for message size and connection limit validators - channel-utils.test.ts: Tests for error logging and writeWithTimeout - peer-state-manager.test.ts: Tests for PeerStateManager class - reconnection-lifecycle.test.ts: Tests for reconnection lifecycle functions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
102ebf4 to
ece964a
Compare
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
constants.tsfilePeerStateManagerclass for peer state managementwriteWithTimeoutandmakeErrorLoggertochannel-utils.tsmakeMessageSizeValidatorandmakeConnectionLimitCheckertovalidators.tsreconnection-lifecycle.tsThis reduces
transport.tsfrom 784 to 521 lines (~33% reduction) while improving testability and maintainability.Test plan
🤖 Generated with Claude Code
Note
Streamlines transport by extracting core concerns into dedicated, testable modules and updating
transport.tsto compose them.constants.ts,channel-utils.ts(makeErrorLogger,writeWithTimeout),validators.ts(message size/connection limit),peer-state-manager.ts(peer channels/flags/timestamps), andreconnection-lifecycle.ts(orchestrates reconnection)transport.tsto usePeerStateManager, composed reconnection lifecycle, validators, and shared constants; replaces inline logic and mapschannel-utils,validators,peer-state-manager,reconnection-lifecycle) and adjusts defaults viaDEFAULT_*constantstransport.tssize and improving maintainabilityWritten by Cursor Bugbot for commit ece964a. This will update automatically on new commits. Configure here.