Try to login in different DC if current is unavailable
This commit is contained in:
parent
feaf6c32d8
commit
5bed3fb6cd
@ -83,7 +83,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 8
|
||||||
targetSdkVersion 19
|
targetSdkVersion 19
|
||||||
versionCode 280
|
versionCode 281
|
||||||
versionName "1.6.0"
|
versionName "1.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,7 +781,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
}
|
}
|
||||||
updatingDcSettings = false;
|
updatingDcSettings = false;
|
||||||
}
|
}
|
||||||
}, null, true, RPCRequest.RPCRequestClassEnableUnauthorized | RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin, dcNum == 0 ? currentDatacenterId : dcNum);
|
}, null, true, RPCRequest.RPCRequestClassEnableUnauthorized | RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassWithoutLogin | RPCRequest.RPCRequestClassTryDifferentDc, dcNum == 0 ? currentDatacenterId : dcNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TLObject wrapInLayer(TLObject object, int datacenterId, RPCRequest request) {
|
private TLObject wrapInLayer(TLObject object, int datacenterId, RPCRequest request) {
|
||||||
@ -996,20 +996,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
for (int i = 0; i < runningRequests.size(); i++) {
|
for (int i = 0; i < runningRequests.size(); i++) {
|
||||||
RPCRequest request = runningRequests.get(i);
|
RPCRequest request = runningRequests.get(i);
|
||||||
|
|
||||||
if (datacenters.size() > 1) {
|
|
||||||
if (updatingDcSettings && request.rawRequest instanceof TLRPC.TL_help_getConfig) {
|
|
||||||
if (updatingDcStartTime < currentTime - 60) {
|
|
||||||
FileLog.e("tmessages", "move TL_help_getConfig to requestQueue");
|
|
||||||
requestQueue.add(request);
|
|
||||||
runningRequests.remove(i);
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else if (request.rawRequest instanceof TLRPC.TL_auth_sendCode || request.rawRequest instanceof TLRPC.TL_auth_signIn || request.rawRequest instanceof TLRPC.TL_auth_signUp) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int datacenterId = request.runningDatacenterId;
|
int datacenterId = request.runningDatacenterId;
|
||||||
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
||||||
if (movingToDatacenterId != DEFAULT_DATACENTER_ID) {
|
if (movingToDatacenterId != DEFAULT_DATACENTER_ID) {
|
||||||
@ -1018,6 +1004,22 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
datacenterId = currentDatacenterId;
|
datacenterId = currentDatacenterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (datacenters.size() > 1 && (request.flags & RPCRequest.RPCRequestClassTryDifferentDc) != 0) {
|
||||||
|
int requestStartTime = request.runningStartTime;
|
||||||
|
int timeout = 30;
|
||||||
|
if (updatingDcSettings && request.rawRequest instanceof TLRPC.TL_help_getConfig) {
|
||||||
|
requestStartTime = updatingDcStartTime;
|
||||||
|
timeout = 60;
|
||||||
|
}
|
||||||
|
if (requestStartTime != 0 && requestStartTime < currentTime - timeout) {
|
||||||
|
FileLog.e("tmessages", "move " + request.rawRequest + " to requestQueue");
|
||||||
|
requestQueue.add(request);
|
||||||
|
runningRequests.remove(i);
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Datacenter requestDatacenter = datacenterWithId(datacenterId);
|
Datacenter requestDatacenter = datacenterWithId(datacenterId);
|
||||||
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
||||||
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
||||||
@ -1124,27 +1126,23 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean updatingState = MessagesController.getInstance().updatingState;
|
|
||||||
|
|
||||||
if (genericConnection != null && genericConnection.channelToken != 0) {
|
if (genericConnection != null && genericConnection.channelToken != 0) {
|
||||||
if (!updatingState) {
|
Datacenter currentDatacenter = datacenterWithId(currentDatacenterId);
|
||||||
Datacenter currentDatacenter = datacenterWithId(currentDatacenterId);
|
|
||||||
|
|
||||||
for (Long it : sessionsToDestroy) {
|
for (Long it : sessionsToDestroy) {
|
||||||
if (destroyingSessions.contains(it)) {
|
if (destroyingSessions.contains(it)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (System.currentTimeMillis() / 1000 - lastDestroySessionRequestTime > 2.0) {
|
if (System.currentTimeMillis() / 1000 - lastDestroySessionRequestTime > 2.0) {
|
||||||
lastDestroySessionRequestTime = (int)(System.currentTimeMillis() / 1000);
|
lastDestroySessionRequestTime = (int)(System.currentTimeMillis() / 1000);
|
||||||
TLRPC.TL_destroy_session destroySession = new TLRPC.TL_destroy_session();
|
TLRPC.TL_destroy_session destroySession = new TLRPC.TL_destroy_session();
|
||||||
destroySession.session_id = it;
|
destroySession.session_id = it;
|
||||||
destroyingSessions.add(it);
|
destroyingSessions.add(it);
|
||||||
|
|
||||||
NetworkMessage networkMessage = new NetworkMessage();
|
NetworkMessage networkMessage = new NetworkMessage();
|
||||||
networkMessage.protoMessage = wrapMessage(destroySession, currentDatacenter.connection, false);
|
networkMessage.protoMessage = wrapMessage(destroySession, currentDatacenter.connection, false);
|
||||||
if (networkMessage.protoMessage != null) {
|
if (networkMessage.protoMessage != null) {
|
||||||
addMessageToDatacenter(currentDatacenter.datacenterId, networkMessage);
|
addMessageToDatacenter(currentDatacenter.datacenterId, networkMessage);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1172,22 +1170,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updatingDcSettings && datacenters.size() > 1 && request.rawRequest instanceof TLRPC.TL_help_getConfig) {
|
|
||||||
if (updatingDcStartTime < currentTime - 60) {
|
|
||||||
updatingDcStartTime = currentTime;
|
|
||||||
ArrayList<Datacenter> allDc = new ArrayList<Datacenter>(datacenters.values());
|
|
||||||
for (int a = 0; a < allDc.size(); a++) {
|
|
||||||
Datacenter dc = allDc.get(a);
|
|
||||||
if (dc.datacenterId == request.runningDatacenterId) {
|
|
||||||
allDc.remove(a);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Datacenter newDc = allDc.get(Math.abs(Utilities.random.nextInt() % allDc.size()));
|
|
||||||
request.runningDatacenterId = newDc.datacenterId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int datacenterId = request.runningDatacenterId;
|
int datacenterId = request.runningDatacenterId;
|
||||||
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
||||||
if (movingToDatacenterId != DEFAULT_DATACENTER_ID && (request.flags & RPCRequest.RPCRequestClassEnableUnauthorized) == 0) {
|
if (movingToDatacenterId != DEFAULT_DATACENTER_ID && (request.flags & RPCRequest.RPCRequestClassEnableUnauthorized) == 0) {
|
||||||
@ -1196,6 +1178,28 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
datacenterId = currentDatacenterId;
|
datacenterId = currentDatacenterId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (datacenters.size() > 1 && (request.flags & RPCRequest.RPCRequestClassTryDifferentDc) != 0) {
|
||||||
|
int requestStartTime = request.runningStartTime;
|
||||||
|
int timeout = 30;
|
||||||
|
if (updatingDcSettings && request.rawRequest instanceof TLRPC.TL_help_getConfig) {
|
||||||
|
requestStartTime = updatingDcStartTime;
|
||||||
|
updatingDcStartTime = currentTime;
|
||||||
|
timeout = 60;
|
||||||
|
}
|
||||||
|
if (requestStartTime != 0 && requestStartTime < currentTime - timeout) {
|
||||||
|
ArrayList<Datacenter> allDc = new ArrayList<Datacenter>(datacenters.values());
|
||||||
|
for (int a = 0; a < allDc.size(); a++) {
|
||||||
|
Datacenter dc = allDc.get(a);
|
||||||
|
if (dc.datacenterId == datacenterId) {
|
||||||
|
allDc.remove(a);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Datacenter newDc = allDc.get(Math.abs(Utilities.random.nextInt() % allDc.size()));
|
||||||
|
datacenterId = request.runningDatacenterId = newDc.datacenterId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Datacenter requestDatacenter = datacenterWithId(datacenterId);
|
Datacenter requestDatacenter = datacenterWithId(datacenterId);
|
||||||
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
||||||
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
||||||
@ -1225,10 +1229,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updatingState && (request.rawRequest instanceof TLRPC.TL_account_updateStatus || request.rawRequest instanceof TLRPC.TL_account_registerDevice)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.requiresCompletion) {
|
if (request.requiresCompletion) {
|
||||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||||
if (genericRunningRequestCount >= 60) {
|
if (genericRunningRequestCount >= 60) {
|
||||||
|
@ -26,6 +26,7 @@ public class RPCRequest {
|
|||||||
public static int RPCRequestClassCanCompress = 32;
|
public static int RPCRequestClassCanCompress = 32;
|
||||||
public static int RPCRequestClassPush = 64;
|
public static int RPCRequestClassPush = 64;
|
||||||
public static int RPCRequestClassWithoutLogin = 128;
|
public static int RPCRequestClassWithoutLogin = 128;
|
||||||
|
public static int RPCRequestClassTryDifferentDc = 256;
|
||||||
|
|
||||||
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
|
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ public class LoginActivityPhoneView extends SlideView implements AdapterView.OnI
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin);
|
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin | RPCRequest.RPCRequestClassTryDifferentDc | RPCRequest.RPCRequestClassEnableUnauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user