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

Enable activating and deactivating the 'Firefox VPN' #61

Merged
merged 10 commits into from
Sep 30, 2024

Conversation

lesleyjanenorton
Copy link
Member

This PR...

  • Adds a new StateVPNOnPartial state to the controller for when the VPN client is also in StateOnPartial
  • Adds a new ExtensionController to manage extension states (on, off, idle, connecting - no UI for connecting in this PR as we'll need some guidance from UX)
  • Updates toolbarIcon, tabHandler, and the UI to use extensionController instead of VPNController (where sensible).
  • Updates the ProxyHandler
    • Moves resolving the site contexts list into proxyMap into ProxyHandler, since that is where other siteContexts things are happening.
    • Subscribes to the VPN controller for loophole, server, and exit server location data to update the proxyMap.
    • Processes and exposes the localproxy and exit location data into arrays of proxyInfo objects as well as the proxyMap.
  • Updates the RequestHandler:
    • Subscribes to ProxyHandler for updated localProxy, exitLocation, and proxyMap
    • Subscribes to extensionController state and uses extensionState properties bypassTunnel and useExitRelays to conditionally proxy all Firefox traffic, instead of only site specific traffic.

If we're generally good with the structure of these changes I will start unbreaking and adding tests.

@lesleyjanenorton lesleyjanenorton marked this pull request as ready for review September 23, 2024 14:45
Copy link
Collaborator

@strseb strseb left a comment

Choose a reason for hiding this comment

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

r+wc

src/background/proxyHandler/proxyHandler.js Outdated Show resolved Hide resolved
src/background/proxyHandler/proxyHandler.js Show resolved Hide resolved
src/background/proxyHandler/proxyHandler.js Outdated Show resolved Hide resolved
}
}

updateProxyMap(newProxyMap, servers) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this needs type info please 👉 👈

this.#mProxyMap.value = result;
Is the only member access. I wonder if this should be static and
the caller should do
this.#mProxyMap.value = getProxyMap(newProxyMap, servers)

This way you can easy create tests for that, which would be neat :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

After reading a Tidbid more.
This property should be a computed Property, based on this.#mSiteContexts and vpnState.servers, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had forgotten about ye' old computed properties! Makes sense. Would need to be based on vpncontroller.state, vpncontroller.servers, and siteContexts though.

try {
this.#mSiteContexts.value = siteContexts;
this.updateProxyMap(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this was a computed property, we would not need to update this manually :)

extController.state.subscribe((s) => {
this.extState = s;
this.handleExtensionStateChanges(s);
});

propertySum(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This propsum is a bit suboptimal imho.
updateProxyInfoFromClient. Handles the following:
Sets ->
this.localProxyInfo = localProxy;
Sets ->
this.currentExitRelay = exitRelays;
But it does not do anything with them. So we should prefer to just grab the original value proxyHandler.currentExitRelays.value - (or create a private getter as shortcut).

Then you also have this.

    if (this.extState.useExitRelays) {
      this.defaultProxyInfo = exitRelays;
    } else {
      this.defaultProxyInfo = ProxyUtils.getDirectProxyInfoObject();
    }

However your,propertySum does not listen to changes to extState. I think that is why it's also duped in handleExtensionStateChanges?
So i think you can simply that all by just using one propertysum to update defaultProxyInfo whenever one of the dependants change:

propertySum(
proxyHandler.currentExitRelays,
extController.state,
(exitRelay, extState)=>{
   if (extState.useExitRelays) {
      this.defaultProxyInfo = exitRelays;
    } else {
      this.defaultProxyInfo = ProxyUtils.getDirectProxyInfoObject();
    }
}

And you can remove all the other dupe code to keep that up to date :)

src/background/vpncontroller/states.js Outdated Show resolved Hide resolved
@lesleyjanenorton lesleyjanenorton force-pushed the the-rest-of-it branch 2 times, most recently from c819ec9 to 9968a1e Compare September 23, 2024 17:24
@lesleyjanenorton lesleyjanenorton merged commit c3f1cf7 into main Sep 30, 2024
3 checks passed
@lesleyjanenorton lesleyjanenorton deleted the the-rest-of-it branch September 30, 2024 15:10
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