diff --git a/src/app/core/services/index.ts b/src/app/core/services/index.ts index de4bf47..7548742 100644 --- a/src/app/core/services/index.ts +++ b/src/app/core/services/index.ts @@ -2,4 +2,5 @@ export * from './electron/electron.service'; export * from './daemon/daemon.service'; export * from './daemon/daemon-data.service'; export * from './i2p/i2p-daemon.service'; +export * from './tor/tor-daemon.service'; export { MoneroInstallerService } from './monero-installer/monero-installer.service'; diff --git a/src/app/core/services/tor/tor-daemon.service.spec.ts b/src/app/core/services/tor/tor-daemon.service.spec.ts new file mode 100644 index 0000000..fe02149 --- /dev/null +++ b/src/app/core/services/tor/tor-daemon.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/core/services/tor/tor-daemon.service.ts b/src/app/core/services/tor/tor-daemon.service.ts new file mode 100644 index 0000000..57ef509 --- /dev/null +++ b/src/app/core/services/tor/tor-daemon.service.ts @@ -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(), err: new EventEmitter() }; + + 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; + err: EventEmitter; +}; \ No newline at end of file diff --git a/src/common/TorDaemonSettings.ts b/src/common/TorDaemonSettings.ts new file mode 100644 index 0000000..277a2fb --- /dev/null +++ b/src/common/TorDaemonSettings.ts @@ -0,0 +1,35 @@ +import { Comparable } from "./Comparable"; + +export class TorDaemonSettings extends Comparable { + 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; + } +} \ No newline at end of file diff --git a/src/common/index.ts b/src/common/index.ts index 86421b7..cbe2f01 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -51,4 +51,5 @@ export * from './i2p'; export { PrivnetDaemonSettings } from "./PrivnetDaemonSettings"; export { DefaultPrivnetNode1Settings } from "./DefaultPrivnetNode1Settings"; export { DefaultPrivnetNode2Settings } from "./DefaultPrivnetNode2Settings"; -export * from './I2pDaemonSettings'; \ No newline at end of file +export * from './I2pDaemonSettings'; +export * from './TorDaemonSettings'; \ No newline at end of file