| ... |
... |
@@ -25,6 +25,24 @@ const logger = console.createInstance({ |
|
25
|
25
|
prefix: "TorProcess",
|
|
26
|
26
|
});
|
|
27
|
27
|
|
|
|
28
|
+/**
|
|
|
29
|
+ * Format host and port to pass them as a command line argument to tor.
|
|
|
30
|
+ *
|
|
|
31
|
+ * @param {string} host - The hostname. If it looks like an IPv6 (it contains
|
|
|
32
|
+ * `:`), it will be wrapped between `[` and `]`
|
|
|
33
|
+ * @param {number} port - The port
|
|
|
34
|
+ * @returns {string} The properly formatted host and port combination
|
|
|
35
|
+ */
|
|
|
36
|
+function formatTorHostPort(host, port) {
|
|
|
37
|
+ if (!host) {
|
|
|
38
|
+ return String(port);
|
|
|
39
|
+ }
|
|
|
40
|
+ if (host.includes(":") && !host.startsWith("[")) {
|
|
|
41
|
+ return `[${host}]:${port}`;
|
|
|
42
|
+ }
|
|
|
43
|
+ return `${host}:${port}`;
|
|
|
44
|
+}
|
|
|
45
|
+
|
|
28
|
46
|
/**
|
|
29
|
47
|
* This class can be used to start a tor daemon instance and receive
|
|
30
|
48
|
* notifications when it exits.
|
| ... |
... |
@@ -316,9 +334,10 @@ export class TorProcess { |
|
316
|
334
|
if (this.#controlSettings.ipcFile) {
|
|
317
|
335
|
controlPortArg = this.#controlSettings.ipcFile;
|
|
318
|
336
|
} else if (this.#controlSettings.port) {
|
|
319
|
|
- controlPortArg = this.#controlSettings.host
|
|
320
|
|
- ? `${this.#controlSettings.host}:${this.#controlSettings.port}`
|
|
321
|
|
- : this.#controlSettings.port.toString();
|
|
|
337
|
+ controlPortArg = formatTorHostPort(
|
|
|
338
|
+ this.#controlSettings.host,
|
|
|
339
|
+ this.#controlSettings.port
|
|
|
340
|
+ );
|
|
322
|
341
|
}
|
|
323
|
342
|
if (controlPortArg) {
|
|
324
|
343
|
this.#args.push("+__ControlPort", controlPortArg);
|
| ... |
... |
@@ -347,9 +366,10 @@ export class TorProcess { |
|
347
|
366
|
if (this.#socksSettings.ipcFile) {
|
|
348
|
367
|
socksPortArg = this.#socksSettings.ipcFile;
|
|
349
|
368
|
} else if (this.#socksSettings.port > 0) {
|
|
350
|
|
- socksPortArg = this.#socksSettings.host
|
|
351
|
|
- ? `${this.#socksSettings.host}:${this.#socksSettings.port}`
|
|
352
|
|
- : this.#socksSettings.port.toString();
|
|
|
369
|
+ socksPortArg = formatTorHostPort(
|
|
|
370
|
+ this.#socksSettings.host,
|
|
|
371
|
+ this.#socksSettings.port
|
|
|
372
|
+ );
|
|
353
|
373
|
} else {
|
|
354
|
374
|
socksPortArg = "auto";
|
|
355
|
375
|
}
|