wip: re-architect how we initialize the TUN device #4159
Closed
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.
Currently, the callbacks for initializing and updating the TUN device create a lot of back-and-forth control flow that is hard to follow. This PR presents the cornerstones of a different design that I deem simpler to understand.
The key differences are:
Tunnel
has anupdate_tun
function that allows setting a new TUN device. EssentiallyTun
is now just anAsyncRead + AsyncWrite
so that could be further abstracted. I think that would be good because we end up with less conditional dependencies.on_set_interface_config
means the portal has given us new IPs. We set those IPs on the TUN device in a platform-specific way. For example, for Linux, this means talking tonetlink
, for Android and iOS/MacOS, this means forwarding to the main app.Session
. For Android, we have to wait for the file-descriptor from the first callback.