Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Talk to the control socket using my old draft tor daemon manager. #14146

Merged
merged 34 commits into from
May 22, 2018

Conversation

riastradh-brave
Copy link
Contributor

@riastradh-brave riastradh-brave commented May 16, 2018

This doesn't solve #14043 yet, but it provides a candidate place to hook up a progress indicator. See the TODO(riastradh): Visually update a progress bar! comment for the place where we should update a progress bar, currently c2b3eda#diff-8a9bac13ef6264feb2b6da7c18d86b3cR751.

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Test Plan:

Launch Brave. Confirm that the console output mentions tor bootstrapping.

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

app/filtering.js Outdated
@@ -47,6 +48,8 @@ const headersReceivedFilteringFns = []
let partitionsToInitialize = ['default', appConfig.tor.partition]
let initializedPartitions = {}

let torDaemon = new tor.TorDaemon()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you don't reassign to this variable so better to use const instead of let

also this doesn't need to be in the module scope, right? so it can be declared in setupTor instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 453e327

loop(i + 1)
})
}
loop(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be slightly clearer if you used directories.forEach instead of this recursive loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callbacks make forEach a little tricky. If this should be done with mkdirSync, I guess that's OK, but I figured it would be better to avoid that. (I'm not sure this is necessary, but the ordering of directory creation in muon vs browser-laptop is not obvious, so I figured it would be safer to keep this logic than delete it.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riastradh-brave i see now that one of the directories is a subdir of the other. in that case you can just use fs-extra's mkdir instead of fs's mkdir, which will behave like mkdir -p: https://github.com/jprichardson/node-fs-extra

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does that help to do multiple ones in a loop? I guess I could replace the whole thing by a single mkdirp for the deepest subdirectory, but I didn't want to embed the assumption that there is a single deepest subdirectory in that function.

app/tor.js Outdated
module.exports.torControlParseQuoted = torControlParseQuoted
module.exports.torrcEscapeBuffer = torrcEscapeBuffer
module.exports.torrcEscapePath = torrcEscapePath
module.exports.torrcEscapeString = torrcEscapeString
Copy link
Member

@diracdeltas diracdeltas May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit tests for these exported methods (located in test/unit, npm run unittest to run)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 4282807

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding tests - could you also document the input types of any externally-callable methods/constructors using jsdoc so it's harder to get the types wrong? http://usejsdoc.org/ - see js/lib/request for an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 8f532a9

@diracdeltas diracdeltas force-pushed the tor/0.23.x branch 2 times, most recently from fc600c5 to a93cfd4 Compare May 17, 2018 21:20
@riastradh-brave riastradh-brave force-pushed the riastradh-tor-control branch from 81e4ac4 to 4b39b3a Compare May 17, 2018 23:11
@riastradh-brave
Copy link
Contributor Author

In 4b39b3a, I added some automatic tests for the logic to launch tor and wait for a notification that it has launched within a reasonable time, but they are broken because fs.mkdir doesn't work while running npm run unittest.

These tests may also be problematic because they deliberately put in a half-second delay to make sure we exercise both orders of (a) tor process startup, and (b) fs event watch notification logic setup.

What to do?

@riastradh-brave riastradh-brave force-pushed the riastradh-tor-control branch from 4b39b3a to d265aa9 Compare May 17, 2018 23:46
@riastradh-brave
Copy link
Contributor Author

Never mind, apparently this works now and I have no idea why it failed before.

These indicate when tor thinks it's definitely ready, or definitely
not ready (any more).
- 'end' means end of input only
- 'error' means an error happened but no state change
- 'close' means underlying resource is now closed

Make sure TorDaemon emits 'exit' event when control closes.  Confirm
in automatic tests that

(a) the TorDaemon emits 'exit', _and_
(b) the tor process exits.

This increases the total amount of code by about 70 lines, but the
logic in each of the event handlers is smaller because their use more
precisely reflects their fine-grained intent in the nodejs APIs, and
many of the new lines are in comments on new short internal
subroutines.
@riastradh-brave riastradh-brave force-pushed the riastradh-tor-control branch from 277a354 to daf4f24 Compare May 22, 2018 19:55
@diracdeltas diracdeltas merged commit 86e51d0 into tor/0.23.x May 22, 2018
@diracdeltas diracdeltas deleted the riastradh-tor-control branch May 22, 2018 21:59
diracdeltas pushed a commit that referenced this pull request Jun 8, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
diracdeltas pushed a commit that referenced this pull request Jun 12, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
petemill pushed a commit that referenced this pull request Jun 15, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 21, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 21, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 22, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
diracdeltas pushed a commit that referenced this pull request Jun 22, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 23, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 25, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 26, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
bsclifton pushed a commit that referenced this pull request Jun 27, 2018
…4146)

Needed for #14043.

Auditors:
@diracdeltas

Test Plan:
1. Launch Brave.
2. Examine console output.
3. Confirm it mentions tor bootstrapping.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants