clean up VPNBuilder setup code
This commit is contained in:
parent
91a72ef5d1
commit
08c220f88e
|
@ -144,6 +144,9 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
|
||||||
{
|
{
|
||||||
if (mInterface == null)
|
if (mInterface == null)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
// Set the locale to English (or probably any other language that^M
|
// Set the locale to English (or probably any other language that^M
|
||||||
// uses Hindu-Arabic (aka Latin) numerals).^M
|
// uses Hindu-Arabic (aka Latin) numerals).^M
|
||||||
// We have found that VpnService.Builder does something locale-dependent^M
|
// We have found that VpnService.Builder does something locale-dependent^M
|
||||||
|
@ -151,12 +154,14 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
|
||||||
// (i.e., Farsi and Arabic).^M
|
// (i.e., Farsi and Arabic).^M
|
||||||
Locale.setDefault(new Locale("en"));
|
Locale.setDefault(new Locale("en"));
|
||||||
|
|
||||||
|
String localhost = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
|
||||||
String vpnName = "OrbotVPN";
|
String vpnName = "OrbotVPN";
|
||||||
String virtualGateway = "10.0.0.1";
|
String virtualGateway = "10.0.0.1";
|
||||||
String virtualIP = "10.0.0.2";
|
String virtualIP = "10.0.0.2";
|
||||||
String virtualNetMask = "255.255.255.0";
|
String virtualNetMask = "255.255.255.0";
|
||||||
String localSocks = "127.0.0.1:" + TorServiceConstants.PORT_SOCKS_DEFAULT;
|
String localSocks = localhost + ':' + TorServiceConstants.PORT_SOCKS_DEFAULT;
|
||||||
String localDNS = "10.0.0.1:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT;
|
String localDNS = localhost + ':' + TorServiceConstants.TOR_DNS_PORT_DEFAULT;
|
||||||
|
|
||||||
|
|
||||||
Builder builder = new Builder();
|
Builder builder = new Builder();
|
||||||
|
@ -164,17 +169,15 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
|
||||||
builder.setMtu(VPN_MTU);
|
builder.setMtu(VPN_MTU);
|
||||||
builder.addAddress(virtualGateway,28);
|
builder.addAddress(virtualGateway,28);
|
||||||
builder.setSession(vpnName);
|
builder.setSession(vpnName);
|
||||||
|
|
||||||
builder.addRoute("0.0.0.0",0);
|
builder.addRoute("0.0.0.0",0);
|
||||||
|
builder.addDnsServer("8.8.8.8");
|
||||||
|
|
||||||
// Create a new interface using the builder and save the parameters.
|
// Create a new interface using the builder and save the parameters.
|
||||||
mInterface = builder.setSession(mSessionName)
|
mInterface = builder.setSession(mSessionName)
|
||||||
.setConfigureIntent(mConfigureIntent)
|
.setConfigureIntent(mConfigureIntent)
|
||||||
.establish();
|
.establish();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true);
|
Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
Loading…
Reference in New Issue