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();
}
$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)

View File

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

View File

@ -115,9 +115,9 @@ trait PeerHandler
{
try {
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) {
if ($e->rpc === 'CHAT_FORBIDDEN') return true;
if ($e->rpc === 'CHANNEL_PRIVATE') return true;
return false;
}
}
@ -191,6 +191,10 @@ trait PeerHandler
case 'peerChannel':
$id = $this->to_supergroup($id['channel_id']);
break;
case 'chatForbidden':
case 'channelForbidden':
throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN');
default:
throw new \danog\MadelineProto\Exception('Invalid constructor given '.var_export($id, true));
break;
@ -215,7 +219,13 @@ trait PeerHandler
$this->method_call('messages.getFullChat', ['chat_id' => -$id], ['datacenter' => $this->datacenter->curdc]);
}
if (isset($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) {
$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';
break;
case 'channelForbidden':
throw new \danog\MadelineProto\Exception('Chat forbidden');
throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN');
break;
default:
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'];
while ($offset <= $count) {
@ -543,6 +554,7 @@ trait PeerHandler
public function gen_participants_hash($ids)
{
return 0;
$hash = 0;
if (\danog\MadelineProto\Logger::$bigint) {
return $hash;