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