Merge branch 'develop' of github.com:Agorise/graphenej into develop
This commit is contained in:
commit
b37bb9dce0
1 changed files with 14 additions and 5 deletions
|
@ -22,7 +22,7 @@ import okhttp3.WebSocketListener;
|
||||||
public class NodeLatencyVerifier {
|
public class NodeLatencyVerifier {
|
||||||
private final String TAG = this.getClass().getName();
|
private final String TAG = this.getClass().getName();
|
||||||
|
|
||||||
public static final int DEFAULT_LATENCY_VERIFICATION_PERIOD = 5 * 1000;
|
private static final int DEFAULT_LATENCY_VERIFICATION_PERIOD = 5 * 1000;
|
||||||
|
|
||||||
// Variable used to store the list of nodes that should be verified
|
// Variable used to store the list of nodes that should be verified
|
||||||
private List<FullNode> mNodeList;
|
private List<FullNode> mNodeList;
|
||||||
|
@ -88,7 +88,7 @@ public class NodeLatencyVerifier {
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
timestamps.put(fullNode, before);
|
timestamps.put(fullNode, before);
|
||||||
|
|
||||||
// We want to reuse the same OkHttoClient instance if possible
|
// We want to reuse the same OkHttpClient instance if possible
|
||||||
if(client == null) client = new OkHttpClient();
|
if(client == null) client = new OkHttpClient();
|
||||||
|
|
||||||
// Same thing with the Request instance, we want to reuse them. But since
|
// Same thing with the Request instance, we want to reuse them. But since
|
||||||
|
@ -143,9 +143,18 @@ public class NodeLatencyVerifier {
|
||||||
HttpUrl url = webSocket.request().url();
|
HttpUrl url = webSocket.request().url();
|
||||||
if(nodeURLMap.containsKey(url)){
|
if(nodeURLMap.containsKey(url)){
|
||||||
FullNode fullNode = nodeURLMap.get(url);
|
FullNode fullNode = nodeURLMap.get(url);
|
||||||
|
long delay;
|
||||||
|
|
||||||
|
if(response == null) {
|
||||||
|
// There is no internet connection, or the node is unreachable. We are just
|
||||||
|
// putting an artificial delay.
|
||||||
|
delay = Long.MAX_VALUE;
|
||||||
|
} else {
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
long before = timestamps.get(fullNode);
|
long before = timestamps.get(fullNode);
|
||||||
long delay = after - before;
|
delay = after - before;
|
||||||
|
}
|
||||||
|
|
||||||
fullNode.addLatencyValue(delay);
|
fullNode.addLatencyValue(delay);
|
||||||
subject.onNext(fullNode);
|
subject.onNext(fullNode);
|
||||||
}else{
|
}else{
|
||||||
|
|
Loading…
Reference in a new issue