Do not remove subconnection from DataCenterConnection if reconnecting
This commit is contained in:
parent
e9e66f3835
commit
579dfe3563
13
bot.php
13
bot.php
@ -12,6 +12,9 @@ See the GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with MadelineProto.
|
||||
If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use danog\MadelineProto\Stream\Proxy\SocksProxy;
|
||||
|
||||
\set_include_path(\get_include_path().':'.\realpath(\dirname(__FILE__).'/MadelineProto/'));
|
||||
|
||||
/*
|
||||
@ -63,7 +66,15 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
$settings = ['logger' => ['logger_level' => 5], 'serialization' => ['serialization_interval' => 30, 'cleanup_before_serialization' => true]];
|
||||
$settings = [
|
||||
'logger' => [
|
||||
'logger_level' => 5
|
||||
],
|
||||
'serialization' => [
|
||||
'serialization_interval' => 30,
|
||||
'cleanup_before_serialization' => true
|
||||
],
|
||||
];
|
||||
|
||||
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
|
||||
$MadelineProto->async(true);
|
||||
|
@ -523,9 +523,11 @@ class Connection extends Session
|
||||
/**
|
||||
* Disconnect from DC.
|
||||
*
|
||||
* @param bool $temporary Whether the disconnection is temporary, triggered by the reconnect method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disconnect()
|
||||
public function disconnect(bool $temporary = false)
|
||||
{
|
||||
$this->API->logger->logger("Disconnecting from DC {$this->datacenterId}");
|
||||
$this->needsReconnect = true;
|
||||
@ -541,7 +543,9 @@ class Connection extends Session
|
||||
$this->API->logger->logger($e);
|
||||
}
|
||||
}
|
||||
$this->shared->signalDisconnect($this->id);
|
||||
if (!$temporary) {
|
||||
$this->shared->signalDisconnect($this->id);
|
||||
}
|
||||
$this->API->logger->logger("Disconnected from DC {$this->datacenterId}");
|
||||
}
|
||||
|
||||
@ -553,17 +557,8 @@ class Connection extends Session
|
||||
public function reconnect(): \Generator
|
||||
{
|
||||
$this->API->logger->logger("Reconnecting DC {$this->datacenterId}");
|
||||
$this->disconnect();
|
||||
$this->disconnect(true);
|
||||
yield $this->API->datacenter->dcConnectAsync($this->ctx->getDc(), $this->id);
|
||||
if ($this->API->hasAllAuth() && !$this->hasPendingCalls()) {
|
||||
/*$this->callFork((function () {
|
||||
try {
|
||||
$this->API->method_call_async_read('ping', ['ping_id' => $this->random_int()], ['datacenter' => $this->datacenter]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->API->logger("Got an error while pinging on reconnect: $e", Logger::FATAL_ERROR);
|
||||
}
|
||||
})());*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,10 +233,10 @@ class DataCenter
|
||||
$this->CookieJar,
|
||||
new HttpSocketPool(
|
||||
new ProxySocketPool(
|
||||
function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) {
|
||||
return $this->rawConnectAsync($uri, $token, $ctx, true);
|
||||
}
|
||||
)
|
||||
function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) {
|
||||
return $this->rawConnectAsync($uri, $token, $ctx, true);
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
$DoHConfig = new DoHConfig(
|
||||
@ -528,7 +528,11 @@ class DataCenter
|
||||
{
|
||||
$old = isset($this->sockets[$dc_number]) && (
|
||||
$this->sockets[$dc_number]->shouldReconnect() ||
|
||||
($id !== -1 && $this->sockets[$dc_number]->hasConnection($id) && $this->sockets[$dc_number]->getConnection($id)->shouldReconnect())
|
||||
(
|
||||
$id !== -1
|
||||
&& $this->sockets[$dc_number]->hasConnection($id)
|
||||
&& $this->sockets[$dc_number]->getConnection($id)->shouldReconnect()
|
||||
)
|
||||
);
|
||||
if (isset($this->sockets[$dc_number]) && !$old) {
|
||||
$this->API->logger("Not reconnecting to DC $dc_number ($id)");
|
||||
|
Loading…
Reference in New Issue
Block a user