Merge branch 'develop' of github.com:Agorise/graphenej into develop

This commit is contained in:
Nelson R. Perez 2018-10-18 18:00:19 -05:00
commit a5f0ba1345
2 changed files with 38 additions and 29 deletions

View file

@ -2,6 +2,7 @@ package cy.agorise.graphenej.api.android;
import android.app.Service;
import android.content.Intent;
import java.util.concurrent.TimeUnit;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
@ -210,7 +211,10 @@ public class NetworkService extends Service {
* Actually establishes a connection from this Service to one of the full nodes.
*/
public void connect(){
OkHttpClient client = new OkHttpClient();
OkHttpClient client = new OkHttpClient
.Builder()
.connectTimeout(2, TimeUnit.SECONDS)
.build();
mSelectedNode = nodeProvider.getBestNode();
Log.v(TAG,"connect.url: "+ mSelectedNode.getUrl());
Request request = new Request.Builder().url(mSelectedNode.getUrl()).build();

View file

@ -102,11 +102,10 @@ public class NodeLatencyVerifier {
}
String normalURL = fullNode.getUrl().replace("wss://", "https://");
if(!nodeURLMap.containsKey(fullNode.getUrl().replace("wss://", "https://"))){
HttpUrl key = HttpUrl.parse(normalURL);
if(!nodeURLMap.containsKey(key)){
nodeURLMap.put(key, fullNode);
}
client.newWebSocket(request, mWebSocketListener);
}
mHandler.postDelayed(this, verificationPeriod);
@ -133,10 +132,11 @@ public class NodeLatencyVerifier {
* Method used to handle the node's first response. The idea here is to obtain
* the RTT (Round Trip Time) measurement and publish it using the PublishSubject.
*
* @param webSocket Websocket instance
* @param webSocket WebSocket instance
* @param response Response instance
*/
private void handleResponse(WebSocket webSocket, Response response){
synchronized (this){
// Obtaining the HttpUrl instance that was previously used as a key
HttpUrl url = webSocket.request().url();
if(nodeURLMap.containsKey(url)){
@ -152,8 +152,12 @@ public class NodeLatencyVerifier {
long before = timestamps.get(fullNode);
delay = after - before;
}
if(fullNode != null){
fullNode.addLatencyValue(delay);
subject.onNext(fullNode);
}else{
Log.w(TAG,"Could not extract FullNode instance from the map");
}
}else{
// We cannot properly handle a response to a request whose
// URL was not registered at the nodeURLMap. This is because without this,
@ -165,6 +169,7 @@ public class NodeLatencyVerifier {
}
webSocket.close(NetworkService.NORMAL_CLOSURE_STATUS, null);
}
}
};
/**