Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions src/core/tc_tor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ TTor = class(TProcess)
FClient: IClient;
FClientListenPort: DWord;
FSocksPort: DWord;
FStandaloneTor: Boolean;
procedure GenerateTorrc;
procedure StartTorProcess;
procedure KillIfAlreadyRunning;
Expand All @@ -77,7 +78,10 @@ constructor TTor.Create(AOwner: TComponent; AClient: IClient;
FClient := AClient;
FClientListenPort := AClientPort;
FSocksPort := FClient.Config.TorPort;
StartTorProcess;
FStandaloneTor := (FClient.Config.GetString('StandaloneTor') = '1') or
(FClient.Config.GetString('StandaloneTor') = '"true"');
if not FStandaloneTor then
StartTorProcess;
end;

destructor TTor.Destroy;
Expand Down Expand Up @@ -259,35 +263,41 @@ function TTor.HiddenServiceName: String;
const
OnionLength = 16;
begin
FileName := ConcatPaths([CurrentDirectory, 'hidden_service', 'hostname']);
SetLength(Result, OnionLength);
try
HostnameFile := TFileStream.Create(FileName, fmOpenRead);
if HostnameFile.Read(Result[1], OnionLength) < OnionLength then
if FStandaloneTor then
Result := FClient.Config.GetString('HiddenServiceName')
else begin
FileName := ConcatPaths([CurrentDirectory, 'hidden_service', 'hostname']);
SetLength(Result, OnionLength);
try
HostnameFile := TFileStream.Create(FileName, fmOpenRead);
if HostnameFile.Read(Result[1], OnionLength) < OnionLength then
Result := '';
except
Result := '';
except
Result := '';
end;
if Assigned(HostnameFile) then FreeAndNil(HostnameFile);
end;
if Assigned(HostnameFile) then FreeAndNil(HostnameFile);
end;

procedure TTor.CleanShutdown;
begin
{$ifdef unix}
FpKill(Handle, SIGINT); // Tor will exit cleanly on SIGINT
{$else}
{$ifdef windows}
// there are no signals in windows, they also forgot to
// implement any other mechanism for sending Ctrl-C to
// another process. We have to kill it.
TerminateProcess(Handle, 0);
DeleteFile(ConcatPaths([CurrentDirectory, 'tor.pid']));
if not FStandaloneTor then begin
{$ifdef unix}
FpKill(Handle, SIGINT); // Tor will exit cleanly on SIGINT
{$else}
Terminate(0);
DeleteFile(ConcatPaths([CurrentDirectory, 'tor.pid']));
{$ifdef windows}
// there are no signals in windows, they also forgot to
// implement any other mechanism for sending Ctrl-C to
// another process. We have to kill it.
TerminateProcess(Handle, 0);
DeleteFile(ConcatPaths([CurrentDirectory, 'tor.pid']));
{$else}
Terminate(0);
DeleteFile(ConcatPaths([CurrentDirectory, 'tor.pid']));
{$endif}
{$endif}
{$endif}
RemovePortFromList(FSocksPort);
RemovePortFromList(FSocksPort);
end;
end;

end.
Expand Down