Commit d3363a9a authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Don't execute the check if the given server is null

parent 41d64904
......@@ -761,7 +761,7 @@ public class MainActivity extends NavigationDrawerActivity implements RuleImport
dialog.show();
((MainFragment)currentFragment()).checkDNSReachability(new MainFragment.DNSReachabilityCallback() {
@Override
public void checkFinished(List<IPPortPair> unreachable, List<IPPortPair> reachable) {
public void checkFinished(@NonNull List<IPPortPair> unreachable, List<IPPortPair> reachable) {
dialog.dismiss();
if(unreachable.size() == 0){
MainActivity.this.runOnUiThread(new Runnable() {
......
......@@ -376,7 +376,7 @@ public class MainFragment extends Fragment {
dialog.show();
checkDNSReachability(new DNSReachabilityCallback() {
@Override
public void checkFinished(List<IPPortPair> unreachable, List<IPPortPair> reachable) {
public void checkFinished(@NonNull List<IPPortPair> unreachable, @NonNull List<IPPortPair> reachable) {
dialog.dismiss();
if(unreachable.size() == 0){
((MainActivity)requireContext()).runOnUiThread(new Runnable() {
......@@ -391,7 +391,7 @@ public class MainFragment extends Fragment {
_text = _text.replace("[x]", unreachable.size() + reachable.size() + "");
_text = _text.replace("[y]", unreachable.size() + "");
boolean customPorts = PreferencesAccessor.areCustomPortsEnabled(requireContext());
for(IPPortPair p: unreachable)builder.append("- ").append(p.formatForTextfield(customPorts)).append("\n");
for(IPPortPair p: unreachable) builder.append("- ").append(p.formatForTextfield(customPorts)).append("\n");
_text = _text.replace("[servers]", builder.toString());
final String text = _text;
((MainActivity)requireContext()).runOnUiThread(new Runnable() {
......@@ -490,13 +490,14 @@ public class MainFragment extends Fragment {
}
public static abstract class DNSReachabilityCallback{
private final List<IPPortPair> unreachable = new ArrayList<>();
private final List<IPPortPair> reachable = new ArrayList<>();
@NonNull private final List<IPPortPair> unreachable = new ArrayList<>();
@NonNull private final List<IPPortPair> reachable = new ArrayList<>();
private int servers;
public abstract void checkFinished(List<IPPortPair> unreachable, List<IPPortPair> reachable);
public abstract void checkFinished(@NonNull List<IPPortPair> unreachable, @NonNull List<IPPortPair> reachable);
public final void checkProgress(IPPortPair server, boolean reachable){
if(server == null)return;
if(!reachable)unreachable.add(server);
else this.reachable.add(server);
if(this.unreachable.size() + this.reachable.size() >= servers)checkFinished(unreachable, this.reachable);
......
......@@ -43,6 +43,7 @@ public class DNSQueryUtil {
}
public static void startDNSServerConnectivityCheck(@NonNull final IPPortPair server, @NonNull final Util.ConnectivityCheckCallback callback){
if(server == null)return;
runAsyncDNSQuery(server, "frostnerd.com", false, Type.A, DClass.ANY, new Util.DNSQueryResultListener() {
@Override
public void onSuccess(Record[] response) {
......@@ -58,6 +59,7 @@ public class DNSQueryUtil {
public static void runAsyncDNSQuery(final IPPortPair server, final String query, final boolean tcp, final int type,
final int dClass, final Util.DNSQueryResultListener resultListener, final int timeout){
if(server == null)return;
new Thread(){
@Override
public void run() {
......@@ -80,6 +82,7 @@ public class DNSQueryUtil {
public static Record[] runSyncDNSQuery(final IPPortPair server, final String query, final boolean tcp, final int type,
final int dClass, final int timeout){
if(server == null) return null;
try {
Resolver resolver = new SimpleResolver(server.getAddress());
resolver.setPort(server.getPort());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment