mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
Try to login in different DC if current is unavailable
This commit is contained in:
parent
feaf6c32d8
commit
5bed3fb6cd
4 changed files with 56 additions and 55 deletions
|
@ -83,7 +83,7 @@ android {
|
|||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 19
|
||||
versionCode 280
|
||||
versionCode 281
|
||||
versionName "1.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -781,7 +781,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
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) {
|
||||
|
@ -996,20 +996,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
for (int i = 0; i < runningRequests.size(); 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;
|
||||
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
||||
if (movingToDatacenterId != DEFAULT_DATACENTER_ID) {
|
||||
|
@ -1018,6 +1004,22 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
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);
|
||||
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
||||
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
||||
|
@ -1124,10 +1126,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
}
|
||||
|
||||
boolean updatingState = MessagesController.getInstance().updatingState;
|
||||
|
||||
if (genericConnection != null && genericConnection.channelToken != 0) {
|
||||
if (!updatingState) {
|
||||
Datacenter currentDatacenter = datacenterWithId(currentDatacenterId);
|
||||
|
||||
for (Long it : sessionsToDestroy) {
|
||||
|
@ -1148,7 +1147,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int genericRunningRequestCount = 0;
|
||||
int uploadRunningRequestCount = 0;
|
||||
|
@ -1172,22 +1170,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
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;
|
||||
if (datacenterId == DEFAULT_DATACENTER_ID) {
|
||||
if (movingToDatacenterId != DEFAULT_DATACENTER_ID && (request.flags & RPCRequest.RPCRequestClassEnableUnauthorized) == 0) {
|
||||
|
@ -1196,6 +1178,28 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
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);
|
||||
if (!request.initRequest && requestDatacenter.lastInitVersion != currentAppVersion) {
|
||||
request.rpcRequest = wrapInLayer(request.rawRequest, requestDatacenter.datacenterId, request);
|
||||
|
@ -1225,10 +1229,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
continue;
|
||||
}
|
||||
|
||||
if (updatingState && (request.rawRequest instanceof TLRPC.TL_account_updateStatus || request.rawRequest instanceof TLRPC.TL_account_registerDevice)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (request.requiresCompletion) {
|
||||
if ((request.flags & RPCRequest.RPCRequestClassGeneric) != 0) {
|
||||
if (genericRunningRequestCount >= 60) {
|
||||
|
|
|
@ -26,6 +26,7 @@ public class RPCRequest {
|
|||
public static int RPCRequestClassCanCompress = 32;
|
||||
public static int RPCRequestClassPush = 64;
|
||||
public static int RPCRequestClassWithoutLogin = 128;
|
||||
public static int RPCRequestClassTryDifferentDc = 256;
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue