Improved DNS server structure
This commit is contained in:
parent
5a8fd1ee82
commit
b9ff5188f4
BIN
app/src/main/assets/about_html/favicon.ico
Normal file
BIN
app/src/main/assets/about_html/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
@ -53,6 +53,7 @@
|
||||
<img width="185" height="55" src="cutedns_logo.png">
|
||||
<br>
|
||||
<br>
|
||||
<img width="100" height="100" src="favicon.ico"><br>
|
||||
<div style="font-size: 25px;"><a href="http://puredns.cn">Pure DNS</a></div>
|
||||
<br>
|
||||
<div style="font-size: 25px;"><a href="https://aixyz.com">AIXYZ DNS</a></div>
|
||||
@ -69,8 +70,7 @@
|
||||
<br>
|
||||
<div style="font-size: 10px; color: gray;">
|
||||
This program is free software: you can redistribute it and/or modify<br>
|
||||
it under the terms of the GNU General Public License as
|
||||
published by<br>
|
||||
it under the terms of the GNU General Public License as published by<br>
|
||||
the Free Software Foundation, either version 3 of the License, or<br>
|
||||
(at your option) any later version.<br>
|
||||
<br>
|
||||
|
@ -53,6 +53,7 @@
|
||||
<img width="185" height="55" src="cutedns_logo.png">
|
||||
<br>
|
||||
<br>
|
||||
<img width="100" height="100" src="favicon.ico"><br>
|
||||
<div style="font-size: 25px;"><a href="http://puredns.cn">Pure DNS</a></div>
|
||||
<br>
|
||||
<div style="font-size: 25px;"><a href="https://aixyz.com">AIXYZ DNS</a></div>
|
||||
@ -69,8 +70,7 @@
|
||||
<br>
|
||||
<div style="font-size: 10px; color: gray;">
|
||||
This program is free software: you can redistribute it and/or modify<br>
|
||||
it under the terms of the GNU General Public License as
|
||||
published by<br>
|
||||
it under the terms of the GNU General Public License as published by<br>
|
||||
the Free Software Foundation, either version 3 of the License, or<br>
|
||||
(at your option) any later version.<br>
|
||||
<br>
|
||||
|
@ -19,7 +19,11 @@ import com.google.gson.JsonParseException;
|
||||
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.Configurations;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.Rule;
|
||||
import org.itxtech.daedalus.util.RulesResolver;
|
||||
import org.itxtech.daedalus.util.server.DNSServer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -49,12 +53,12 @@ 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("115.159.220.214", R.string.server_puredns_east_china));
|
||||
add(new DnsServer("123.207.137.88", R.string.server_puredns_north_china));
|
||||
add(new DnsServer("115.159.146.99", R.string.server_aixyz_east_china));
|
||||
add(new DnsServer("123.206.21.48", R.string.server_aixyz_south_china));
|
||||
add(new DnsServer("119.29.105.234", R.string.server_cutedns_south_china));
|
||||
public static final List<DNSServer> DNS_SERVERS = new ArrayList<DNSServer>() {{
|
||||
add(new DNSServer("115.159.220.214", R.string.server_puredns_east_china));
|
||||
add(new DNSServer("123.207.137.88", R.string.server_puredns_north_china));
|
||||
add(new DNSServer("115.159.146.99", R.string.server_aixyz_east_china));
|
||||
add(new DNSServer("123.206.21.48", R.string.server_aixyz_south_china));
|
||||
add(new DNSServer("119.29.105.234", R.string.server_cutedns_south_china));
|
||||
}};
|
||||
|
||||
public static final List<Rule> RULES = new ArrayList<Rule>() {{
|
||||
|
@ -26,7 +26,7 @@ import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.fragment.*;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -175,8 +175,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
if (result == Activity.RESULT_OK) {
|
||||
DaedalusVpnService.primaryServer = DnsServerHelper.getAddressById(DnsServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DnsServerHelper.getAddressById(DnsServerHelper.getSecondary());
|
||||
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
|
||||
|
||||
Daedalus.getInstance().startService(Daedalus.getInstance().getServiceIntent().setAction(DaedalusVpnService.ACTION_ACTIVATE));
|
||||
|
||||
|
@ -13,8 +13,8 @@ import android.view.ViewGroup;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.ConfigActivity;
|
||||
import org.itxtech.daedalus.util.CustomDnsServer;
|
||||
import org.itxtech.daedalus.util.DnsServer;
|
||||
import org.itxtech.daedalus.util.server.CustomDNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServer;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -70,7 +70,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());
|
||||
@ -80,7 +80,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);
|
||||
}
|
||||
@ -104,9 +104,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));
|
||||
@ -120,7 +120,7 @@ public class DnsServerConfigFragment extends ConfigFragment {
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Daedalus.configurations.getCustomDnsServers().remove(index);
|
||||
Daedalus.configurations.getCustomDNSServers().remove(index);
|
||||
getActivity().finish();
|
||||
}
|
||||
})
|
||||
|
@ -14,8 +14,8 @@ import android.widget.TextView;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.ConfigActivity;
|
||||
import org.itxtech.daedalus.util.CustomDnsServer;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.server.CustomDNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -30,7 +30,7 @@ import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
*/
|
||||
public class DnsServersFragment extends ToolbarFragment {
|
||||
private DnsServersFragment.DnsServerAdapter adapter;
|
||||
private CustomDnsServer server = null;
|
||||
private CustomDNSServer server = null;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@ -45,8 +45,8 @@ public class DnsServersFragment extends ToolbarFragment {
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
if (viewHolder instanceof ViewHolder) {
|
||||
int index = ((ViewHolder) viewHolder).getIndex();
|
||||
if (index < Daedalus.configurations.getCustomDnsServers().size() &&
|
||||
DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDnsServers().get(index))) {
|
||||
if (index < Daedalus.configurations.getCustomDNSServers().size() &&
|
||||
DNSServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -61,8 +61,8 @@ public class DnsServersFragment extends ToolbarFragment {
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
int position = viewHolder.getAdapterPosition();
|
||||
server = Daedalus.configurations.getCustomDnsServers().get(position);
|
||||
Daedalus.configurations.getCustomDnsServers().remove(position);
|
||||
server = Daedalus.configurations.getCustomDNSServers().get(position);
|
||||
Daedalus.configurations.getCustomDNSServers().remove(position);
|
||||
Snackbar.make(view, R.string.action_removed, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.action_undo, new SnackbarClickListener(position)).show();
|
||||
adapter.notifyItemRemoved(position);
|
||||
@ -98,7 +98,7 @@ public class DnsServersFragment extends ToolbarFragment {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Daedalus.configurations.getCustomDnsServers().add(position, server);
|
||||
Daedalus.configurations.getCustomDNSServers().add(position, server);
|
||||
adapter.notifyItemInserted(position);
|
||||
}
|
||||
}
|
||||
@ -122,7 +122,7 @@ public class DnsServersFragment extends ToolbarFragment {
|
||||
private class DnsServerAdapter extends RecyclerView.Adapter<ViewHolder> {
|
||||
@Override
|
||||
public void onBindViewHolder(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.getAddress() + ":" + server.getPort());
|
||||
@ -130,7 +130,7 @@ public class DnsServersFragment extends ToolbarFragment {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return Daedalus.configurations.getCustomDnsServers().size();
|
||||
return Daedalus.configurations.getCustomDNSServers().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -162,7 +162,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)
|
||||
|
@ -16,8 +16,9 @@ import de.measite.minidns.Record;
|
||||
import de.measite.minidns.source.NetworkDataSource;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.AbstractDNSServer;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
@ -46,17 +47,13 @@ public class DnsTestFragment extends ToolbarFragment {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private Record.TYPE getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,9 +68,9 @@ public class DnsTestFragment extends ToolbarFragment {
|
||||
final TextView textViewTestInfo = (TextView) view.findViewById(R.id.textView_test_info);
|
||||
|
||||
final Spinner spinnerServerChoice = (Spinner) view.findViewById(R.id.spinner_server_choice);
|
||||
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, DnsServerHelper.getNames(Daedalus.getInstance()));
|
||||
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));
|
||||
@ -101,21 +98,21 @@ public class DnsTestFragment extends ToolbarFragment {
|
||||
ArrayAdapter<Type> typeAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, types);
|
||||
spinnerType.setAdapter(typeAdapter);
|
||||
|
||||
final AutoCompleteTextView textViewTestUrl = (AutoCompleteTextView) view.findViewById(R.id.autoCompleteTextView_test_url);
|
||||
final AutoCompleteTextView textViewTestDomain = (AutoCompleteTextView) view.findViewById(R.id.autoCompleteTextView_test_url);
|
||||
ArrayAdapter autoCompleteArrayAdapter = new ArrayAdapter<>(Daedalus.getInstance(), android.R.layout.simple_list_item_1, Daedalus.DEFAULT_TEST_DOMAINS);
|
||||
textViewTestUrl.setAdapter(autoCompleteArrayAdapter);
|
||||
textViewTestDomain.setAdapter(autoCompleteArrayAdapter);
|
||||
|
||||
mRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String testDomain = textViewTestUrl.getText().toString();
|
||||
String testDomain = textViewTestDomain.getText().toString();
|
||||
if (testDomain.equals("")) {
|
||||
testDomain = Daedalus.DEFAULT_TEST_DOMAINS[0];
|
||||
}
|
||||
StringBuilder testText = new StringBuilder();
|
||||
ArrayList<String> dnsServers = new ArrayList<String>() {{
|
||||
add(DnsServerHelper.getAddressByDescription(Daedalus.getInstance(), spinnerServerChoice.getSelectedItem().toString()));
|
||||
add(((AbstractDNSServer) spinnerServerChoice.getSelectedItem()).getAddress());
|
||||
String servers = Daedalus.getPrefs().getString("dns_test_servers", "");
|
||||
if (!servers.equals("")) {
|
||||
addAll(Arrays.asList(servers.split(",")));
|
||||
@ -134,7 +131,7 @@ public class DnsTestFragment extends ToolbarFragment {
|
||||
|
||||
|
||||
private StringBuilder testServer(DNSQuery dnsQuery, Record.TYPE type, String server, String domain, StringBuilder testText) {
|
||||
Logger.debug("Testing DNS " + server);
|
||||
Logger.debug("Testing DNS server" + server);
|
||||
testText.append(getString(R.string.test_domain)).append(" ").append(domain).append("\n").append(getString(R.string.test_dns_server)).append(" ").append(server);
|
||||
|
||||
mHandler.obtainMessage(DnsTestHandler.MSG_DISPLAY_STATUS, testText.toString()).sendToTarget();
|
||||
|
@ -9,7 +9,7 @@ import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -29,20 +29,20 @@ public class GlobalConfigFragment extends PreferenceFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
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);
|
||||
|
||||
ListPreference primaryServer = (ListPreference) findPreference("primary_server");
|
||||
primaryServer.setEntries(DnsServerHelper.getNames(Daedalus.getInstance()));
|
||||
primaryServer.setEntryValues(DnsServerHelper.getIds());
|
||||
primaryServer.setSummary(DnsServerHelper.getDescription(primaryServer.getValue(), Daedalus.getInstance()));
|
||||
primaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
|
||||
primaryServer.setEntryValues(DNSServerHelper.getIds());
|
||||
primaryServer.setSummary(DNSServerHelper.getDescription(primaryServer.getValue(), Daedalus.getInstance()));
|
||||
primaryServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
preference.setSummary(DnsServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
|
||||
preference.setSummary(DNSServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
|
||||
Snackbar.make(getView(), R.string.notice_need_restart, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
return true;
|
||||
@ -50,13 +50,13 @@ public class GlobalConfigFragment extends PreferenceFragment {
|
||||
});
|
||||
|
||||
ListPreference secondaryServer = (ListPreference) findPreference("secondary_server");
|
||||
secondaryServer.setEntries(DnsServerHelper.getNames(Daedalus.getInstance()));
|
||||
secondaryServer.setEntryValues(DnsServerHelper.getIds());
|
||||
secondaryServer.setSummary(DnsServerHelper.getDescription(secondaryServer.getValue(), Daedalus.getInstance()));
|
||||
secondaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
|
||||
secondaryServer.setEntryValues(DNSServerHelper.getIds());
|
||||
secondaryServer.setSummary(DNSServerHelper.getDescription(secondaryServer.getValue(), Daedalus.getInstance()));
|
||||
secondaryServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
preference.setSummary(DnsServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
|
||||
preference.setSummary(DNSServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
|
||||
Snackbar.make(getView(), R.string.notice_need_restart, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
return true;
|
||||
|
@ -9,8 +9,8 @@ import android.system.OsConstants;
|
||||
import android.system.StructPollfd;
|
||||
import android.util.Log;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.pcap4j.packet.IpPacket;
|
||||
|
||||
import java.io.*;
|
||||
@ -136,7 +136,7 @@ public class TcpDnsProvider extends UdpDnsProvider {
|
||||
|
||||
service.protect(dnsSocket);
|
||||
|
||||
SocketAddress address = new InetSocketAddress(outPacket.getAddress(), DnsServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
|
||||
SocketAddress address = new InetSocketAddress(outPacket.getAddress(), DNSServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
|
||||
dnsSocket.connect(address, 5000);
|
||||
dnsSocket.setSoTimeout(5000);
|
||||
Logger.info("TcpDnsProvider: Sending DNS query request");
|
||||
|
@ -13,9 +13,9 @@ import de.measite.minidns.Record;
|
||||
import de.measite.minidns.record.A;
|
||||
import de.measite.minidns.util.InetAddressUtil;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.RulesResolver;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
import org.pcap4j.packet.*;
|
||||
import org.pcap4j.packet.factory.PacketFactoryPropertiesLoader;
|
||||
import org.pcap4j.util.PropertiesLoader;
|
||||
@ -325,7 +325,7 @@ public class UdpDnsProvider extends DnsProvider {
|
||||
// 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()));
|
||||
DNSServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
|
||||
forwardPacket(outPacket, null);
|
||||
return;
|
||||
}
|
||||
@ -363,7 +363,7 @@ public class UdpDnsProvider extends DnsProvider {
|
||||
} else {
|
||||
Logger.info("DnsProvider: Resolving " + dnsQueryName + " Sending to " + destAddr);
|
||||
DatagramPacket outPacket = new DatagramPacket(dnsRawData, 0, dnsRawData.length, destAddr,
|
||||
DnsServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
|
||||
DNSServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
|
||||
forwardPacket(outPacket, parsedPacket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -6,8 +6,8 @@ import android.content.Intent;
|
||||
import android.net.VpnService;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -30,8 +30,8 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
|
||||
context.startActivity(vIntent);
|
||||
}
|
||||
|
||||
DaedalusVpnService.primaryServer = DnsServerHelper.getAddressById(DnsServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DnsServerHelper.getAddressById(DnsServerHelper.getSecondary());
|
||||
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
|
||||
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
|
||||
|
||||
context.startService((new Intent(context, DaedalusVpnService.class)).setAction(DaedalusVpnService.ACTION_ACTIVATE));
|
||||
|
||||
|
@ -18,9 +18,9 @@ import org.itxtech.daedalus.provider.DnsProvider;
|
||||
import org.itxtech.daedalus.provider.TcpDnsProvider;
|
||||
import org.itxtech.daedalus.provider.UdpDnsProvider;
|
||||
import org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver;
|
||||
import org.itxtech.daedalus.util.DnsServerHelper;
|
||||
import org.itxtech.daedalus.util.Logger;
|
||||
import org.itxtech.daedalus.util.RulesResolver;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
@ -101,7 +101,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
}
|
||||
|
||||
Daedalus.initHostsResolver();
|
||||
DnsServerHelper.buildPortCache();
|
||||
DNSServerHelper.buildPortCache();
|
||||
|
||||
if (this.mThread == null) {
|
||||
this.mThread = new Thread(this, "DaedalusVpn");
|
||||
@ -157,7 +157,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
||||
|
||||
if (shouldRefresh) {
|
||||
RulesResolver.clear();
|
||||
DnsServerHelper.clearPortCache();
|
||||
DNSServerHelper.clearPortCache();
|
||||
Logger.info("Daedalus VPN service has stopped");
|
||||
}
|
||||
|
||||
|
@ -3,6 +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 java.io.File;
|
||||
import java.io.FileReader;
|
||||
@ -26,7 +27,7 @@ public class Configurations {
|
||||
|
||||
private static File file;
|
||||
|
||||
private ArrayList<CustomDnsServer> customDnsServers;
|
||||
private ArrayList<CustomDNSServer> customDNSServers;
|
||||
|
||||
private ArrayList<Rule> hostsRules;
|
||||
private ArrayList<Rule> dnsmasqRules;
|
||||
@ -36,7 +37,7 @@ public class Configurations {
|
||||
|
||||
private long activateCounter;
|
||||
|
||||
int getNextDnsId() {
|
||||
public int getNextDnsId() {
|
||||
if (totalDnsId < CUSTOM_ID_START) {
|
||||
totalDnsId = CUSTOM_ID_START;
|
||||
}
|
||||
@ -58,11 +59,11 @@ public class Configurations {
|
||||
this.activateCounter = activateCounter;
|
||||
}
|
||||
|
||||
public ArrayList<CustomDnsServer> getCustomDnsServers() {
|
||||
if (customDnsServers == null) {
|
||||
customDnsServers = new ArrayList<>();
|
||||
public ArrayList<CustomDNSServer> getCustomDNSServers() {
|
||||
if (customDNSServers == null) {
|
||||
customDNSServers = new ArrayList<>();
|
||||
}
|
||||
return customDnsServers;
|
||||
return customDNSServers;
|
||||
}
|
||||
|
||||
public ArrayList<Rule> getHostsRules() {
|
||||
|
@ -0,0 +1,47 @@
|
||||
package org.itxtech.daedalus.util.server;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
*
|
||||
* @author iTX Technologies
|
||||
* @link https://itxtech.org
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
abstract public class AbstractDNSServer {
|
||||
public static final int DNS_SERVER_DEFAULT_PORT = 53;
|
||||
|
||||
protected String address;
|
||||
protected int port;
|
||||
|
||||
public AbstractDNSServer(String address, int port) {
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.itxtech.daedalus.util;
|
||||
package org.itxtech.daedalus.util.server;
|
||||
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
|
||||
@ -13,16 +13,13 @@ 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 {
|
||||
public class CustomDNSServer extends AbstractDNSServer {
|
||||
private String name;
|
||||
private String address;
|
||||
private int port;
|
||||
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.address = address;
|
||||
this.port = port;
|
||||
this.id = String.valueOf(Daedalus.configurations.getNextDnsId());
|
||||
}
|
||||
|
||||
@ -38,23 +35,7 @@ public class CustomDnsServer {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package org.itxtech.daedalus.util;
|
||||
package org.itxtech.daedalus.util.server;
|
||||
|
||||
import android.content.Context;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -13,41 +14,33 @@ import android.content.Context;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DnsServer {
|
||||
public static int DNS_SERVER_DEFAULT_PORT = 53;
|
||||
|
||||
public class DNSServer extends AbstractDNSServer {
|
||||
|
||||
private static int totalId = 0;
|
||||
|
||||
private String id;
|
||||
private String address;
|
||||
private int port;
|
||||
private int description = 0;
|
||||
|
||||
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.address = address;
|
||||
this.description = description;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public DnsServer(String address, int description) {
|
||||
public DNSServer(String address, int description) {
|
||||
this(address, description, DNS_SERVER_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getStringDescription(Context context) {
|
||||
return context.getResources().getString(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getStringDescription(Daedalus.getInstance());
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.itxtech.daedalus.util;
|
||||
package org.itxtech.daedalus.util.server;
|
||||
|
||||
import android.content.Context;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
@ -18,7 +18,7 @@ import java.util.HashMap;
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
public class DnsServerHelper {
|
||||
public class DNSServerHelper {
|
||||
private static HashMap<String, Integer> portCache = null;
|
||||
|
||||
public static void clearPortCache() {
|
||||
@ -27,11 +27,11 @@ public class DnsServerHelper {
|
||||
|
||||
public static void buildPortCache() {
|
||||
portCache = new HashMap<>();
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
portCache.put(server.getAddress(), server.getPort());
|
||||
}
|
||||
|
||||
for (CustomDnsServer server : Daedalus.configurations.getCustomDnsServers()) {
|
||||
for (CustomDNSServer server : Daedalus.configurations.getCustomDNSServers()) {
|
||||
portCache.put(server.getAddress(), server.getPort());
|
||||
}
|
||||
|
||||
@ -53,8 +53,8 @@ public class DnsServerHelper {
|
||||
return intId;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Daedalus.configurations.getCustomDnsServers().size(); i++) {
|
||||
if (Daedalus.configurations.getCustomDnsServers().get(i).getId().equals(id)) {
|
||||
for (int i = 0; i < Daedalus.configurations.getCustomDNSServers().size(); i++) {
|
||||
if (Daedalus.configurations.getCustomDNSServers().get(i).getId().equals(id)) {
|
||||
return i + Daedalus.DNS_SERVERS.size();
|
||||
}
|
||||
}
|
||||
@ -62,18 +62,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() - 1)) {
|
||||
return id;
|
||||
}
|
||||
for (CustomDnsServer server : Daedalus.configurations.getCustomDnsServers()) {
|
||||
for (CustomDNSServer server : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (server.getId().equals(String.valueOf(id))) {
|
||||
return id;
|
||||
}
|
||||
@ -82,28 +82,28 @@ public class DnsServerHelper {
|
||||
}
|
||||
|
||||
public static String getAddressById(String id) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
if (server.getId().equals(id)) {
|
||||
return server.getAddress();
|
||||
}
|
||||
}
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
if (customDnsServer.getId().equals(id)) {
|
||||
return customDnsServer.getAddress();
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (customDNSServer.getId().equals(id)) {
|
||||
return customDNSServer.getAddress();
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
||||
}
|
||||
|
||||
public static String getAddressByDescription(Context context, String description) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
for (DNSServer server : Daedalus.DNS_SERVERS) {
|
||||
if (server.getStringDescription(context).equals(description)) {
|
||||
return server.getAddress();
|
||||
}
|
||||
}
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
if (customDnsServer.getName().equals(description)) {
|
||||
return customDnsServer.getAddress();
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (customDNSServer.getName().equals(description)) {
|
||||
return customDNSServer.getAddress();
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
||||
@ -111,11 +111,11 @@ public class DnsServerHelper {
|
||||
|
||||
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()) {
|
||||
servers.add(customDnsServer.getId());
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
servers.add(customDNSServer.getId());
|
||||
}
|
||||
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
|
||||
return servers.toArray(stringServers);
|
||||
@ -123,31 +123,38 @@ 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()) {
|
||||
servers.add(customDnsServer.getName());
|
||||
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());
|
||||
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()) {
|
||||
if (customDnsServer.getId().equals(id)) {
|
||||
return customDnsServer.getName();
|
||||
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
|
||||
if (customDNSServer.getId().equals(id)) {
|
||||
return customDNSServer.getName();
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getStringDescription(context);
|
||||
}
|
||||
|
||||
public static boolean isInUsing(CustomDnsServer server) {
|
||||
public static boolean isInUsing(CustomDNSServer server) {
|
||||
return Daedalus.getInstance().isServiceActivated() && (server.getId().equals(getPrimary()) || server.getId().equals(getSecondary()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user