1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 14:51:17 +01:00

Fix final update issues
Some checks failed
ci/woodpecker/push/build Pipeline failed
ci/woodpecker/tag/build Pipeline was successful
ci/woodpecker/tag/deploy Pipeline was successful

This commit is contained in:
Daniil Gentili 2022-08-15 17:43:32 +02:00
parent 59ccaaa030
commit 75e5e5cf61
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 41 additions and 49 deletions

View File

@ -347,7 +347,7 @@ class Connection
if (!isset($this->waiter)) {
$this->waiter = new HttpWaitLoop($this);
}
if (!isset($this->pinger) && !$this->ctx->isMedia() && !$this->ctx->isCDN()) { // && ($this->ctx->hasStreamName(WssStream::class) || $this->ctx->hasStreamName(WsStream::class))) {
if (!isset($this->pinger) && !$this->ctx->isMedia() && !$this->ctx->isCDN()) {
$this->pinger = new PingLoop($this);
}
foreach ($this->new_outgoing as $message_id => $message) {

View File

@ -212,6 +212,9 @@ class DataCenterConnection implements JsonSerializable
} finally {
$lock->release();
}
if ($this->hasTempAuthKey()) {
$connection->pingHttpWaiter();
}
}
/**
* Bind temporary and permanent auth keys.

View File

@ -1541,10 +1541,12 @@ class MTProto extends AsyncConstruct implements TLCallback
public function hasAllAuth(): bool
{
if ($this->isInitingAuthorization()) {
$this->logger("Initing auth");
return false;
}
foreach ($this->datacenter->getDataCenterConnections() as $dc) {
foreach ($this->datacenter->getDataCenterConnections() as $id => $dc) {
if ((!$dc->isAuthorized() || !$dc->hasTempAuthKey()) && !$dc->isCDN()) {
$this->logger("Initing auth $id");
return false;
}
}
@ -1702,7 +1704,8 @@ class MTProto extends AsyncConstruct implements TLCallback
if (!isset($this->secretFeeders[$id])) {
$this->secretFeeders[$id] = new SecretFeedLoop($this, $id);
}
if ($this->secretFeeders[$id]->start() && isset($this->secretFeeders[$id])) {
$this->secretFeeders[$id]->start();
if (isset($this->secretFeeders[$id])) {
$this->secretFeeders[$id]->resume();
}
}
@ -1722,17 +1725,18 @@ class MTProto extends AsyncConstruct implements TLCallback
if (!isset($this->updaters[$channelId])) {
$this->updaters[$channelId] = new UpdateLoop($this, $channelId);
}
if ($this->feeders[$channelId]->start() && isset($this->feeders[$channelId])) {
$this->feeders[$channelId]->start();
if (isset($this->feeders[$channelId])) {
$this->feeders[$channelId]->resume();
}
if ($this->updaters[$channelId]->start() && isset($this->updaters[$channelId])) {
$this->updaters[$channelId]->start();
if (isset($this->updaters[$channelId])) {
$this->updaters[$channelId]->resume();
}
}
$this->flushAll();
if ($this->seqUpdater->start()) {
$this->seqUpdater->resume();
}
$this->seqUpdater->start();
$this->seqUpdater->resume();
}
/**
* Flush all datacenter connections.

View File

@ -2,6 +2,7 @@
namespace danog\MadelineProto\MTProtoTools;
use Amp\Sync\LocalMutex;
use danog\MadelineProto\DataCenter;
use danog\MadelineProto\Tools;
use phpseclib3\Math\BigInteger;
@ -11,13 +12,7 @@ use phpseclib3\Math\BigInteger;
*/
trait AuthKeyHandler
{
/**
* Whether another initAuthorization is pending.
*
* @var boolean
*/
private $pending_auth = false;
private ?LocalMutex $auth_mutex = null;
/**
* Asynchronously create, bind and check auth keys for all DCs.
*
@ -27,43 +22,35 @@ trait AuthKeyHandler
*/
public function initAuthorization(): \Generator
{
if ($this->initing_authorization) {
if ($this->pending_auth) {
$this->logger("Pending auth check, not queueing further auth check");
return;
}
$this->logger("Queueing further auth check");
$this->pending_auth = true;
return;
}
$this->auth_mutex ??= new LocalMutex;
$lock = yield $this->auth_mutex->acquire();
$this->logger("Initing authorization...");
$this->initing_authorization = true;
try {
do {
$this->pending_auth = false;
$main = [];
$media = [];
foreach ($this->datacenter->getDataCenterConnections() as $socket) {
if (!$socket->hasCtx()) {
continue;
}
if ($socket->isMedia()) {
$media []= [$socket, 'initAuthorization'];
} else {
$main []= [$socket, 'initAuthorization'];
}
$main = [];
$media = [];
foreach ($this->datacenter->getDataCenterConnections() as $socket) {
if (!$socket->hasCtx()) {
continue;
}
if ($main) {
$first = \array_shift($main)();
yield from $first;
if ($socket->isMedia()) {
$media []= [$socket, 'initAuthorization'];
} else {
$main []= [$socket, 'initAuthorization'];
}
yield Tools::all(\array_map(fn ($cb) => $cb(), $main));
yield Tools::all(\array_map(fn ($cb) => $cb(), $media));
} while ($this->pending_auth);
}
if ($main) {
$first = \array_shift($main)();
yield from $first;
}
yield Tools::all(\array_map(fn ($cb) => $cb(), $main));
yield Tools::all(\array_map(fn ($cb) => $cb(), $media));
} finally {
$lock->release();
$this->logger("Done initing authorization!");
$this->initing_authorization = false;
}
$this->startUpdateSystem(true);
}
/**
* Get diffie-hellman configuration.

View File

@ -93,9 +93,8 @@ trait AuthKeyHandler
'mtproto' => 1
];
$this->secretFeeders[$params['id']] = new SecretFeedLoop($this, $params['id']);
if ($this->secretFeeders[$params['id']]->start()) {
$this->secretFeeders[$params['id']]->resume();
}
$this->secretFeeders[$params['id']]->start();
$this->secretFeeders[$params['id']]->resume();
$g_b = $dh_config['g']->powMod($b, $dh_config['p']);
Crypt::checkG($g_b, $dh_config['p']);
yield from $this->methodCallAsyncRead('messages.acceptEncryption', ['peer' => $params['id'], 'g_b' => $g_b->toBytes(), 'key_fingerprint' => $key['fingerprint']]);
@ -158,9 +157,8 @@ trait AuthKeyHandler
$key['visualization_46'] = \substr(\hash('sha256', $key['auth_key'], true), 20);
$this->secret_chats[$params['id']] = ['key' => $key, 'admin' => true, 'user_id' => $params['participant_id'], 'InputEncryptedChat' => ['chat_id' => $params['id'], 'access_hash' => $params['access_hash'], '_' => 'inputEncryptedChat'], 'in_seq_no_x' => 0, 'out_seq_no_x' => 1, 'in_seq_no' => 0, 'out_seq_no' => 0, 'layer' => 8, 'ttl' => 0, 'ttr' => 100, 'updated' => \time(), 'incoming' => [], 'outgoing' => [], 'created' => \time(), 'rekeying' => [0], 'key_x' => 'to server', 'mtproto' => 1];
$this->secretFeeders[$params['id']] = new SecretFeedLoop($this, $params['id']);
if ($this->secretFeeders[$params['id']]->start()) {
$this->secretFeeders[$params['id']]->resume();
}
$this->secretFeeders[$params['id']]->start();
$this->secretFeeders[$params['id']]->resume();
yield from $this->notifyLayer($params['id']);
$this->logger->logger('Secret chat '.$params['id'].' completed successfully!', \danog\MadelineProto\Logger::NOTICE);
}