From 41c682a12dac4d633e0206c9f81dd0a3f73790b3 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 28 Aug 2018 20:55:49 +0200 Subject: [PATCH] Fix recursive alphabetical search and implement nothing in the socket fix --- src/danog/MadelineProto/API.php | 2 +- src/danog/MadelineProto/MTProto.php | 2 +- src/danog/MadelineProto/MTProtoTools/CallHandler.php | 6 +++++- src/danog/MadelineProto/MTProtoTools/PeerHandler.php | 11 ++++++++--- src/danog/MadelineProto/Tools.php | 1 + tests/testing.php | 1 + 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 5f822bbf..dadf3612 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -186,10 +186,10 @@ class API extends APIFactory if ($params === null) { $params = $this->session; } - Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']); if (empty($params)) { return; } + Logger::log(\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']); return Serialization::serialize($params, $this); } diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 4e523396..b0a24d9c 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -154,7 +154,7 @@ class MTProto public function __sleep() { - return ['event_handler', 'event_handler_instance', 'loop_callback', 'web_template', 'encrypted_layer', 'settings', 'config', 'authorization', 'authorized', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'pending_pwrchat', 'postpone_pwrchat', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'full_chats', 'msg_ids', 'dialog_params', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'temp_requested_secret_chats', 'temp_rekeyed_secret_chats', 'secret_chats', 'hook_url', 'storage', 'authorized_dc', 'tos']; + return ['channel_participants', 'event_handler', 'event_handler_instance', 'loop_callback', 'web_template', 'encrypted_layer', 'settings', 'config', 'authorization', 'authorized', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'pending_pwrchat', 'postpone_pwrchat', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'full_chats', 'msg_ids', 'dialog_params', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'temp_requested_secret_chats', 'temp_rekeyed_secret_chats', 'secret_chats', 'hook_url', 'storage', 'authorized_dc', 'tos']; } public function __wakeup() diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index 468218ab..adde6575 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -149,7 +149,11 @@ trait CallHandler $only_updates = false; $response_tries = $this->settings['max_tries']['response'] + 1; if ($last_recv) { - $response_tries += (int) floor((time() - $last_recv) / 10); + $additional = (int) floor((time() - $last_recv) / 10); + if ($additional > $this->settings['max_tries']['response']*2) { + $additional = $this->settings['max_tries']['response']*2; + } + $response_tries += $additional; } 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 diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index f1421efa..01aec732 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -652,6 +652,7 @@ trait PeerHandler $limit = 200; $has_more = false; $cached = false; + $last_count = -1; do { try { @@ -670,7 +671,11 @@ trait PeerHandler $this->store_participants_cache($gres, $channel, $filter, $q, $offset, $limit); } - $has_more = $gres['count'] === 10000; + if ($last_count !== -1 && $last_count !== $gres['count']) { + $has_more = true; + } else { + $last_count = $gres['count']; + } foreach ($gres['participants'] as $participant) { $newres = []; @@ -712,7 +717,7 @@ trait PeerHandler } $res['participants'][$participant['user_id']] = $newres; } - $this->logger->logger("Fetched channel participants with filter $filter, query $q, offset $offset, limit $limit, hash $hash: ".($cached ? 'cached' : 'not cached').', '.count($gres['participants']).' participants out of '.$gres['count'].', in total fetched '.count($res['participants']).' out of '.$total_count); + $this->logger->logger("Fetched ".count($gres['participants'])." channel participants with filter $filter, query $q, offset $offset, limit $limit, hash $hash: ".($cached ? 'cached' : 'not cached').', '.($offset + count($gres['participants'])).' participants out of '.$gres['count'].', in total fetched '.count($res['participants']).' out of '.$total_count); $offset += count($gres['participants']); } while (count($gres['participants'])); @@ -726,7 +731,7 @@ trait PeerHandler public function store_participants_cache($gres, $channel, $filter, $q, $offset, $limit) { - return; + //return; unset($gres['users']); $ids = []; foreach ($gres['participants'] as $participant) { diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index e062b7ea..f14a2484 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -19,6 +19,7 @@ trait Tools { public function gen_vector_hash($ints) { + sort($ints, SORT_NUMERIC); if (\danog\MadelineProto\Magic::$bigint) { $hash = new \phpseclib\Math\BigInteger(0); foreach ($ints as $int) { diff --git a/tests/testing.php b/tests/testing.php index 6fb05164..c8a479b0 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -77,6 +77,7 @@ if ($MadelineProto->get_self() === false) { \danog\MadelineProto\Logger::log('hey', \danog\MadelineProto\Logger::ERROR); \danog\MadelineProto\Logger::log('hey', \danog\MadelineProto\Logger::FATAL_ERROR); + /** * A small example message to use for tests. */