Skip to content

Commit

Permalink
Partial tor daemon service implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Feb 22, 2025
1 parent 787cfa6 commit f940f88
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/app/core/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
16 changes: 16 additions & 0 deletions src/app/core/services/tor/tor-daemon.service.spec.ts
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();
});
});
53 changes: 53 additions & 0 deletions src/app/core/services/tor/tor-daemon.service.ts
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>;
};
35 changes: 35 additions & 0 deletions src/common/TorDaemonSettings.ts
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;
}
}
3 changes: 2 additions & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export * from './i2p';
export { PrivnetDaemonSettings } from "./PrivnetDaemonSettings";
export { DefaultPrivnetNode1Settings } from "./DefaultPrivnetNode1Settings";
export { DefaultPrivnetNode2Settings } from "./DefaultPrivnetNode2Settings";
export * from './I2pDaemonSettings';
export * from './I2pDaemonSettings';
export * from './TorDaemonSettings';

0 comments on commit f940f88

Please sign in to comment.