Skip to content

feat: auto-relay for web port (fixes #15)#18

Merged
monteslu merged 3 commits intomasterfrom
feat/auto-relay-web-port
Feb 11, 2026
Merged

feat: auto-relay for web port (fixes #15)#18
monteslu merged 3 commits intomasterfrom
feat/auto-relay-web-port

Conversation

@monteslu
Copy link
Copy Markdown
Owner

@monteslu monteslu commented Feb 6, 2026

Summary

When hsync forwards web traffic to a local port, RTC clients can now automatically relay to that port without explicit relay configuration.

Fixes #15

Changes

  • Add setWebPort() to socket-relays.js
  • Auto-create relay in connectSocket() if port matches web port
  • Call setWebPort() in connection.js when port is configured
  • Add 5 new tests for auto-relay functionality

How it works

Before: Client A forwarding web traffic to port 3000 required explicit relay config for RTC clients to connect.

After:

  • Client A: hsync -p 3000 (forwards web traffic to localhost:3000)
  • Client B: Can now connect to port 3000 via RTC automatically - no extra config needed on A

Testing

  • 104 tests pass (99 original + 5 new)
  • New tests cover: setWebPort, auto-relay creation, non-web-port rejection, explicit relay preference

@monteslu
Copy link
Copy Markdown
Owner Author

monteslu commented Feb 6, 2026

Code Review - Radagast 🧙‍♂️

Overall: Clean implementation, looks good to merge!

What I like:

  • Simple, focused change that solves a real UX friction
  • Proper precedence: explicit relay configs still override auto-relay
  • Good debug logging for troubleshooting
  • Solid test coverage (5 new tests covering happy path and edge cases)

Implementation notes:

  • setWebPort() stores the port in closure-scoped webPort variable ✓
  • Auto-relay only triggers if no explicit relay exists ✓
  • Auto-created relay targets localhost which is the right default ✓

Minor observation:

The auto-relay always creates with targetHost: "localhost" - this seems correct for the web port use case, but worth documenting that behavior.

Verdict: Ship it! 🚀

Copy link
Copy Markdown
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Review ✅ APPROVE

Overview

This PR implements auto-relay functionality for web ports, addressing issue #15. The implementation is secure and well-designed.

Security Analysis

✅ Secure Defaults:

  • Auto-relay defaults to localhost as target (prevents external exposure)
  • Explicit relays take precedence over auto-relay (correct security hierarchy)
  • Port validation handled properly

✅ Access Control:

  • Auto-relay only triggers when webPort is explicitly set
  • No unauthorized relay creation
  • Proper error handling maintains security boundaries

✅ Code Quality:

  • Comprehensive test coverage including edge cases
  • Clear separation of auto vs explicit relay logic
  • Good error messages for debugging

Edge Cases Reviewed

✅ Auto-relay vs explicit relay precedence
✅ Invalid port handling
✅ Multiple relay scenarios
✅ Port collision edge cases

Recommendation

APPROVE - This is a solid security-conscious implementation that properly addresses the auto-relay requirement while maintaining security boundaries.

— Luthien 🌙

Copy link
Copy Markdown
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean feature — auto-creates relay when port matches web port. Good use of the existing cachedRelays pattern. Tests cover the happy path and edge cases.

🌙

@monteslu monteslu merged commit dd681eb into master Feb 11, 2026
2 checks passed
@monteslu monteslu deleted the feat/auto-relay-web-port branch February 11, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

automatically relay the local HTTP port

2 participants