@@ -38,6 +38,7 @@ const {cookieExceptions, isRefererException} = require('../js/data/siteHacks')
38
38
const { getBraverySettingsCache, updateBraverySettingsCache} = require ( './common/cache/braverySettingsCache' )
39
39
const { shouldDebugTabEvents} = require ( './cmdLine' )
40
40
const { getTorSocksProxy} = require ( './channel' )
41
+ const tor = require ( './tor' )
41
42
42
43
let appStore = null
43
44
@@ -712,6 +713,7 @@ const initPartition = (partition) => {
712
713
options . parent_partition = ''
713
714
}
714
715
if ( isTorPartition ) {
716
+ setupTor ( )
715
717
// TODO(riastradh): Duplicate logic in app/browser/tabs.js.
716
718
options . isolated_storage = true
717
719
options . parent_partition = ''
@@ -740,6 +742,49 @@ const initPartition = (partition) => {
740
742
}
741
743
module . exports . initPartition = initPartition
742
744
745
+ function setupTor ( ) {
746
+ // Set up the tor daemon watcher. (NOTE: We don't actually start
747
+ // the tor daemon here; that happens in C++ code. But we do talk to
748
+ // its control socket.)
749
+ const torDaemon = new tor . TorDaemon ( )
750
+ torDaemon . setup ( ( err ) => {
751
+ if ( err ) {
752
+ console . log ( `tor: failed to make directories: ${ err } ` )
753
+ return
754
+ }
755
+ torDaemon . on ( 'exit' , ( ) => console . log ( 'tor: daemon exited' ) )
756
+ torDaemon . on ( 'launch' , ( socksAddr ) => {
757
+ console . log ( `tor: daemon listens on ${ socksAddr } ` )
758
+ const bootstrapped = ( err , progress ) => {
759
+ // TODO(riastradh): Visually update a progress bar!
760
+ if ( err ) {
761
+ console . log ( `tor: bootstrap error: ${ err } ` )
762
+ return
763
+ }
764
+ console . log ( `tor: bootstrapped ${ progress } %` )
765
+ }
766
+ const circuitEstablished = ( err , ok ) => {
767
+ if ( ok ) {
768
+ console . log ( `tor: ready` )
769
+ } else {
770
+ console . log ( err ? `tor: not ready: ${ err } ` : `tor: not ready` )
771
+ }
772
+ }
773
+ torDaemon . onBootstrap ( bootstrapped , ( err ) => {
774
+ if ( err ) {
775
+ console . log ( `tor: error subscribing to bootstrap: ${ err } ` )
776
+ }
777
+ torDaemon . onCircuitEstablished ( circuitEstablished , ( err ) => {
778
+ if ( err ) {
779
+ console . log ( `tor: error subscribing to circuit ready: ${ err } ` )
780
+ }
781
+ } )
782
+ } )
783
+ } )
784
+ torDaemon . start ( )
785
+ } )
786
+ }
787
+
743
788
const filterableProtocols = [ 'http:' , 'https:' , 'ws:' , 'wss:' , 'magnet:' , 'file:' ]
744
789
745
790
function shouldIgnoreUrl ( details ) {
0 commit comments