Adding a very high latency to nodes that fail their connection

This commit is contained in:
Nelson R. Perez 2018-10-02 01:35:53 -05:00
parent 694572b18d
commit 25b7e6c8c6
2 changed files with 11 additions and 12 deletions

View file

@ -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){

View file

@ -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);