-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-desktop-core): support external Tor
- Loading branch information
Showing
5 changed files
with
171 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/suite-desktop-core/src/libs/processes/TorExternalProcess.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Status } from './BaseProcess'; | ||
|
||
import { TOR_CONTROLLER_STATUS, TorControllerExternal } from '@trezor/request-manager'; | ||
|
||
export type TorProcessStatus = Status & { isBootstrapping?: boolean }; | ||
|
||
const DEFAULT_TOR_EXTERNAL_HOST = '127.0.0.1'; | ||
const DEFAULT_TOR_EXTERNAL_PORT = 9050; | ||
|
||
export class TorExternalProcess { | ||
isStopped = true; | ||
torController: TorControllerExternal; | ||
port = DEFAULT_TOR_EXTERNAL_PORT; | ||
host = DEFAULT_TOR_EXTERNAL_HOST; | ||
constructor() { | ||
this.torController = new TorControllerExternal({ host: this.host, port: this.port }); | ||
} | ||
|
||
public setTorConfig(_torConfig: { useExternalTor: boolean; snowflakeBinaryPath: string }) { | ||
// Do nothing | ||
} | ||
|
||
public getPort() { | ||
return this.port; | ||
} | ||
|
||
public async status(): Promise<TorProcessStatus> { | ||
const torControllerStatus = await this.torController.getStatus(); | ||
|
||
return { | ||
service: torControllerStatus === TOR_CONTROLLER_STATUS.ExternalTorRunning, | ||
process: torControllerStatus === TOR_CONTROLLER_STATUS.ExternalTorRunning, | ||
isBootstrapping: torControllerStatus === TOR_CONTROLLER_STATUS.Bootstrapping, // For Tor external we fake bootstrap process. | ||
}; | ||
} | ||
|
||
public async start(): Promise<void> { | ||
this.isStopped = false; | ||
await this.torController.waitUntilAlive(); | ||
} | ||
|
||
public stop() { | ||
// We should not stop External Tor Process but ignore it. | ||
this.isStopped = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters