don't show connection error if we havent tested yet (#700)

This commit is contained in:
m2049r 2020-11-21 13:22:54 +01:00 committed by GitHub
parent 4e59be2dff
commit 08f815e830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

View File

@ -185,7 +185,6 @@ public class Dispatcher implements PeerRetriever.OnGetPeers {
public void seedPeers(Collection<NodeInfo> seedNodes) { public void seedPeers(Collection<NodeInfo> seedNodes) {
for (NodeInfo node : seedNodes) { for (NodeInfo node : seedNodes) {
node.clear();
if (node.isFavourite()) { if (node.isFavourite()) {
rpcNodes.add(node); rpcNodes.add(node);
if (listener != null) listener.onGet(node); if (listener != null) listener.onGet(node);

View File

@ -563,7 +563,6 @@ public class NodeFragment extends Fragment
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
nodeInfo.clear();
tvResult.setText(getString(R.string.node_testing, nodeInfo.getHostAddress())); tvResult.setText(getString(R.string.node_testing, nodeInfo.getHostAddress()));
} }

View File

@ -46,7 +46,7 @@ import okhttp3.ResponseBody;
import timber.log.Timber; import timber.log.Timber;
public class NodeInfo extends Node { public class NodeInfo extends Node {
final static public int MIN_MAJOR_VERSION = 11; final static public int MIN_MAJOR_VERSION = 14;
final static public String RPC_VERSION = "2.0"; final static public String RPC_VERSION = "2.0";
private long height = 0; private long height = 0;
@ -54,6 +54,7 @@ public class NodeInfo extends Node {
private int majorVersion = 0; private int majorVersion = 0;
private double responseTime = Double.MAX_VALUE; private double responseTime = Double.MAX_VALUE;
private int responseCode = 0; private int responseCode = 0;
private boolean tested = false;
public void clear() { public void clear() {
height = 0; height = 0;
@ -61,6 +62,11 @@ public class NodeInfo extends Node {
responseTime = Double.MAX_VALUE; responseTime = Double.MAX_VALUE;
responseCode = 0; responseCode = 0;
timestamp = 0; timestamp = 0;
tested = false;
}
public boolean isTested() {
return tested;
} }
static public NodeInfo fromString(String nodeString) { static public NodeInfo fromString(String nodeString) {
@ -188,7 +194,7 @@ public class NodeInfo extends Node {
} }
private static final int HTTP_TIMEOUT = OkHttpHelper.HTTP_TIMEOUT; private static final int HTTP_TIMEOUT = OkHttpHelper.HTTP_TIMEOUT;
public static final double PING_GOOD = HTTP_TIMEOUT / 3; //ms public static final double PING_GOOD = HTTP_TIMEOUT / 3.0; //ms
public static final double PING_MEDIUM = 2 * PING_GOOD; //ms public static final double PING_MEDIUM = 2 * PING_GOOD; //ms
public static final double PING_BAD = HTTP_TIMEOUT; public static final double PING_BAD = HTTP_TIMEOUT;
@ -251,8 +257,9 @@ public class NodeInfo extends Node {
} }
} }
} catch (IOException | JSONException ex) { } catch (IOException | JSONException ex) {
// failure
Timber.d(ex); Timber.d(ex);
} finally {
tested = true;
} }
return false; return false;
} }

View File

@ -147,11 +147,15 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo
nodeItem = nodeItems.get(position); nodeItem = nodeItems.get(position);
tvName.setText(nodeItem.getName()); tvName.setText(nodeItem.getName());
ivPing.setImageResource(getPingIcon(nodeItem)); ivPing.setImageResource(getPingIcon(nodeItem));
if (nodeItem.isValid()) { if (nodeItem.isTested()) {
Helper.showTimeDifference(tvIp, nodeItem.getTimestamp()); if (nodeItem.isValid()) {
Helper.showTimeDifference(tvIp, nodeItem.getTimestamp());
} else {
tvIp.setText(getResponseErrorText(context, nodeItem.getResponseCode()));
tvIp.setTextColor(ColorHelper.getThemedColor(tvIp.getContext(), R.attr.colorError));
}
} else { } else {
tvIp.setText(getResponseErrorText(context, nodeItem.getResponseCode())); tvIp.setText(context.getResources().getString(R.string.node_testing, nodeItem.getHostAddress()));
tvIp.setTextColor(ColorHelper.getThemedColor(tvIp.getContext(), R.attr.colorError));
} }
itemView.setSelected(nodeItem.isSelected()); itemView.setSelected(nodeItem.isSelected());
itemView.setClickable(itemsClickable); itemView.setClickable(itemsClickable);

View File

@ -40,10 +40,7 @@ public class NodePinger {
final ExecutorService exeService = Executors.newFixedThreadPool(NUM_THREADS); final ExecutorService exeService = Executors.newFixedThreadPool(NUM_THREADS);
List<Callable<Boolean>> taskList = new ArrayList<>(); List<Callable<Boolean>> taskList = new ArrayList<>();
for (NodeInfo node : nodes) { for (NodeInfo node : nodes) {
taskList.add(() -> { taskList.add(() -> node.testRpcService(listener));
node.clear();
return node.testRpcService(listener);
});
} }
try { try {