Verified Commit 642df684 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 40933: Add tor-launcher functionality

Fix a couple of problems in TorLauncherUtil and TorParsers.

Also, moved the function to parse bridges in TorParsers.
parent c3d2496b
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -209,14 +209,15 @@ class TorFile {
  // and return a file object. The control and SOCKS IPC objects will be
  // created by tor.
  normalize() {
    if (!this.file.exists() && !this.isIPC) {
      throw new Error(`${this.fileType} file not found: ${this.file.path}`);
    }
    if (this.file.exists()) {
      try {
        this.file.normalize();
      } catch (e) {
        console.warn("Normalization of the path failed", e);
      }
    } else if (!this.isIPC) {
      throw new Error(`${this.fileType} file not found: ${this.file.path}`);
    }

    // Ensure that the IPC path length is short enough for use by the
    // operating system. If not, create and use a unique directory under
+14 −0
Original line number Diff line number Diff line
@@ -267,4 +267,18 @@ export const TorParsers = Object.freeze({
    rv += aStr.substring(lastAdded, aStr.length - 1);
    return rv;
  },

  parseBridgeLine(line) {
    const re =
      /\s*(?:(?<transport>\S+)\s+)?(?<addr>[0-9a-fA-F\.\[\]\:]+:\d{1,5})(?:\s+(?<id>[0-9a-fA-F]{40}))?(?:\s+(?<args>.+))?/;
    const match = re.exec(line);
    if (!match) {
      throw new Error("Invalid bridge line.");
    }
    const bridge = match.groups;
    if (!bridge.transport) {
      bridge.transport = "vanilla";
    }
    return bridge;
  },
});