generated from MetaMask/metamask-module-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
ocap-enhancementOCAP Kernel enhancementOCAP Kernel enhancement
Description
Problem
Currently only WebSocket/WebRTC transports are configured in connection-factory.ts, limiting Node.js environments to relay-based connections. Direct TCP connections would provide better performance for server-to-server communication.
Expected Behavior
Enable direct TCP connections for remote comms between Node.js instances to bypass relay requirements.
Implementation
Files to Modify
| File | Changes |
|---|---|
platform/connection-factory.ts |
Add TCP transport conditionally for Node.js |
Approach
-
Detect runtime environment
- Check if running in Node.js vs browser
- Use environment detection (e.g.,
typeof process \!== 'undefined')
-
Add TCP transport for Node.js (in
ConnectionFactory.#init())import { tcp } from '@libp2p/tcp'; // In transports array: ...(isNodeJS ? [tcp()] : []),
-
Add TCP listening addresses for Node.js
addresses: { listen: [ '/webrtc', '/p2p-circuit', ...(isNodeJS ? ['/ip4/0.0.0.0/tcp/0'] : []), ], }
-
Update
candidateAddressStrings()- Try direct TCP addresses before relay paths when available
- Prioritize direct connections over relayed ones
Dependencies
@libp2p/tcppackage
Acceptance Criteria
- TCP transport loaded when running in Node.js
- TCP listening address configured in Node.js mode
- Direct TCP connections attempted before relay fallback
- Browser environments continue to work (WebSocket/WebRTC only)
- Unit tests verify transport configuration per environment
- E2E test for direct TCP connection between Node.js instances
Metadata
Metadata
Assignees
Labels
ocap-enhancementOCAP Kernel enhancementOCAP Kernel enhancement