Improve peer management and connection management

This commit is contained in:
Daniil Gentili 2018-03-09 16:39:13 +00:00
parent 9de3f24215
commit 87f2ec50ac
3 changed files with 20 additions and 6 deletions

View File

@ -209,7 +209,6 @@ class Connection
throw new Bug74586Exception(); throw new Bug74586Exception();
} }
$this->time_delta = 0; $this->time_delta = 0;
//$this->__construct($this->proxy, $this->extra, $this->ip, $this->port, $this->protocol, $this->timeout, $this->ipv6);
} }
public function write($what, $length = null) public function write($what, $length = null)

View File

@ -216,6 +216,9 @@ class MTProto
if (isset($settings['authorization']['rsa_key'])) { if (isset($settings['authorization']['rsa_key'])) {
unset($settings['authorization']['rsa_key']); unset($settings['authorization']['rsa_key']);
} }
if (!isset($this->full_chats)) $this->full_chats = [];
if (!isset($this->secret_chats)) $this->secret_chats = [];
foreach ($this->full_chats as $id => $full) { foreach ($this->full_chats as $id => $full) {
$this->full_chats[$id] = ['full' => $full['full'], 'last_update' => $full['last_update']]; $this->full_chats[$id] = ['full' => $full['full'], 'last_update' => $full['last_update']];
} }
@ -266,7 +269,7 @@ class MTProto
$this->channels_state = []; $this->channels_state = [];
$this->got_state = false; $this->got_state = false;
} }
//$this->connect_to_all_dcs(); $this->connect_to_all_dcs();
//datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); //datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']);
foreach ($this->calls as $id => $controller) { foreach ($this->calls as $id => $controller) {
if (!is_object($controller)) { if (!is_object($controller)) {

View File

@ -115,9 +115,9 @@ trait PeerHandler
{ {
try { try {
return isset($this->chats[$this->get_info($id)['bot_api_id']]); return isset($this->chats[$this->get_info($id)['bot_api_id']]);
} catch (\danog\MadelineProto\Exception $e) {
return $e->getMessage() === 'Chat forbidden';
} catch (\danog\MadelineProto\RPCErrorException $e) { } catch (\danog\MadelineProto\RPCErrorException $e) {
if ($e->rpc === 'CHAT_FORBIDDEN') return true;
if ($e->rpc === 'CHANNEL_PRIVATE') return true;
return false; return false;
} }
} }
@ -191,6 +191,10 @@ trait PeerHandler
case 'peerChannel': case 'peerChannel':
$id = $this->to_supergroup($id['channel_id']); $id = $this->to_supergroup($id['channel_id']);
break; break;
case 'chatForbidden':
case 'channelForbidden':
throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN');
default: default:
throw new \danog\MadelineProto\Exception('Invalid constructor given '.var_export($id, true)); throw new \danog\MadelineProto\Exception('Invalid constructor given '.var_export($id, true));
break; break;
@ -215,7 +219,13 @@ trait PeerHandler
$this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]); $this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]);
} }
if (isset($this->chats[$id])) { if (isset($this->chats[$id])) {
return $this->gen_all($this->chats[$id]); try {
return $this->gen_all($this->chats[$id]);
} catch (\danog\MadelineProto\Exception $e) {
if ($e->getMessage() === 'This peer is not present in the internal peer database') {
unset($this->chats[$id]);
} else throw $e;
}
} }
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true && $recursive) { if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true && $recursive) {
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true); $dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true);
@ -294,7 +304,7 @@ trait PeerHandler
$res['type'] = $constructor['megagroup'] ? 'supergroup' : 'channel'; $res['type'] = $constructor['megagroup'] ? 'supergroup' : 'channel';
break; break;
case 'channelForbidden': case 'channelForbidden':
throw new \danog\MadelineProto\Exception('Chat forbidden'); throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN');
break; break;
default: default:
throw new \danog\MadelineProto\Exception('Invalid constructor given '.var_export($constructor, true)); throw new \danog\MadelineProto\Exception('Invalid constructor given '.var_export($constructor, true));
@ -479,6 +489,7 @@ trait PeerHandler
} }
} }
if ($gres['_'] === 'channels.channelParticipantsNotModified') continue;
$count = $gres['count']; $count = $gres['count'];
while ($offset <= $count) { while ($offset <= $count) {
@ -543,6 +554,7 @@ trait PeerHandler
public function gen_participants_hash($ids) public function gen_participants_hash($ids)
{ {
return 0;
$hash = 0; $hash = 0;
if (\danog\MadelineProto\Logger::$bigint) { if (\danog\MadelineProto\Logger::$bigint) {
return $hash; return $hash;