mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-27 13:54:39 +01:00
Stability fixes
This commit is contained in:
parent
e3a2c720ef
commit
588aea5c8e
@ -264,10 +264,11 @@ class Connection
|
||||
case 'obfuscated2':
|
||||
$packet = '';
|
||||
while (strlen($packet) < $length) {
|
||||
$packet .= $this->sock->read($length - strlen($packet));
|
||||
if ($packet === false || strlen($packet) === 0) {
|
||||
$piece = $this->sock->read($length - strlen($packet));
|
||||
if ($piece === false || strlen($piece) === 0) {
|
||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
||||
}
|
||||
$packet .= $piece;
|
||||
}
|
||||
|
||||
return @$this->obfuscated['decryption']->encrypt($packet);
|
||||
@ -278,10 +279,11 @@ class Connection
|
||||
case 'https':
|
||||
$packet = '';
|
||||
while (strlen($packet) < $length) {
|
||||
$packet .= $this->sock->read($length - strlen($packet));
|
||||
if ($packet === false || strlen($packet) === 0) {
|
||||
$piece = $this->sock->read($length - strlen($packet));
|
||||
if ($piece === false || strlen($piece) === 0) {
|
||||
throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
|
||||
}
|
||||
$packet .= $piece;
|
||||
}
|
||||
|
||||
return $packet;
|
||||
|
@ -145,7 +145,7 @@ class DataCenter
|
||||
return $all ? array_keys((array) $this->dclist[$test][$ipv6]) : array_keys((array) $this->sockets);
|
||||
}
|
||||
|
||||
public function select()
|
||||
public function select($poll = false)
|
||||
{
|
||||
$read = [];
|
||||
$write = [];
|
||||
@ -153,7 +153,7 @@ class DataCenter
|
||||
foreach ($this->sockets as $dc_id => $socket) {
|
||||
$read[$dc_id] = $socket->getSocket();
|
||||
}
|
||||
\Socket::select($read, $write, $except, $this->settings['all']['timeout']);
|
||||
\Socket::select($read, $write, $except, $poll ? 0 : $this->settings['all']['timeout']);
|
||||
|
||||
return array_keys($read);
|
||||
}
|
||||
|
@ -143,7 +143,11 @@ trait CallHandler
|
||||
$server_answer = null;
|
||||
$update_count = 0;
|
||||
$only_updates = false;
|
||||
while ($server_answer === null && $res_count++ < $this->settings['max_tries']['response'] + 1) {
|
||||
$response_tries = $this->settings['max_tries']['response'] + 1;
|
||||
if ($last_recv) {
|
||||
$response_tries += (int) floor((time() - $last_recv)/10);
|
||||
}
|
||||
while ($server_answer === null && $res_count++ < $response_tries) {
|
||||
// Loop until we get a response, loop for a max of $this->settings['max_tries']['response'] times
|
||||
try {
|
||||
\danog\MadelineProto\Logger::log('Getting response (try number '.$res_count.' for '.$method.')...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
|
@ -61,31 +61,39 @@ trait UpdateHandler
|
||||
$time = microtime(true);
|
||||
|
||||
try {
|
||||
if (!$this->is_http($this->datacenter->curdc) || $this->altervista) {
|
||||
if (!$this->is_http($this->datacenter->curdc) && !$this->altervista) {
|
||||
try {
|
||||
$waiting = $this->datacenter->select();
|
||||
$dc = count($waiting) ? $waiting[0] : $this->datacenter->curdc;
|
||||
$last_recv = $this->datacenter->sockets[$dc]->last_recv;
|
||||
if (count($waiting)) {
|
||||
if (($error = $this->recv_message($dc)) !== true) {
|
||||
if ($error === -404) {
|
||||
if ($this->datacenter->sockets[$dc]->temp_auth_key !== null) {
|
||||
\danog\MadelineProto\Logger::log('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
|
||||
$this->datacenter->sockets[$dc]->temp_auth_key = null;
|
||||
$this->init_authorization();
|
||||
$tries = 10;
|
||||
while (count($waiting) && $tries--) {
|
||||
$dc = $waiting[0];
|
||||
if (($error = $this->recv_message($dc)) !== true) {
|
||||
if ($error === -404) {
|
||||
if ($this->datacenter->sockets[$dc]->temp_auth_key !== null) {
|
||||
\danog\MadelineProto\Logger::log('WARNING: Resetting auth key...', \danog\MadelineProto\Logger::WARNING);
|
||||
$this->datacenter->sockets[$dc]->temp_auth_key = null;
|
||||
$this->init_authorization();
|
||||
|
||||
throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key');
|
||||
throw new \danog\MadelineProto\Exception('I had to recreate the temporary authorization key');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new \danog\MadelineProto\RPCErrorException($error, $error);
|
||||
throw new \danog\MadelineProto\RPCErrorException($error, $error);
|
||||
}
|
||||
$only_updates = $this->handle_messages($dc);
|
||||
$waiting = $this->datacenter->select(true);
|
||||
}
|
||||
$only_updates = $this->handle_messages($dc);
|
||||
} else {
|
||||
$this->get_updates_difference();
|
||||
}
|
||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||
$this->get_updates_difference();
|
||||
}
|
||||
} else {
|
||||
$this->get_updates_difference();
|
||||
}
|
||||
if ($this->is_http($dc) || $this->altervista && time() - $this->last_getdifference > $this->settings['updates']['getdifference_interval']) {
|
||||
if (time() - $this->last_getdifference > $this->settings['updates']['getdifference_interval']) {
|
||||
$this->get_updates_difference();
|
||||
}
|
||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||
@ -294,7 +302,7 @@ trait UpdateHandler
|
||||
\danog\MadelineProto\Logger::log('Fetching normal difference...', \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
while (!isset($difference)) {
|
||||
try {
|
||||
$difference = $this->method_call('updates.getDifference', ['pts' => $this->load_update_state()['pts'], 'date' => $this->load_update_state()['date'], 'qts' => $this->load_update_state()['qts']], ['datacenter' => $this->datacenter->curdc]);
|
||||
$difference = $this->method_call('updates.getDifference', ['pts' => $this->load_update_state()['pts'], 'date' => $this->load_update_state()['date'], 'qts' => $this->load_update_state()['qts']], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
|
||||
} catch (\danog\MadelineProto\PTSException $e) {
|
||||
$this->updates_state['sync_loading'] = false;
|
||||
$this->got_state = false;
|
||||
@ -348,8 +356,8 @@ trait UpdateHandler
|
||||
$this->updates_state['sync_loading'] = true;
|
||||
|
||||
try {
|
||||
$data = $this->method_call('updates.getState', [], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->get_cdn_config($this->datacenter->curdc);
|
||||
$data = $this->method_call('updates.getState', [], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
|
||||
$this->get_cdn_config( $this->settings['connection_settings']['default_dc']);
|
||||
} finally {
|
||||
$this->updates_state['sync_loading'] = $last;
|
||||
}
|
||||
@ -565,7 +573,7 @@ trait UpdateHandler
|
||||
return false;
|
||||
}
|
||||
\danog\MadelineProto\Logger::log('Applying qts: '.$update['qts'].' over current qts '.$cur_state['qts'].', chat id: '.$update['message']['chat_id'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
$this->method_call('messages.receivedQueue', ['max_qts' => $cur_state['qts'] = $update['qts']], ['datacenter' => $this->datacenter->curdc]);
|
||||
$this->method_call('messages.receivedQueue', ['max_qts' => $cur_state['qts'] = $update['qts']], ['datacenter' => $this->settings['connection_settings']['default_dc']]);
|
||||
$this->handle_encrypted_update($update);
|
||||
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user