Skip to content
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

Wrap channel in an asyncio.Transport to eliminate loop back connection #303

Draft
wants to merge 80 commits into
base: main
Choose a base branch
from

Conversation

bdraco
Copy link
Contributor

@bdraco bdraco commented Oct 24, 2024

Breaking change

SniTunClientAioHttp.start() no longer uses endpoint_connection_error_callback. Passing it will now generate a DeprecationWarning that it will be removed in a future release. This failure condition is no longer possible since there is no longer a loop back connection, and the protocol is connected directly to the aiohttp RequestHandler (server).

hass_nabucasa currently uses this callback in https://github.com/NabuCasa/hass-nabucasa/blob/cb14a2cad747b882f407e72e69f539f5d8fa20bb/hass_nabucasa/remote.py#L321

Its unclear if hass_nabucasa can simply remove passing the callback or another change will be needed.

Technically Breaking change

The signature of snitun.client.connector.Connector has changed since it no longer connects to loop-back. Instead of end_host and end_port it takes the ssl_context and protocol_factory (an asyncio.Protocol factory, in Home Assistant's case this is an aiohttp RequestHandler)

This doesn't appear to be used externally as SniTunClientAioHttp is the entry point that creates these.

Deployment considerations

The new ChannelTransport is hard coded to pass the remote IP as 127.0.0.1 for compatibility with the currently deployed Cloud servers.

https://github.com/NabuCasa/snitun/pull/303/files#diff-962be76744351102b2907e3aab99d5a45bc091cac1cc65f53f0fe2db9033c47fR30 should be adjusted to True when channel.ip_address is the actual remote IP address of the client that connected to the cloud server and not the IP Address of the internal forwarder.

Proposed change

The concept is that the SelectorTransport is replaced with the new ChannelTransport that is a wrapper around the channel so we don't need to connect back to localhost since we can create the request handler, connect up the transport and protocol and start_tls

Since aiohttp gets the ip address from the transport it can be set to whatever is desired in a future up. See Deployment considerations

Testing TODO:

@bdraco bdraco changed the title Direct connect PoC Wrap channel in an asyncio.Transport to eliminate loop back connection PoC Oct 24, 2024
@bdraco

This comment was marked as outdated.

@bdraco
Copy link
Contributor Author

bdraco commented Feb 8, 2025

Last step is to replace all the connector tests with ones that test connecting to the handler

@bdraco bdraco changed the title Wrap channel in an asyncio.Transport to eliminate loop back connection PoC Wrap channel in an asyncio.Transport to eliminate loop back connection Feb 8, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@8315a3f). Learn more about missing BASE report.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #303   +/-   ##
=======================================
  Coverage        ?   84.59%           
=======================================
  Files           ?       20           
  Lines           ?     1298           
  Branches        ?      127           
=======================================
  Hits            ?     1098           
  Misses          ?      168           
  Partials        ?       32           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco bdraco force-pushed the direct_connect_v2 branch 3 times, most recently from 51befd7 to 8757bea Compare February 8, 2025 20:40
@bdraco bdraco force-pushed the direct_connect_v2 branch from 27a149b to 04993e8 Compare February 8, 2025 21:03
@bdraco bdraco force-pushed the direct_connect_v2 branch 4 times, most recently from 31128d2 to ad98e36 Compare February 8, 2025 22:42
@bdraco bdraco marked this pull request as ready for review February 8, 2025 22:42
@bdraco bdraco force-pushed the direct_connect_v2 branch 2 times, most recently from 8bcc0f4 to ba155d2 Compare February 8, 2025 23:30
@bdraco bdraco marked this pull request as ready for review February 13, 2025 21:23
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.

2 participants