generated from maximegris/angular-electron
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial tor daemon service implementation
- Loading branch information
1 parent
787cfa6
commit f940f88
Showing
5 changed files
with
107 additions
and
1 deletion.
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
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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { TorDaemonService } from './tor-daemon.service'; | ||
|
||
describe('TorDaemonService', () => { | ||
let service: TorDaemonService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(TorDaemonService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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,53 @@ | ||
import { EventEmitter, Injectable } from '@angular/core'; | ||
import { TorDaemonSettings } from '../../../../common'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TorDaemonService { | ||
|
||
public readonly std: TorStd = { out: new EventEmitter<string>(), err: new EventEmitter<string>() }; | ||
|
||
private _settings: TorDaemonSettings = new TorDaemonSettings(); | ||
private _running: boolean = false; | ||
private _starting: boolean = false; | ||
private _stopping: boolean = false; | ||
private _restarting: boolean = false; | ||
private _loaded: boolean = false; | ||
private _logs: string[] = []; | ||
|
||
public get running(): boolean { | ||
return this._running; | ||
} | ||
|
||
public get starting(): boolean { | ||
return this._starting; | ||
} | ||
|
||
public get stopping(): boolean { | ||
return this._stopping; | ||
} | ||
|
||
public get restarting(): boolean { | ||
return this._restarting; | ||
} | ||
|
||
public get logs(): string[] { | ||
return this._logs; | ||
} | ||
|
||
public get settings(): TorDaemonSettings { | ||
return this._settings; | ||
} | ||
|
||
public get loaded(): boolean { | ||
return this._loaded; | ||
} | ||
|
||
constructor() { } | ||
} | ||
|
||
interface TorStd { | ||
out: EventEmitter<string>; | ||
err: EventEmitter<string>; | ||
}; |
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,35 @@ | ||
import { Comparable } from "./Comparable"; | ||
|
||
export class TorDaemonSettings extends Comparable<TorDaemonSettings> { | ||
public allowIncomingConnections: boolean = true; | ||
public txProxyEnabled: boolean = true; | ||
public enabled: boolean = false; | ||
public path: string = ""; | ||
|
||
public port: number = 18085; | ||
public rpcPort: number = 18089; | ||
|
||
public outproxy?: { host: string; port: number }; | ||
|
||
public override clone(): TorDaemonSettings { | ||
const result = Object.assign(new TorDaemonSettings(), this); | ||
|
||
if (this.outproxy) result.outproxy = { ...this.outproxy }; | ||
|
||
return result; | ||
} | ||
|
||
public static parse(obj: any): TorDaemonSettings { | ||
const { allowIncomingConnections, txProxyEnabled, enabled, path, outproxy } = obj; | ||
|
||
const result = new TorDaemonSettings(); | ||
|
||
if (typeof allowIncomingConnections === 'boolean') result.allowIncomingConnections = allowIncomingConnections; | ||
if (typeof txProxyEnabled === 'boolean') result.txProxyEnabled = txProxyEnabled; | ||
if (typeof enabled === 'boolean') result.enabled = enabled; | ||
if (typeof path === 'string') result.path = path; | ||
if (typeof outproxy === 'object') result.outproxy = { ...outproxy }; | ||
|
||
return result; | ||
} | ||
} |
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