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
Merged
+1,609
−338
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
102ebf4 to
ece964a
Compare
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 tasks
grypez
approved these changes
Jan 26, 2026
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>
ece964a to
24cc1f6
Compare
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
Splits transport responsibilities into focused modules to improve testability and maintainability while preserving behavior.
constants.ts,channel-utils.ts(makeErrorLogger,writeWithTimeout),peer-state-manager.ts,validators.ts(message size/connection limit), andreconnection-lifecycle.tstransport.tsto use these modules: centralized timeouts/limits, peer state tracking, reconnection orchestration, and error logging; removes duplicated inline logicWritten by Cursor Bugbot for commit 24cc1f6. This will update automatically on new commits. Configure here.