1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 06:34:41 +01:00

More testmode improvements

This commit is contained in:
Daniil Gentili 2023-08-06 18:41:22 +02:00
parent 96e95b5d95
commit 423cc1c2b5
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
9 changed files with 28 additions and 14 deletions

View File

@ -263,7 +263,7 @@ final class DataCenterConnection implements JsonSerializable
) {
try {
$logger->logger('Trying to copy authorization from DC '.$authorized_dc_id.' to DC '.$this->datacenter);
$exported_authorization = $this->API->methodCallAsyncRead('auth.exportAuthorization', ['dc_id' => $this->datacenter], ['datacenter' => $authorized_dc_id]);
$exported_authorization = $this->API->methodCallAsyncRead('auth.exportAuthorization', ['dc_id' => $this->datacenter % 10_000], ['datacenter' => $authorized_dc_id]);
$socket->methodCallAsyncRead('auth.importAuthorization', $exported_authorization);
$this->authorized(true);
break;

View File

@ -92,7 +92,7 @@ final class UpdateLoop extends Loop
}
$request_pts = $state->pts();
try {
$difference = $this->API->methodCallAsyncRead('updates.getChannelDifference', ['channel' => $this->API->toSupergroup($this->channelId), 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['datacenter' => $this->API->datacenter->currentDatacenter, 'postpone' => $this->first, 'FloodWaitLimit' => 86400]);
$difference = $this->API->methodCallAsyncRead('updates.getChannelDifference', ['channel' => $this->API->toSupergroup($this->channelId), 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['postpone' => $this->first, 'FloodWaitLimit' => 86400]);
} catch (RPCErrorException $e) {
if ($e->rpc === '-503') {
delay(1.0);

View File

@ -1514,6 +1514,15 @@ final class MTProto implements TLCallback, LoggerGetter
$this->parseDcOptions($options);
}
}
/**
* Whether we're currently connected to the test DCs.
*
* @return boolean
*/
public function isTestMode(): bool
{
return $this->config['test_mode'];
}
/**
* Parse DC options from config.
*

View File

@ -306,12 +306,14 @@ trait ResponseHandler
}
return fn () => new RPCErrorException($response['error_message'], $response['error_code'], $request->getConstructor());
case 303:
$this->API->datacenter->currentDatacenter = $datacenter = (int) \preg_replace('/[^0-9]+/', '', $response['error_message']);
$datacenter = (int) \preg_replace('/[^0-9]+/', '', $response['error_message']);
if ($this->API->isTestMode()) {
$datacenter += 10_000;
}
if ($request->isFileRelated() && $this->API->datacenter->has(-$datacenter)) {
$datacenter = -$datacenter;
}
if ($this->API->config['test_mode']) {
$datacenter += 10_000;
} else {
$this->API->datacenter->currentDatacenter = $datacenter;
}
if ($request->isUserRelated()) {
$this->API->authorized_dc = $this->API->datacenter->currentDatacenter;

View File

@ -911,7 +911,11 @@ trait Files
}
$part_size ??= 1024 * 1024;
$parallel_chunks = $this->settings->getFiles()->getDownloadParallelChunks();
$datacenter = $messageMedia['InputFileLocation']['dc_id'] ?? $this->authorized_dc;
if (isset($messageMedia['InputFileLocation']['dc_id'])) {
$datacenter = $this->isTestMode() ? 10_000 + $messageMedia['InputFileLocation']['dc_id'] : $messageMedia['InputFileLocation']['dc_id'];
} else {
$datacenter = $this->authorized_dc;
}
if ($this->datacenter->has(-$datacenter)) {
$datacenter = -$datacenter;
}
@ -1029,7 +1033,7 @@ trait Files
{
do {
if (!$cdn) {
$basic_param = ['location' => $messageMedia['InputFileLocation']];
$basic_param = ['location' => $messageMedia['InputFileLocation'], 'cdn_supported' => true];
} else {
$basic_param = ['file_token' => $messageMedia['file_token']];
}
@ -1062,7 +1066,7 @@ trait Files
$messageMedia['cdn_key'] = $res['encryption_key'];
$messageMedia['cdn_iv'] = $res['encryption_iv'];
$old_dc = $datacenter;
$datacenter = $res['dc_id'];
$datacenter = ($this->isTestMode() ? 10_000 : 0) + $res['dc_id'];
if (!$this->datacenter->has($datacenter)) {
$this->config['expires'] = -1;
$this->getConfig();

View File

@ -1189,7 +1189,7 @@ trait PeerHandler
$last_count = -1;
do {
try {
$gres = $this->methodCallAsyncRead('channels.getParticipants', ['channel' => $channel, 'filter' => ['_' => $filter, 'q' => $q], 'offset' => $offset, 'limit' => $limit, 'hash' => $hash = $this->getParticipantsHash($channel, $filter, $q, $offset, $limit)], ['datacenter' => $this->datacenter->currentDatacenter, 'heavy' => true]);
$gres = $this->methodCallAsyncRead('channels.getParticipants', ['channel' => $channel, 'filter' => ['_' => $filter, 'q' => $q], 'offset' => $offset, 'limit' => $limit, 'hash' => $hash = $this->getParticipantsHash($channel, $filter, $q, $offset, $limit)], ['heavy' => true]);
} catch (RPCErrorException $e) {
if ($e->rpc === 'CHAT_ADMIN_REQUIRED') {
$this->logger->logger($e->rpc);

View File

@ -701,7 +701,7 @@ trait UpdateHandler
$authorization = $this->methodCallAsyncRead(
'auth.importLoginToken',
$authorization,
['datacenter' => $authorization['dc_id']]
['datacenter' => $this->isTestMode() ? 10_000 + $authorization['dc_id'] : $authorization['dc_id']]
);
}
$this->processAuthorization($authorization['authorization']);

View File

@ -214,11 +214,10 @@ trait DialogHandler
$this->dialog_params['hash'] = 0;
}
$res = ['dialogs' => [0], 'count' => 1];
$datacenter = $this->datacenter->currentDatacenter;
$dialogs = [];
$this->logger->logger('Getting dialogs...');
while ($this->dialog_params['count'] < $res['count']) {
$res = $this->methodCallAsyncRead('messages.getDialogs', $this->dialog_params, ['datacenter' => $datacenter, 'FloodWaitLimit' => 100]);
$res = $this->methodCallAsyncRead('messages.getDialogs', $this->dialog_params, ['FloodWaitLimit' => 100]);
$last_peer = 0;
$last_date = 0;
$last_id = 0;

View File

@ -126,7 +126,7 @@ trait Login
$authorization = $this->methodCallAsyncRead(
'auth.importLoginToken',
$authorization,
['datacenter' => $authorization['dc_id']]
['datacenter' => $this->isTestMode() ? 10_000 + $authorization['dc_id'] : $authorization['dc_id']]
);
}
$this->processAuthorization($authorization['authorization']);