From 25b7e6c8c6198b71f6cea07af85781065ac5d258 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Tue, 2 Oct 2018 01:35:53 -0500 Subject: [PATCH] Adding a very high latency to nodes that fail their connection --- .../graphenej/api/android/NetworkService.java | 5 +++++ .../api/android/NetworkServiceManager.java | 18 ++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java index 7a1ba3a..919fbb5 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkService.java @@ -595,6 +595,11 @@ public class NetworkService extends Service { Log.e(TAG,"Response: "+response.message()); } + // Adding a very high latency value to this node in order to prevent + // us from getting it again + mSelectedNode.addLatencyValue(Long.MAX_VALUE); + nodeProvider.updateNode(mSelectedNode); + RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.DISCONNECTED, ApiAccess.API_NONE)); if(nodeProvider.getBestNode() == null){ diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java index 5d5fb02..28f17b1 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/android/NetworkServiceManager.java @@ -9,6 +9,7 @@ import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; +import android.util.Log; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -74,14 +75,7 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb } @Override - public void onActivityCreated(Activity activity, Bundle bundle) { - if(mService == null){ - // Starting a NetworkService instance - Context context = mContextReference.get(); - Intent intent = new Intent(context, NetworkService.class); - context.startService(intent); - } - } + public void onActivityCreated(Activity activity, Bundle bundle) { } @Override public void onActivityStarted(Activity activity) { @@ -148,8 +142,8 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb return mUserName; } - public void setUserName(String mUserName) { - this.mUserName = mUserName; + public void setUserName(String userName) { + this.mUserName = userName; } public String getPassword() { @@ -286,8 +280,8 @@ public class NetworkServiceManager implements Application.ActivityLifecycleCallb */ public NetworkServiceManager build(Context context){ NetworkServiceManager manager = new NetworkServiceManager(context); - if(username != null) manager.setUserName(username); - if(password != null) manager.setPassword(password); + if(username != null) manager.setUserName(username); else manager.setUserName(""); + if(password != null) manager.setPassword(password); else manager.setPassword(""); if(customNodeUrls != null) manager.setCustomNodeUrls(customNodeUrls); manager.setRequestedApis(requestedApis); manager.setAutoConnect(autoconnect);