GramJs: Use "-1" DCs for file transfers (generate keys with standard DCs) (#1368)

This commit is contained in:
Alexander Zinchuk 2021-08-11 01:27:58 +03:00
parent d59390364c
commit 3635d312ce
2 changed files with 15 additions and 7 deletions

View File

@ -605,37 +605,44 @@ function isListLike(item) {
)
}
*/
function getDC(dcId) {
/**
* Returns the appropriate DC based on the id
* @param dcId the id of the DC.
* @param downloadDC whether to use -1 DCs or not
* (These only support downloading/uploading and not creating a new AUTH key)
* @return {{port: number, ipAddress: string, id: number}}
*/
function getDC(dcId, downloadDC = false) {
// TODO Move to external config
switch (dcId) {
case 1:
return {
id: 1,
ipAddress: 'zws1.web.telegram.org',
ipAddress: `zws1${downloadDC ? '-1' : ''}.web.telegram.org`,
port: 443,
};
case 2:
return {
id: 2,
ipAddress: 'zws2.web.telegram.org',
ipAddress: `zws2${downloadDC ? '-1' : ''}.web.telegram.org`,
port: 443,
};
case 3:
return {
id: 3,
ipAddress: 'zws3.web.telegram.org',
ipAddress: `zws3${downloadDC ? '-1' : ''}.web.telegram.org`,
port: 443,
};
case 4:
return {
id: 4,
ipAddress: 'zws4.web.telegram.org',
ipAddress: `zws4${downloadDC ? '-1' : ''}.web.telegram.org`,
port: 443,
};
case 5:
return {
id: 5,
ipAddress: 'zws5.web.telegram.org',
ipAddress: `zws5${downloadDC ? '-1' : ''}.web.telegram.org`,
port: 443,
};
default:

View File

@ -327,7 +327,8 @@ class TelegramClient {
}
async _connectSender(sender, dcId) {
const dc = utils.getDC(dcId);
// if we don't already have an auth key we want to use normal DCs not -1
const dc = utils.getDC(dcId, !!sender.authKey.getKey());
while (true) {
try {