Provider: use DnsServer directly, get rid of magics
This commit is contained in:
parent
c95b87b5a8
commit
a2d92d49aa
@ -10,7 +10,6 @@ import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.net.VpnService;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@ -19,8 +18,8 @@ import com.google.gson.stream.JsonReader;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.*;
|
||||
import org.itxtech.daedalus.util.server.DNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.DnsServer;
|
||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -42,13 +41,13 @@ public class Daedalus extends Application {
|
||||
|
||||
private static final String SHORTCUT_ID_ACTIVATE = "shortcut_activate";
|
||||
|
||||
public static final List<DNSServer> DNS_SERVERS = new ArrayList<DNSServer>() {{
|
||||
add(new DNSServer("101.101.101.101", R.string.server_twnic_primary));
|
||||
add(new DNSServer("101.102.103.104", R.string.server_twnic_secondary));
|
||||
add(new DNSServer("dns.rubyfish.cn/dns-query", R.string.server_rubyfish));
|
||||
add(new DNSServer("cloudflare-dns.com/dns-query", R.string.server_cloudflare));
|
||||
add(new DNSServer("dns.google/dns-query", R.string.server_google_ietf));
|
||||
add(new DNSServer("dns.google/resolve", R.string.server_google_json));
|
||||
public static final List<DnsServer> DNS_SERVERS = new ArrayList<DnsServer>() {{
|
||||
add(new DnsServer("101.101.101.101", R.string.server_twnic_primary));
|
||||
add(new DnsServer("101.102.103.104", R.string.server_twnic_secondary));
|
||||
add(new DnsServer("rubyfish.cn/dns-query", R.string.server_rubyfish));
|
||||
add(new DnsServer("cloudflare-dns.com/dns-query", R.string.server_cloudflare));
|
||||
add(new DnsServer("dns.google/dns-query", R.string.server_google_ietf));
|
||||
add(new DnsServer("dns.google/resolve", R.string.server_google_json));
|
||||
}};
|
||||
|
||||
public static final List<Rule> RULES = new ArrayList<Rule>() {{
|
||||
@ -211,16 +210,16 @@ public class Daedalus extends Application {
|
||||
}
|
||||
|
||||
public static void activateService(Context context) {
|
||||
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
|
||||
DaedalusVpnService.primaryServer = DnsServerHelper.getServerById(DnsServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DnsServerHelper.getServerById(DnsServerHelper.getSecondary());
|
||||
if (getPrefs().getBoolean("settings_use_system_dns", false)) {
|
||||
String[] servers = DnsServersDetector.getServers(context);
|
||||
if (servers != null) {
|
||||
if (servers.length >= 2) {
|
||||
DaedalusVpnService.primaryServer = servers[0];
|
||||
DaedalusVpnService.secondaryServer = servers[1];
|
||||
DaedalusVpnService.primaryServer = new DnsServer(servers[0], 0);
|
||||
DaedalusVpnService.secondaryServer = new DnsServer(servers[1], 0);
|
||||
} else {
|
||||
DaedalusVpnService.primaryServer = DaedalusVpnService.secondaryServer = servers[0];
|
||||
DaedalusVpnService.primaryServer = DaedalusVpnService.secondaryServer = new DnsServer(servers[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.fragment.ConfigFragment;
|
||||
import org.itxtech.daedalus.fragment.DNSServerConfigFragment;
|
||||
import org.itxtech.daedalus.fragment.DnsServerConfigFragment;
|
||||
import org.itxtech.daedalus.fragment.RuleConfigFragment;
|
||||
|
||||
/**
|
||||
@ -45,13 +45,13 @@ public class ConfigActivity extends AppCompatActivity {
|
||||
ConfigFragment fragment;
|
||||
switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) {
|
||||
case LAUNCH_FRAGMENT_DNS_SERVER:
|
||||
fragment = new DNSServerConfigFragment();
|
||||
fragment = new DnsServerConfigFragment();
|
||||
break;
|
||||
case LAUNCH_FRAGMENT_RULE:
|
||||
fragment = new RuleConfigFragment();
|
||||
break;
|
||||
default://should never reach this
|
||||
fragment = new DNSServerConfigFragment();
|
||||
fragment = new DnsServerConfigFragment();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package org.itxtech.daedalus.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.VpnService;
|
||||
import android.os.Bundle;
|
||||
@ -25,7 +24,6 @@ import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.fragment.*;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -215,10 +213,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
switchFragment(AboutFragment.class);
|
||||
break;
|
||||
case FRAGMENT_DNS_SERVERS:
|
||||
switchFragment(DNSServersFragment.class);
|
||||
switchFragment(DnsServersFragment.class);
|
||||
break;
|
||||
case FRAGMENT_DNS_TEST:
|
||||
switchFragment(DNSTestFragment.class);
|
||||
switchFragment(DnsTestFragment.class);
|
||||
break;
|
||||
case FRAGMENT_HOME:
|
||||
switchFragment(HomeFragment.class);
|
||||
@ -247,10 +245,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
switchFragment(AboutFragment.class);
|
||||
break;
|
||||
case R.id.nav_dns_server:
|
||||
switchFragment(DNSServersFragment.class);
|
||||
switchFragment(DnsServersFragment.class);
|
||||
break;
|
||||
case R.id.nav_dns_test:
|
||||
switchFragment(DNSTestFragment.class);
|
||||
switchFragment(DnsTestFragment.class);
|
||||
break;
|
||||
case R.id.nav_github:
|
||||
Daedalus.openUri("https://github.com/iTXTech/Daedalus");
|
||||
|
@ -13,6 +13,7 @@ import android.webkit.WebViewClient;
|
||||
import org.itxtech.daedalus.BuildConfig;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@ -64,7 +65,7 @@ public class AboutFragment extends ToolbarFragment {
|
||||
mWebView.loadUrl("javascript:changeColor('"+(Daedalus.isDarkTheme() ? "#FFFFFF" : "#000000")+"')");
|
||||
mWebView.loadUrl("javascript:changeVersionInfo('" + Daedalus.getInstance().getPackageManager().getPackageInfo(Daedalus.getInstance().getPackageName(), 0).versionName + "', '" + BuildConfig.BUILD_TIME + "', '" + BuildConfig.GIT_COMMIT + "')");
|
||||
} catch (Exception e) {
|
||||
Log.e("DAboutActivity", e.toString());
|
||||
Logger.logException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -82,8 +83,6 @@ public class AboutFragment extends ToolbarFragment {
|
||||
super.onDestroyView();
|
||||
|
||||
if (mWebView != null) {
|
||||
Log.d("DAboutActivity", "onDestroy");
|
||||
|
||||
mWebView.removeAllViews();
|
||||
mWebView.setWebViewClient(null);
|
||||
((ViewGroup) mWebView.getParent()).removeView(mWebView);
|
||||
|
@ -11,8 +11,8 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.ConfigActivity;
|
||||
import org.itxtech.daedalus.util.server.CustomDNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServer;
|
||||
import org.itxtech.daedalus.server.CustomDnsServer;
|
||||
import org.itxtech.daedalus.server.DnsServer;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -25,7 +25,7 @@ import org.itxtech.daedalus.util.server.DNSServer;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DNSServerConfigFragment extends ConfigFragment {
|
||||
public class DnsServerConfigFragment extends ConfigFragment {
|
||||
private int index;
|
||||
|
||||
@Override
|
||||
@ -58,7 +58,7 @@ public class DNSServerConfigFragment extends ConfigFragment {
|
||||
|
||||
index = intent.getIntExtra(ConfigActivity.LAUNCH_ACTION_ID, ConfigActivity.ID_NONE);
|
||||
if (index != ConfigActivity.ID_NONE) {
|
||||
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(index);
|
||||
CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(index);
|
||||
serverName.setText(server.getName());
|
||||
serverName.setSummary(server.getName());
|
||||
serverAddress.setText(server.getAddress());
|
||||
@ -68,7 +68,7 @@ public class DNSServerConfigFragment extends ConfigFragment {
|
||||
} else {
|
||||
serverName.setText("");
|
||||
serverAddress.setText("");
|
||||
String port = String.valueOf(DNSServer.DNS_SERVER_DEFAULT_PORT);
|
||||
String port = String.valueOf(DnsServer.DNS_SERVER_DEFAULT_PORT);
|
||||
serverPort.setText(port);
|
||||
serverPort.setSummary(port);
|
||||
}
|
||||
@ -92,9 +92,9 @@ public class DNSServerConfigFragment extends ConfigFragment {
|
||||
}
|
||||
|
||||
if (index == ConfigActivity.ID_NONE) {
|
||||
Daedalus.configurations.getCustomDNSServers().add(new CustomDNSServer(serverName, serverAddress, Integer.parseInt(serverPort)));
|
||||
Daedalus.configurations.getCustomDNSServers().add(new CustomDnsServer(serverName, serverAddress, Integer.parseInt(serverPort)));
|
||||
} else {
|
||||
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(index);
|
||||
CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(index);
|
||||
server.setName(serverName);
|
||||
server.setAddress(serverAddress);
|
||||
server.setPort(Integer.parseInt(serverPort));
|
@ -15,8 +15,8 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.ConfigActivity;
|
||||
import org.itxtech.daedalus.util.server.CustomDNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.CustomDnsServer;
|
||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -29,9 +29,9 @@ import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DNSServersFragment extends ToolbarFragment {
|
||||
public class DnsServersFragment extends ToolbarFragment {
|
||||
private DNSServerAdapter adapter;
|
||||
private CustomDNSServer server = null;
|
||||
private CustomDnsServer server = null;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@ -47,7 +47,7 @@ public class DNSServersFragment extends ToolbarFragment {
|
||||
if (viewHolder instanceof ViewHolder) {
|
||||
int index = ((ViewHolder) viewHolder).getIndex();
|
||||
if (index < Daedalus.configurations.getCustomDNSServers().size() &&
|
||||
DNSServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
|
||||
DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class DNSServersFragment extends ToolbarFragment {
|
||||
private class DNSServerAdapter extends RecyclerView.Adapter<ViewHolder> {
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(position);
|
||||
CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(position);
|
||||
holder.setIndex(position);
|
||||
holder.textViewName.setText(server.getName());
|
||||
holder.textViewAddress.setText(server.getRealName());
|
||||
@ -159,7 +159,7 @@ public class DNSServersFragment extends ToolbarFragment {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!DNSServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
|
||||
if (!DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
|
||||
Daedalus.getInstance().startActivity(new Intent(Daedalus.getInstance(), ConfigActivity.class)
|
||||
.putExtra(ConfigActivity.LAUNCH_ACTION_ID, index)
|
||||
.putExtra(ConfigActivity.LAUNCH_ACTION_FRAGMENT, ConfigActivity.LAUNCH_FRAGMENT_DNS_SERVER)
|
@ -12,8 +12,8 @@ import android.widget.*;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.AbstractDNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.AbstractDnsServer;
|
||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||
import org.minidns.dnsmessage.DnsMessage;
|
||||
import org.minidns.dnsmessage.Question;
|
||||
import org.minidns.record.Record;
|
||||
@ -36,7 +36,7 @@ import java.util.Random;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DNSTestFragment extends ToolbarFragment {
|
||||
public class DnsTestFragment extends ToolbarFragment {
|
||||
private class Type {
|
||||
private Record.TYPE type;
|
||||
private String name;
|
||||
@ -67,9 +67,9 @@ public class DNSTestFragment extends ToolbarFragment {
|
||||
final TextView textViewTestInfo = view.findViewById(R.id.textView_test_info);
|
||||
|
||||
final Spinner spinnerServerChoice = view.findViewById(R.id.spinner_server_choice);
|
||||
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, DNSServerHelper.getAllServers());
|
||||
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, DnsServerHelper.getAllServers());
|
||||
spinnerServerChoice.setAdapter(spinnerArrayAdapter);
|
||||
spinnerServerChoice.setSelection(DNSServerHelper.getPosition(DNSServerHelper.getPrimary()));
|
||||
spinnerServerChoice.setSelection(DnsServerHelper.getPosition(DnsServerHelper.getPrimary()));
|
||||
|
||||
ArrayList<Type> types = new ArrayList<Type>() {{
|
||||
add(new Type("A", Record.TYPE.A));
|
||||
@ -110,38 +110,38 @@ public class DNSTestFragment extends ToolbarFragment {
|
||||
testDomain = Daedalus.DEFAULT_TEST_DOMAINS[0];
|
||||
}
|
||||
StringBuilder testText = new StringBuilder();
|
||||
ArrayList<AbstractDNSServer> dnsServers = new ArrayList<AbstractDNSServer>() {{
|
||||
add(((AbstractDNSServer) spinnerServerChoice.getSelectedItem()));
|
||||
ArrayList<AbstractDnsServer> dnsServers = new ArrayList<AbstractDnsServer>() {{
|
||||
add(((AbstractDnsServer) spinnerServerChoice.getSelectedItem()));
|
||||
String servers = Daedalus.getPrefs().getString("dns_test_servers", "");
|
||||
if (!servers.equals("")) {
|
||||
for (String server : servers.split(",")) {
|
||||
if (server.contains(".") && server.contains(":")) {//IPv4
|
||||
String[] pieces = servers.split(":");
|
||||
int port = AbstractDNSServer.DNS_SERVER_DEFAULT_PORT;
|
||||
int port = AbstractDnsServer.DNS_SERVER_DEFAULT_PORT;
|
||||
try {
|
||||
port = Integer.parseInt(pieces[1]);
|
||||
} catch (Exception e) {
|
||||
Logger.logException(e);
|
||||
}
|
||||
add(new AbstractDNSServer(pieces[0], port));
|
||||
add(new AbstractDnsServer(pieces[0], port));
|
||||
} else if (!server.contains(".") && server.contains("|")) {//IPv6
|
||||
String[] pieces = servers.split("\\|");
|
||||
int port = AbstractDNSServer.DNS_SERVER_DEFAULT_PORT;
|
||||
int port = AbstractDnsServer.DNS_SERVER_DEFAULT_PORT;
|
||||
try {
|
||||
port = Integer.parseInt(pieces[1]);
|
||||
} catch (Exception e) {
|
||||
Logger.logException(e);
|
||||
}
|
||||
add(new AbstractDNSServer(pieces[0], port));
|
||||
add(new AbstractDnsServer(pieces[0], port));
|
||||
} else {
|
||||
add(new AbstractDNSServer(server, AbstractDNSServer.DNS_SERVER_DEFAULT_PORT));
|
||||
add(new AbstractDnsServer(server, AbstractDnsServer.DNS_SERVER_DEFAULT_PORT));
|
||||
}
|
||||
}
|
||||
}
|
||||
}};
|
||||
DnsQuery dnsQuery = new DnsQuery();
|
||||
Record.TYPE type = ((Type) spinnerType.getSelectedItem()).getType();
|
||||
for (AbstractDNSServer dnsServer : dnsServers) {
|
||||
for (AbstractDnsServer dnsServer : dnsServers) {
|
||||
testText = testServer(dnsQuery, type, dnsServer, testDomain, testText);
|
||||
}
|
||||
mHandler.obtainMessage(DnsTestHandler.MSG_TEST_DONE).sendToTarget();
|
||||
@ -152,7 +152,7 @@ public class DNSTestFragment extends ToolbarFragment {
|
||||
}
|
||||
|
||||
|
||||
private StringBuilder testServer(DnsQuery dnsQuery, Record.TYPE type, AbstractDNSServer server, String domain, StringBuilder testText) {
|
||||
private StringBuilder testServer(DnsQuery dnsQuery, Record.TYPE type, AbstractDnsServer server, String domain, StringBuilder testText) {
|
||||
Logger.debug("Testing DNS server " + server.getRealName());
|
||||
testText.append(getString(R.string.test_domain)).append(" ").append(domain).append("\n")
|
||||
.append(getString(R.string.test_dns_server)).append(" ").append(server.getRealName());
|
@ -7,7 +7,7 @@ import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.AppFilterActivity;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -27,8 +27,8 @@ public class GlobalConfigFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
Daedalus.getPrefs().edit()
|
||||
.putString("primary_server", DNSServerHelper.getPrimary())
|
||||
.putString("secondary_server", DNSServerHelper.getSecondary())
|
||||
.putString("primary_server", DnsServerHelper.getPrimary())
|
||||
.putString("secondary_server", DnsServerHelper.getSecondary())
|
||||
.apply();
|
||||
|
||||
addPreferencesFromResource(R.xml.perf_settings);
|
||||
@ -40,11 +40,11 @@ public class GlobalConfigFragment extends PreferenceFragmentCompat {
|
||||
}}) {
|
||||
ListPreference listPref = findPreference(k);
|
||||
listPref.setVisible(visible);
|
||||
listPref.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
|
||||
listPref.setEntryValues(DNSServerHelper.getIds());
|
||||
listPref.setSummary(DNSServerHelper.getDescription(listPref.getValue(), Daedalus.getInstance()));
|
||||
listPref.setEntries(DnsServerHelper.getNames(Daedalus.getInstance()));
|
||||
listPref.setEntryValues(DnsServerHelper.getIds());
|
||||
listPref.setSummary(DnsServerHelper.getDescription(listPref.getValue(), Daedalus.getInstance()));
|
||||
listPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
preference.setSummary(DNSServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
|
||||
preference.setSummary(DnsServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public class HomeFragment extends ToolbarFragment {
|
||||
}
|
||||
|
||||
private void updateUserInterface() {
|
||||
Log.d("DMainFragment", "updateInterface");
|
||||
Button but = getView().findViewById(R.id.button_activate);
|
||||
if (DaedalusVpnService.isActivated()) {
|
||||
but.setText(R.string.button_text_deactivate);
|
||||
|
@ -10,7 +10,7 @@ import okhttp3.OkHttpClient;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||
import org.minidns.dnsmessage.DnsMessage;
|
||||
import org.pcap4j.packet.IpPacket;
|
||||
import org.pcap4j.packet.IpSelector;
|
||||
@ -58,8 +58,8 @@ abstract public class HttpsProvider extends Provider {
|
||||
.header("Accept", accept)
|
||||
.build()))
|
||||
.dns(hostname -> {
|
||||
if (DNSServerHelper.domainCache.containsKey(hostname)) {
|
||||
return DNSServerHelper.domainCache.get(hostname);
|
||||
if (DnsServerHelper.domainCache.containsKey(hostname)) {
|
||||
return DnsServerHelper.domainCache.get(hostname);
|
||||
}
|
||||
return Arrays.asList(InetAddress.getAllByName(hostname));
|
||||
})
|
||||
@ -138,7 +138,7 @@ abstract public class HttpsProvider extends Provider {
|
||||
return;
|
||||
String uri;
|
||||
try {
|
||||
uri = service.dnsServers.get(destAddr.getHostAddress());//https uri
|
||||
uri = service.dnsServers.get(destAddr.getHostAddress()).getAddress();//https uri
|
||||
} catch (Exception e) {
|
||||
Logger.logException(e);
|
||||
return;
|
||||
@ -161,7 +161,7 @@ abstract public class HttpsProvider extends Provider {
|
||||
return;
|
||||
}
|
||||
if (dnsMsg.getQuestion() == null) {
|
||||
Log.i(TAG, "handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
|
||||
Logger.debug("handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,6 @@ public class ProviderPicker {
|
||||
}
|
||||
|
||||
public static int getDnsQueryMethod() {
|
||||
return Integer.valueOf(Daedalus.getPrefs().getString("settings_dns_query_method", "0"));
|
||||
return Integer.parseInt(Daedalus.getPrefs().getString("settings_dns_query_method", "0"));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.AbstractDnsServer;
|
||||
import org.pcap4j.packet.IpPacket;
|
||||
|
||||
import java.io.*;
|
||||
@ -123,7 +123,7 @@ public class TcpProvider extends UdpProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) throws DaedalusVpnService.VpnNetworkException {
|
||||
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket, AbstractDnsServer dnsServer) throws DaedalusVpnService.VpnNetworkException {
|
||||
Socket dnsSocket;
|
||||
try {
|
||||
// Packets to be sent to the real DNS server will need to be protected from the VPN
|
||||
@ -131,7 +131,7 @@ public class TcpProvider extends UdpProvider {
|
||||
|
||||
service.protect(dnsSocket);
|
||||
|
||||
SocketAddress address = new InetSocketAddress(outPacket.getAddress(), DNSServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
|
||||
SocketAddress address = new InetSocketAddress(outPacket.getAddress(), dnsServer.getPort());
|
||||
dnsSocket.connect(address, 5000);
|
||||
dnsSocket.setSoTimeout(5000);
|
||||
Logger.info("TcpProvider: Sending DNS query request");
|
||||
|
@ -3,7 +3,7 @@ package org.itxtech.daedalus.provider;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.AbstractDnsServer;
|
||||
import org.pcap4j.packet.IpPacket;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
@ -28,13 +28,12 @@ public class TlsProvider extends TcpProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) {
|
||||
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket, AbstractDnsServer dnsServer) {
|
||||
Socket dnsSocket;
|
||||
try {
|
||||
SSLContext context = SSLContext.getInstance("TLSv1.2");
|
||||
context.init(null, null, null);
|
||||
dnsSocket = context.getSocketFactory().createSocket(outPacket.getAddress(),
|
||||
DNSServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
|
||||
dnsSocket = context.getSocketFactory().createSocket(outPacket.getAddress(), dnsServer.getPort());
|
||||
//Create TLS v1.2 socket
|
||||
//TODO: SNI
|
||||
|
||||
|
@ -9,7 +9,7 @@ import androidx.annotation.NonNull;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.AbstractDnsServer;
|
||||
import org.minidns.dnsmessage.DnsMessage;
|
||||
import org.pcap4j.packet.IpPacket;
|
||||
import org.pcap4j.packet.IpSelector;
|
||||
@ -118,7 +118,7 @@ public class UdpProvider extends Provider {
|
||||
}
|
||||
}
|
||||
|
||||
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) throws DaedalusVpnService.VpnNetworkException {
|
||||
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket, AbstractDnsServer dnsServer) throws DaedalusVpnService.VpnNetworkException {
|
||||
DatagramSocket dnsSocket;
|
||||
try {
|
||||
// Packets to be sent to the real DNS server will need to be protected from the VPN
|
||||
@ -158,7 +158,6 @@ public class UdpProvider extends Provider {
|
||||
*/
|
||||
@Override
|
||||
protected void handleDnsRequest(byte[] packetData) throws DaedalusVpnService.VpnNetworkException {
|
||||
|
||||
IpPacket parsedPacket;
|
||||
try {
|
||||
parsedPacket = (IpPacket) IpSelector.newPacket(packetData, 0, packetData.length);
|
||||
@ -169,17 +168,20 @@ public class UdpProvider extends Provider {
|
||||
|
||||
if (!(parsedPacket.getPayload() instanceof UdpPacket)) {
|
||||
try {
|
||||
Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload());
|
||||
Logger.debug("handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
InetAddress destAddr = parsedPacket.getHeader().getDstAddr();
|
||||
if (destAddr == null)
|
||||
if (destAddr == null) {
|
||||
return;
|
||||
}
|
||||
AbstractDnsServer dnsServer;
|
||||
try {
|
||||
destAddr = InetAddress.getByName(service.dnsServers.get(destAddr.getHostAddress()));
|
||||
dnsServer = service.dnsServers.get(destAddr.getHostAddress());
|
||||
destAddr = InetAddress.getByName(dnsServer.getHostAddress());
|
||||
} catch (Exception e) {
|
||||
Logger.logException(e);
|
||||
Logger.error("handleDnsRequest: DNS server alias query failed for " + destAddr.getHostAddress());
|
||||
@ -194,9 +196,8 @@ public class UdpProvider extends Provider {
|
||||
// Let's be nice to Firefox. Firefox uses an empty UDP packet to
|
||||
// the gateway to reduce the RTT. For further details, please see
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=888268
|
||||
DatagramPacket outPacket = new DatagramPacket(new byte[0], 0, 0, destAddr,
|
||||
DNSServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
|
||||
forwardPacket(outPacket, null);
|
||||
DatagramPacket outPacket = new DatagramPacket(new byte[0], 0, 0, destAddr, dnsServer.getPort());
|
||||
forwardPacket(outPacket, null, dnsServer);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -212,14 +213,13 @@ public class UdpProvider extends Provider {
|
||||
return;
|
||||
}
|
||||
if (dnsMsg.getQuestion() == null) {
|
||||
Log.i(TAG, "handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
|
||||
Logger.debug("handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resolve(parsedPacket, dnsMsg)) {
|
||||
DatagramPacket outPacket = new DatagramPacket(dnsRawData, 0, dnsRawData.length, destAddr,
|
||||
DNSServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
|
||||
forwardPacket(outPacket, parsedPacket);
|
||||
DatagramPacket outPacket = new DatagramPacket(dnsRawData, 0, dnsRawData.length, destAddr, dnsServer.getPort());
|
||||
forwardPacket(outPacket, parsedPacket, dnsServer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.itxtech.daedalus.util.server;
|
||||
package org.itxtech.daedalus.server;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -11,17 +11,26 @@ package org.itxtech.daedalus.util.server;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class AbstractDNSServer {
|
||||
public class AbstractDnsServer {
|
||||
public static final int DNS_SERVER_DEFAULT_PORT = 53;
|
||||
|
||||
protected String address;
|
||||
protected int port;
|
||||
protected String hostAddress;
|
||||
|
||||
public AbstractDNSServer(String address, int port) {
|
||||
public AbstractDnsServer(String address, int port) {
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setHostAddress(String hostAddress) {
|
||||
this.hostAddress = hostAddress;
|
||||
}
|
||||
|
||||
public String getHostAddress() {
|
||||
return hostAddress;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.itxtech.daedalus.util.server;
|
||||
package org.itxtech.daedalus.server;
|
||||
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
|
||||
@ -13,11 +13,11 @@ import org.itxtech.daedalus.Daedalus;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class CustomDNSServer extends AbstractDNSServer {
|
||||
public class CustomDnsServer extends AbstractDnsServer {
|
||||
private String name;
|
||||
private String id;
|
||||
|
||||
public CustomDNSServer(String name, String address, int port) {
|
||||
public CustomDnsServer(String name, String address, int port) {
|
||||
super(address, port);
|
||||
this.name = name;
|
||||
this.id = String.valueOf(Daedalus.configurations.getNextDnsId());
|
@ -1,4 +1,4 @@
|
||||
package org.itxtech.daedalus.util.server;
|
||||
package org.itxtech.daedalus.server;
|
||||
|
||||
import android.content.Context;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
@ -14,23 +14,27 @@ import org.itxtech.daedalus.Daedalus;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DNSServer extends AbstractDNSServer {
|
||||
public class DnsServer extends AbstractDnsServer {
|
||||
|
||||
private static int totalId = 0;
|
||||
|
||||
private String id;
|
||||
private int description;
|
||||
|
||||
public DNSServer(String address, int description, int port) {
|
||||
public DnsServer(String address, int description, int port) {
|
||||
super(address, port);
|
||||
this.id = String.valueOf(totalId++);
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public DNSServer(String address, int description) {
|
||||
public DnsServer(String address, int description) {
|
||||
this(address, description, DNS_SERVER_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
public DnsServer(String address) {
|
||||
this(address, 0);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.itxtech.daedalus.util.server;
|
||||
package org.itxtech.daedalus.server;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
@ -25,31 +25,19 @@ import java.util.List;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DNSServerHelper {
|
||||
private static HashMap<String, Integer> portCache = new HashMap<>();
|
||||
public class DnsServerHelper {
|
||||
public static HashMap<String, List<InetAddress>> domainCache = new HashMap<>();
|
||||
|
||||
public static void clearCache() {
|
||||
portCache = new HashMap<>();
|
||||
domainCache = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void buildCache() {
|
||||
domainCache = new HashMap<>();
|
||||
portCache = new HashMap<>();
|
||||
|
||||
if (ProviderPicker.getDnsQueryMethod() >= ProviderPicker.DNS_QUERY_METHOD_HTTPS_IETF &&
|
||||
!Daedalus.getPrefs().getBoolean("settings_dont_build_doh_cache", false)) {
|
||||
buildDomainCache(getAddressById(getPrimary()));
|
||||
buildDomainCache(getAddressById(getSecondary()));
|
||||
}
|
||||
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
portCache.put(server.getAddress(), server.getPort());
|
||||
}
|
||||
|
||||
for (CustomDNSServer server : Daedalus.configurations.getCustomDNSServers()) {
|
||||
portCache.put(server.getAddress(), server.getPort());
|
||||
!Daedalus.getPrefs().getBoolean("settings_dont_build_cache", false)) {
|
||||
buildDomainCache(getServerById(getPrimary()).getAddress());
|
||||
buildDomainCache(getServerById(getSecondary()).getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,16 +51,6 @@ public class DNSServerHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getPortOrDefault(InetAddress address, int defaultPort) {
|
||||
String hostAddress = address.getHostAddress();
|
||||
|
||||
if (portCache.containsKey(hostAddress)) {
|
||||
return portCache.get(hostAddress);
|
||||
}
|
||||
|
||||
return defaultPort;
|
||||
}
|
||||
|
||||
public static int getPosition(String id) {
|
||||
int intId = Integer.parseInt(id);
|
||||
if (intId < Daedalus.DNS_SERVERS.size()) {
|
||||
@ -88,18 +66,18 @@ public class DNSServerHelper {
|
||||
}
|
||||
|
||||
public static String getPrimary() {
|
||||
return String.valueOf(DNSServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("primary_server", "0"))));
|
||||
return String.valueOf(DnsServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("primary_server", "0"))));
|
||||
}
|
||||
|
||||
public static String getSecondary() {
|
||||
return String.valueOf(DNSServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("secondary_server", "1"))));
|
||||
return String.valueOf(DnsServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("secondary_server", "1"))));
|
||||
}
|
||||
|
||||
private static int checkServerId(int id) {
|
||||
if (id < Daedalus.DNS_SERVERS.size()) {
|
||||
return id;
|
||||
}
|
||||
for (CustomDNSServer server : Daedalus.configurations.getCustomDNSServers()) {
|
||||
for (CustomDnsServer server : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (server.getId().equals(String.valueOf(id))) {
|
||||
return id;
|
||||
}
|
||||
@ -107,26 +85,26 @@ public class DNSServerHelper {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String getAddressById(String id) {
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
public static AbstractDnsServer getServerById(String id) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
if (server.getId().equals(id)) {
|
||||
return server.getAddress();
|
||||
return server;
|
||||
}
|
||||
}
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (customDNSServer.getId().equals(id)) {
|
||||
return customDNSServer.getAddress();
|
||||
return customDNSServer;
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
||||
return Daedalus.DNS_SERVERS.get(0);
|
||||
}
|
||||
|
||||
public static String[] getIds() {
|
||||
ArrayList<String> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
servers.add(server.getId());
|
||||
}
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
servers.add(customDNSServer.getId());
|
||||
}
|
||||
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
|
||||
@ -135,30 +113,30 @@ public class DNSServerHelper {
|
||||
|
||||
public static String[] getNames(Context context) {
|
||||
ArrayList<String> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
servers.add(server.getStringDescription(context));
|
||||
}
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
servers.add(customDNSServer.getName());
|
||||
}
|
||||
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
|
||||
return servers.toArray(stringServers);
|
||||
}
|
||||
|
||||
public static ArrayList<AbstractDNSServer> getAllServers() {
|
||||
ArrayList<AbstractDNSServer> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
|
||||
public static ArrayList<AbstractDnsServer> getAllServers() {
|
||||
ArrayList<AbstractDnsServer> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
|
||||
servers.addAll(Daedalus.DNS_SERVERS);
|
||||
servers.addAll(Daedalus.configurations.getCustomDNSServers());
|
||||
return servers;
|
||||
}
|
||||
|
||||
public static String getDescription(String id, Context context) {
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
if (server.getId().equals(id)) {
|
||||
return server.getStringDescription(context);
|
||||
}
|
||||
}
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (customDNSServer.getId().equals(id)) {
|
||||
return customDNSServer.getName();
|
||||
}
|
||||
@ -166,7 +144,7 @@ public class DNSServerHelper {
|
||||
return Daedalus.DNS_SERVERS.get(0).getStringDescription(context);
|
||||
}
|
||||
|
||||
public static boolean isInUsing(CustomDNSServer server) {
|
||||
public static boolean isInUsing(CustomDnsServer server) {
|
||||
return DaedalusVpnService.isActivated() && (server.getId().equals(getPrimary()) || server.getId().equals(getSecondary()));
|
||||
}
|
||||
}
|
@ -21,7 +21,8 @@ import org.itxtech.daedalus.provider.ProviderPicker;
|
||||
import org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.RuleResolver;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.itxtech.daedalus.server.AbstractDnsServer;
|
||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
@ -51,8 +52,8 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
private static final String CHANNEL_ID = "daedalus_channel_1";
|
||||
private static final String CHANNEL_NAME = "daedalus_channel";
|
||||
|
||||
public static String primaryServer;
|
||||
public static String secondaryServer;
|
||||
public static AbstractDnsServer primaryServer;
|
||||
public static AbstractDnsServer secondaryServer;
|
||||
|
||||
private NotificationCompat.Builder notification = null;
|
||||
|
||||
@ -64,7 +65,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
|
||||
private Thread mThread = null;
|
||||
|
||||
public HashMap<String, String> dnsServers;
|
||||
public HashMap<String, AbstractDnsServer> dnsServers;
|
||||
|
||||
private static boolean activated = false;
|
||||
|
||||
@ -185,7 +186,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
|
||||
if (shouldRefresh) {
|
||||
RuleResolver.clear();
|
||||
DNSServerHelper.clearCache();
|
||||
DnsServerHelper.clearCache();
|
||||
Logger.info("Daedalus VPN service has stopped");
|
||||
}
|
||||
|
||||
@ -202,27 +203,29 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
stopThread();
|
||||
}
|
||||
|
||||
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, String addr) throws UnknownHostException {
|
||||
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, AbstractDnsServer addr) throws UnknownHostException {
|
||||
int size = dnsServers.size();
|
||||
size++;
|
||||
if (addr.contains("/")) {//https uri
|
||||
if (addr.getAddress().contains("/")) {//https uri
|
||||
String alias = String.format(format, size + 1);
|
||||
dnsServers.put(alias, addr);
|
||||
builder.addRoute(alias, 32);
|
||||
return InetAddress.getByName(alias);
|
||||
}
|
||||
InetAddress address = InetAddress.getByName(addr);
|
||||
InetAddress address = InetAddress.getByName(addr.getAddress());
|
||||
if (address instanceof Inet6Address && ipv6Template == null) {
|
||||
Log.i(TAG, "addDnsServer: Ignoring DNS server " + address);
|
||||
} else if (address instanceof Inet4Address) {
|
||||
String alias = String.format(format, size + 1);
|
||||
dnsServers.put(alias, address.getHostAddress());
|
||||
addr.setHostAddress(address.getHostAddress());
|
||||
dnsServers.put(alias, addr);
|
||||
builder.addRoute(alias, 32);
|
||||
return InetAddress.getByName(alias);
|
||||
} else if (address instanceof Inet6Address) {
|
||||
ipv6Template[ipv6Template.length - 1] = (byte) (size + 1);
|
||||
InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
|
||||
dnsServers.put(i6addr.getHostAddress(), address.getHostAddress());
|
||||
addr.setHostAddress(address.getHostAddress());
|
||||
dnsServers.put(i6addr.getHostAddress(), addr);
|
||||
return i6addr;
|
||||
}
|
||||
return null;
|
||||
@ -231,7 +234,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
DNSServerHelper.buildCache();
|
||||
DnsServerHelper.buildCache();
|
||||
Builder builder = new Builder()
|
||||
.setSession("Daedalus")
|
||||
.setConfigureIntent(PendingIntent.getActivity(this, 0,
|
||||
@ -275,7 +278,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
statisticQuery = Daedalus.getPrefs().getBoolean("settings_count_query_times", false);
|
||||
byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
if (primaryServer.contains(":") || secondaryServer.contains(":")) {//IPv6
|
||||
if (primaryServer.getAddress().contains(":") || secondaryServer.getAddress().contains(":")) {//IPv6
|
||||
try {
|
||||
InetAddress addr = Inet6Address.getByAddress(ipv6Template);
|
||||
Log.d(TAG, "configure: Adding IPv6 address" + addr);
|
||||
@ -296,15 +299,13 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
aliasPrimary = addDnsServer(builder, format, ipv6Template, primaryServer);
|
||||
aliasSecondary = addDnsServer(builder, format, ipv6Template, secondaryServer);
|
||||
} else {
|
||||
aliasPrimary = InetAddress.getByName(primaryServer);
|
||||
aliasSecondary = InetAddress.getByName(secondaryServer);
|
||||
aliasPrimary = InetAddress.getByName(primaryServer.getAddress());
|
||||
aliasSecondary = InetAddress.getByName(secondaryServer.getAddress());
|
||||
}
|
||||
|
||||
InetAddress primaryDNSServer = aliasPrimary;
|
||||
InetAddress secondaryDNSServer = aliasSecondary;
|
||||
Logger.info("Daedalus VPN service is listening on " + primaryServer + " as " + primaryDNSServer.getHostAddress());
|
||||
Logger.info("Daedalus VPN service is listening on " + secondaryServer + " as " + secondaryDNSServer.getHostAddress());
|
||||
builder.addDnsServer(primaryDNSServer).addDnsServer(secondaryDNSServer);
|
||||
Logger.info("Daedalus VPN service is listening on " + primaryServer + " as " + aliasPrimary.getHostAddress());
|
||||
Logger.info("Daedalus VPN service is listening on " + secondaryServer + " as " + aliasSecondary.getHostAddress());
|
||||
builder.addDnsServer(aliasPrimary).addDnsServer(aliasSecondary);
|
||||
|
||||
if (advanced) {
|
||||
builder.setBlocking(true);
|
||||
|
@ -3,7 +3,7 @@ package org.itxtech.daedalus.util;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.util.server.CustomDNSServer;
|
||||
import org.itxtech.daedalus.server.CustomDnsServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -27,7 +27,7 @@ public class Configurations {
|
||||
|
||||
private static File file;
|
||||
|
||||
private ArrayList<CustomDNSServer> customDNSServers;
|
||||
private ArrayList<CustomDnsServer> customDNSServers;
|
||||
private ArrayList<String> appObjects;
|
||||
|
||||
private ArrayList<Rule> hostsRules;
|
||||
@ -60,7 +60,7 @@ public class Configurations {
|
||||
this.activateCounter = activateCounter;
|
||||
}
|
||||
|
||||
public ArrayList<CustomDNSServer> getCustomDNSServers() {
|
||||
public ArrayList<CustomDnsServer> getCustomDNSServers() {
|
||||
if (customDNSServers == null) {
|
||||
customDNSServers = new ArrayList<>();
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
||||
<string name="settings_manual_summary">访问 GitHub wiki 页面。</string>
|
||||
<string name="settings_log_size">日志大小限制</string>
|
||||
<string name="settings_debug_output">调试输出</string>
|
||||
<string name="settings_dont_build_doh_cache">不缓存 DoH DNS 的 IP地址</string>
|
||||
<string name="settings_dont_build_cache">不缓存 DNS 的 IP地址</string>
|
||||
<string name="settings_dark_theme">使用暗主题</string>
|
||||
<string name="settings_dns_query_method">DNS 查询方式</string>
|
||||
<string name="settings_foreground">运行前台服务</string>
|
||||
|
@ -62,7 +62,7 @@
|
||||
<string name="settings_manual_summary">造訪 GitHub wiki 頁面。</string>
|
||||
<string name="settings_log_size">紀錄檔大小限制</string>
|
||||
<string name="settings_debug_output">调试输出 TODO</string>
|
||||
<string name="settings_dont_build_doh_cache">不緩存 DoH DNS 的 IP地址</string>
|
||||
<string name="settings_dont_build_cache">不緩存 DNS 的 IP地址</string>
|
||||
<string name="settings_dark_theme">使用暗主题</string>
|
||||
|
||||
<string name="settings_rule_name">規則名稱</string>
|
||||
|
@ -60,7 +60,7 @@
|
||||
<string name="settings_log_size">Log Size Limit</string>
|
||||
<string name="settings_manual">Manual</string>
|
||||
<string name="settings_manual_summary">Visit GitHub wiki page.</string>
|
||||
<string name="settings_dont_build_doh_cache">Don\'t build DNS Cache for DoH DNS</string>
|
||||
<string name="settings_dont_build_cache">Don\'t cache ip for DNS servers</string>
|
||||
<string name="settings_debug_output">Debug Output</string>
|
||||
<string name="settings_dark_theme">Use Dark Theme</string>
|
||||
<string name="settings_dns_query_method">DNS Query Method</string>
|
||||
|
@ -92,8 +92,8 @@
|
||||
android:defaultValue="false"
|
||||
android:enabled="false"/>
|
||||
<SwitchPreference
|
||||
android:key="settings_dont_build_doh_cache"
|
||||
android:title="@string/settings_dont_build_doh_cache"
|
||||
android:key="settings_dont_build_cache"
|
||||
android:title="@string/settings_dont_build_cache"
|
||||
android:defaultValue="false"
|
||||
android:enabled="false"/>
|
||||
<ListPreference
|
||||
|
Loading…
Reference in New Issue
Block a user