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

refactor(client/windows): move fetching logic from TypeScript to Go #2220

Merged
merged 15 commits into from
Nov 1, 2024

Conversation

jyyi1
Copy link
Contributor

@jyyi1 jyyi1 commented Sep 26, 2024

New Fetch Error

image

client/go/outline/electron/main.go Outdated Show resolved Hide resolved
client/go/outline/dynamic_key.go Outdated Show resolved Hide resolved
client/electron/go_vpn_tunnel.ts Show resolved Hide resolved
client/go/outline/electron/main.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added size/L and removed size/M labels Oct 4, 2024
Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

This is changing the VPN API, but it has nothing to do with it. It needs to be redesigned to stand alone.

@@ -98,4 +98,7 @@ export interface VpnApi {

/** Sets a listener, to be called when the tunnel status changes. */
onStatusChange(listener: (id: string, status: TunnelStatus) => void): void;

/** Fetches the config from a dynamic key URL. */
fetchDynamicConfig(url: string): Promise<string>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not part of the VPN API. Please remove. We need to put it somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about putting it in nativeHelper?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We already have the concept of OutlinePlatform: https://github.com/Jigsaw-Code/outline-apps/blob/master/client/src/www/app/platform.ts

I think we need to add something like a getUrlFetcher()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, added getResourceFetcher.

client/src/www/app/outline_server_repository/server.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file should be reverted, since there's no change needed for the VPN tunnel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

client/electron/go_vpn_tunnel.ts Outdated Show resolved Hide resolved
* @throws ProcessTerminatedExitCodeError if tun2socks failed to run successfully.
*/
checkConnectivity() {
async checkConnectivity(config: TransportConfigJson): Promise<boolean> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move this to a standalone function?

There's no real dependency on internal state, only this.process, which you can replace with new ChildProcessHelper(pathToEmbeddedTun2socksBinary()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

client/electron/go_vpn_tunnel.ts Outdated Show resolved Hide resolved
client/electron/go_vpn_tunnel.ts Outdated Show resolved Hide resolved
//
// The function makes an HTTP GET request to the specified URL and returns the response body as a
// string. If the request fails or the server returns a non-2xx status code, an error is returned.
func FetchDynamicKey(url string) *FetchDynamicKeyResult {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Call it FetchUrl?
Is there anything specific to dynamic keys?

Copy link
Contributor Author

@jyyi1 jyyi1 Oct 11, 2024

Choose a reason for hiding this comment

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

Nope. Updated to FetchResource

client/go/outline/electron/main.go Outdated Show resolved Hide resolved
@jyyi1 jyyi1 requested review from fortuna and sbruens October 11, 2024 23:29
@@ -498,6 +501,12 @@ function main() {
mainWindow?.webContents.send('outline-ipc-push-clipboard');
});

// Fetches dynamic key config from a remote URL.
ipcMain.handle(
'outline-ipc-fetch-config',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps rename this to outline-ipc-fetch-resource to align with the function name and avoid confusion.

You'll need to change in the caller as well.

//
// The function makes an HTTP GET request to the specified URL and returns the response body as a
// string. If the request fails or the server returns a non-2xx status code, an error is returned.
func FetchResource(url string) *FetchResourceResult {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for this PR, but in the future we will likely want a FetchResourceRequest, so we can add other parameters, like a certificate fingerprint.

/**
* Fetches resources using Electron's IPC to communicate with the main process.
*/
export class ElectronResourceFetcher implements ResourceFetcher {
Copy link
Collaborator

Choose a reason for hiding this comment

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

window.electron doesn't exist in Cordova. This shouldn't be in a file that Cordova loads.

You can define it in the electron main.ts or create a separate file in the electron code.

@jyyi1 jyyi1 requested a review from fortuna October 14, 2024 22:20
Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks for the cleanup of udp connectivity test too.

We now have a place to improve the fetching, opening up the possibility to use proxyless solutions in case of blocking, or use certificate fingerprint to fetch from IP locations with self-signed certificates. That will in turn allow the server management API to serve dynamic keys, for example

@fortuna
Copy link
Collaborator

fortuna commented Oct 16, 2024

Perhaps the title needs to be updated to Electron instead of Windows?

@jyyi1
Copy link
Contributor Author

jyyi1 commented Oct 16, 2024

Perhaps the title needs to be updated to Electron instead of Windows?

We removed that in #2082 .

@jyyi1 jyyi1 merged commit b8ac24a into master Nov 1, 2024
22 checks passed
@jyyi1 jyyi1 deleted the junyi/fetch-in-go-electron branch November 1, 2024 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants