@@ -99,25 +99,32 @@ public TorConfigBuilder bridgeCustom(String config) {
99
99
return this ;
100
100
}
101
101
102
+ @ SettingsConfig
103
+ public TorConfigBuilder bridgesFromSettings () {
104
+ try {
105
+ addBridgesFromResources ();
106
+ } catch (IOException e ) {
107
+ e .printStackTrace ();
108
+ }
109
+ return this ;
110
+ }
111
+
102
112
public TorConfigBuilder configurePluggableTransportsFromSettings (File pluggableTransportClient ) throws IOException {
103
- List <String > supportedBridges = settings .getListOfSupportedBridges ();
104
- if (pluggableTransportClient == null || !settings .hasBridges () || supportedBridges .size () < 1 ) {
113
+ if (pluggableTransportClient == null ) {
105
114
return this ;
106
115
}
107
116
108
- if (!pluggableTransportClient .exists () || ! pluggableTransportClient . canExecute () ) {
117
+ if (!pluggableTransportClient .exists ()) {
109
118
throw new IOException ("Bridge binary does not exist: " + pluggableTransportClient
110
119
.getCanonicalPath ());
111
120
}
112
121
113
- if (supportedBridges .contains ("obfs3" ) || supportedBridges .contains ("obfs4" )) {
114
- transportPluginObfs (pluggableTransportClient .getCanonicalPath ());
115
- }
116
- if (supportedBridges .contains ("meek" )) {
117
- transportPluginMeek (pluggableTransportClient .getCanonicalPath ());
122
+ if (!pluggableTransportClient .canExecute ()) {
123
+ throw new IOException ("Bridge binary is not executable: " + pluggableTransportClient
124
+ .getCanonicalPath ());
118
125
}
119
- String type = supportedBridges . contains ( "meek" ) ? "meek_lite" : "obfs4" ;
120
- addBridgesFromResources ( type , 2 );
126
+
127
+ transportPlugin ( pluggableTransportClient . getCanonicalPath () );
121
128
return this ;
122
129
}
123
130
@@ -471,14 +478,8 @@ public TorConfigBuilder transPortFromSettings() {
471
478
return transPort (settings .transPort ());
472
479
}
473
480
474
- public TorConfigBuilder transportPluginMeek (String clientPath ) {
475
- buffer .append ("ClientTransportPlugin meek_lite exec " ).append (clientPath ).append ('\n' );
476
- return this ;
477
- }
478
-
479
- public TorConfigBuilder transportPluginObfs (String clientPath ) {
480
- buffer .append ("ClientTransportPlugin obfs3 exec " ).append (clientPath ).append ('\n' );
481
- buffer .append ("ClientTransportPlugin obfs4 exec " ).append (clientPath ).append ('\n' );
481
+ public TorConfigBuilder transportPlugin (String clientPath ) {
482
+ buffer .append ("ClientTransportPlugin meek_lite,obfs3,obfs4 exec " ).append (clientPath ).append ('\n' );
482
483
return this ;
483
484
}
484
485
@@ -489,7 +490,7 @@ public TorConfigBuilder useBridges() {
489
490
490
491
@ SettingsConfig
491
492
public TorConfigBuilder useBridgesFromSettings () {
492
- return ! settings .hasBridges () ? dontUseBridges () : this ;
493
+ return settings .hasBridges () ? useBridges () : this ;
493
494
}
494
495
495
496
public TorConfigBuilder virtualAddressNetwork (String address ) {
@@ -518,12 +519,12 @@ public TorConfigBuilder virtualAddressNetworkFromSettings() {
518
519
* </code>
519
520
*
520
521
*/
521
- TorConfigBuilder addBridgesFromResources (String type , int maxBridges ) throws IOException {
522
+ TorConfigBuilder addBridgesFromResources () throws IOException {
522
523
if (settings .hasBridges ()) {
523
524
InputStream bridgesStream = context .getInstaller ().openBridgesStream ();
524
525
int formatType = bridgesStream .read ();
525
- if (formatType == 0 ) {
526
- addBridges (bridgesStream , type , maxBridges );
526
+ if (formatType == 0 ) {
527
+ addBridges (bridgesStream );
527
528
} else {
528
529
addCustomBridges (bridgesStream );
529
530
}
@@ -534,23 +535,14 @@ TorConfigBuilder addBridgesFromResources(String type, int maxBridges) throws IOE
534
535
/**
535
536
* Add bridges from bridges.txt file.
536
537
*/
537
- private void addBridges (InputStream input , String bridgeType , int maxBridges ) {
538
- if (input == null || isNullOrEmpty ( bridgeType ) || maxBridges < 1 ) {
538
+ private void addBridges (InputStream input ) {
539
+ if (input == null ) {
539
540
return ;
540
541
}
541
- boolean hasAddedBridge = false ;
542
542
List <Bridge > bridges = readBridgesFromStream (input );
543
- Collections .shuffle (bridges , new Random (System .nanoTime ()));
544
- int bridgeCount = 0 ;
545
543
for (Bridge b : bridges ) {
546
- if (b .type .equals (bridgeType )) {
547
- bridge (b .type , b .config );
548
- hasAddedBridge = true ;
549
- if (++bridgeCount > maxBridges )
550
- break ;
551
- }
544
+ bridge (b .type , b .config );
552
545
}
553
- if (hasAddedBridge ) useBridges ();
554
546
}
555
547
556
548
/**
@@ -560,15 +552,12 @@ private void addCustomBridges(InputStream input) {
560
552
if (input == null ) {
561
553
return ;
562
554
}
563
- boolean hasAddedBridge = false ;
564
555
List <Bridge > bridges = readCustomBridgesFromStream (input );
565
556
for (Bridge b : bridges ) {
566
557
if (b .type .equals ("custom" )) {
567
558
bridgeCustom (b .config );
568
- hasAddedBridge = true ;
569
559
}
570
560
}
571
- if (hasAddedBridge ) useBridges ();
572
561
}
573
562
574
563
private static List <Bridge > readBridgesFromStream (InputStream input ) {
0 commit comments