Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-10-05 11:07:59 +00:00 committed by StyleCI Bot
parent d076eed6be
commit a52ff32169
5 changed files with 89 additions and 70 deletions

View File

@ -676,33 +676,34 @@ class MTProto
{ {
$this->initing_authorization = true; $this->initing_authorization = true;
$this->updates_state['sync_loading'] = true; $this->updates_state['sync_loading'] = true;
try { try {
foreach ($this->datacenter->sockets as $id => $socket) { foreach ($this->datacenter->sockets as $id => $socket) {
if (strpos($id, 'media')) { if (strpos($id, 'media')) {
continue; continue;
}
$cdn = strpos($id, 'cdn');
if ($socket->session_id === null) {
$socket->session_id = $this->random(8);
$socket->session_in_seq_no = 0;
$socket->session_out_seq_no = 0;
}
if ($socket->temp_auth_key === null || $socket->auth_key === null) {
if ($socket->auth_key === null && !$cdn) {
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_perm_auth_key'], $id)], Logger::NOTICE);
$socket->auth_key = $this->create_auth_key(-1, $id);
} }
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id)], Logger::NOTICE); $cdn = strpos($id, 'cdn');
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id); if ($socket->session_id === null) {
if (!$cdn) { $socket->session_id = $this->random(8);
$this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id); $socket->session_in_seq_no = 0;
$this->get_config($this->write_client_info('help.getConfig', [], ['datacenter' => $id])); $socket->session_out_seq_no = 0;
} }
if (in_array($socket->protocol, ['http', 'https'])) { if ($socket->temp_auth_key === null || $socket->auth_key === null) {
$this->method_call('http_wait', ['max_wait' => 0, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $id]); if ($socket->auth_key === null && !$cdn) {
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_perm_auth_key'], $id)], Logger::NOTICE);
$socket->auth_key = $this->create_auth_key(-1, $id);
}
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['gen_temp_auth_key'], $id)], Logger::NOTICE);
$socket->temp_auth_key = $this->create_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
if (!$cdn) {
$this->bind_temp_auth_key($this->settings['authorization']['default_temp_auth_key_expires_in'], $id);
$this->get_config($this->write_client_info('help.getConfig', [], ['datacenter' => $id]));
}
if (in_array($socket->protocol, ['http', 'https'])) {
$this->method_call('http_wait', ['max_wait' => 0, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $id]);
}
} }
} }
}
} finally { } finally {
$this->initing_authorization = false; $this->initing_authorization = false;
$this->updates_state['sync_loading'] = false; $this->updates_state['sync_loading'] = false;
@ -712,26 +713,28 @@ class MTProto
public function sync_authorization($authorized_dc) public function sync_authorization($authorized_dc)
{ {
$this->updates_state['sync_loading'] = true; $this->updates_state['sync_loading'] = true;
try { try {
foreach ($this->datacenter->sockets as $new_dc => $socket) { foreach ($this->datacenter->sockets as $new_dc => $socket) {
if (($int_dc = preg_replace('|/D+|', '', $new_dc)) == $authorized_dc) { if (($int_dc = preg_replace('|/D+|', '', $new_dc)) == $authorized_dc) {
continue; continue;
}
if ($int_dc != $new_dc) {
continue;
}
\danog\MadelineProto\Logger::log([$int_dc, $new_dc]);
if (strpos($new_dc, '_') !== false) {
continue;
}
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['copy_auth_dcs'], $authorized_dc, $new_dc)], Logger::VERBOSE);
$exported_authorization = $this->method_call('auth.exportAuthorization', ['dc_id' => $new_dc], ['datacenter' => $authorized_dc]);
$this->method_call('auth.logOut', [], ['datacenter' => $new_dc]);
$authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $new_dc]);
} }
if ($int_dc != $new_dc) {
continue;
}
\danog\MadelineProto\Logger::log([$int_dc, $new_dc]);
if (strpos($new_dc, '_') !== false) {
continue;
}
\danog\MadelineProto\Logger::log([sprintf(\danog\MadelineProto\Lang::$current_lang['copy_auth_dcs'], $authorized_dc, $new_dc)], Logger::VERBOSE);
$exported_authorization = $this->method_call('auth.exportAuthorization', ['dc_id' => $new_dc], ['datacenter' => $authorized_dc]);
$this->method_call('auth.logOut', [], ['datacenter' => $new_dc]);
$authorization = $this->method_call('auth.importAuthorization', $exported_authorization, ['datacenter' => $new_dc]);
}
} finally { } finally {
$this->updates_state['sync_loading'] = false; $this->updates_state['sync_loading'] = false;
} }
return $authorization; return $authorization;
} }

View File

@ -501,6 +501,7 @@ trait AuthKeyHandler
public function get_dh_config() public function get_dh_config()
{ {
$this->updates_state['sync_loading'] = true; $this->updates_state['sync_loading'] = true;
try { try {
$dh_config = $this->method_call('messages.getDhConfig', ['version' => $this->dh_config['version'], 'random_length' => 0], ['datacenter' => $this->datacenter->curdc]); $dh_config = $this->method_call('messages.getDhConfig', ['version' => $this->dh_config['version'], 'random_length' => 0], ['datacenter' => $this->datacenter->curdc]);
} finally { } finally {

View File

@ -83,6 +83,7 @@ trait CallHandler
if ($canunset = !$this->updates_state['sync_loading'] && !$this->threads && !$this->run_workers) { if ($canunset = !$this->updates_state['sync_loading'] && !$this->threads && !$this->run_workers) {
$this->updates_state['sync_loading'] = true; $this->updates_state['sync_loading'] = true;
} }
try { try {
\danog\MadelineProto\Logger::log(['Calling method (try number '.$count.' for '.$method.')...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE); \danog\MadelineProto\Logger::log(['Calling method (try number '.$count.' for '.$method.')...'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
@ -210,18 +211,18 @@ trait CallHandler
$last_error = $e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine(); $last_error = $e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine();
\danog\MadelineProto\Logger::log(['An error occurred while calling method '.$method.': '.$last_error.'. Recreating connection and retrying to call method...'], \danog\MadelineProto\Logger::WARNING); \danog\MadelineProto\Logger::log(['An error occurred while calling method '.$method.': '.$last_error.'. Recreating connection and retrying to call method...'], \danog\MadelineProto\Logger::WARNING);
//if (in_array($this->datacenter->sockets[$aargs['datacenter']]->protocol, ['http', 'https']) && $method !== 'http_wait') { //if (in_array($this->datacenter->sockets[$aargs['datacenter']]->protocol, ['http', 'https']) && $method !== 'http_wait') {
//$this->method_call('http_wait', ['max_wait' => $this->datacenter->sockets[$aargs['datacenter']]->timeout, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $aargs['datacenter']]); //$this->method_call('http_wait', ['max_wait' => $this->datacenter->sockets[$aargs['datacenter']]->timeout, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $aargs['datacenter']]);
//} else { //} else {
$this->datacenter->sockets[$aargs['datacenter']]->close_and_reopen(); $this->datacenter->sockets[$aargs['datacenter']]->close_and_reopen();
//} //}
continue; continue;
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
$last_error = $e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine(); $last_error = $e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine();
\danog\MadelineProto\Logger::log(['An error occurred while calling method '.$method.': '.$last_error.'. Recreating connection and retrying to call method...'], \danog\MadelineProto\Logger::WARNING); \danog\MadelineProto\Logger::log(['An error occurred while calling method '.$method.': '.$last_error.'. Recreating connection and retrying to call method...'], \danog\MadelineProto\Logger::WARNING);
//if (in_array($this->datacenter->sockets[$aargs['datacenter']]->protocol, ['http', 'https']) && $method !== 'http_wait') { //if (in_array($this->datacenter->sockets[$aargs['datacenter']]->protocol, ['http', 'https']) && $method !== 'http_wait') {
//$this->method_call('http_wait', ['max_wait' => $this->datacenter->sockets[$aargs['datacenter']]->timeout, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $aargs['datacenter']]); //$this->method_call('http_wait', ['max_wait' => $this->datacenter->sockets[$aargs['datacenter']]->timeout, 'wait_after' => 0, 'max_delay' => 0], ['datacenter' => $aargs['datacenter']]);
//} else { //} else {
$this->datacenter->sockets[$aargs['datacenter']]->close_and_reopen(); $this->datacenter->sockets[$aargs['datacenter']]->close_and_reopen();
//} //}
continue; continue;
} finally { } finally {

View File

@ -193,11 +193,14 @@ trait UpdateHandler
break; break;
case 'updates.channelDifference': case 'updates.channelDifference':
$this->load_channel_state($channel)['sync_loading'] = true; $this->load_channel_state($channel)['sync_loading'] = true;
try { try {
$this->set_channel_state($channel, $difference); $this->set_channel_state($channel, $difference);
$this->handle_update_messages($difference['new_messages'], $channel); $this->handle_update_messages($difference['new_messages'], $channel);
$this->handle_multiple_update($difference['other_updates'], [], $channel); $this->handle_multiple_update($difference['other_updates'], [], $channel);
} finally { $this->load_channel_state($channel)['sync_loading'] = false; } } finally {
$this->load_channel_state($channel)['sync_loading'] = false;
}
if (!$difference['final']) { if (!$difference['final']) {
unset($difference); unset($difference);
$this->get_channel_difference($channel); $this->get_channel_difference($channel);
@ -206,11 +209,14 @@ trait UpdateHandler
case 'updates.channelDifferenceTooLong': case 'updates.channelDifferenceTooLong':
\danog\MadelineProto\Logger::log(['Got '.$difference['_']], \danog\MadelineProto\Logger::VERBOSE); \danog\MadelineProto\Logger::log(['Got '.$difference['_']], \danog\MadelineProto\Logger::VERBOSE);
$this->load_channel_state($channel)['sync_loading'] = true; $this->load_channel_state($channel)['sync_loading'] = true;
try { try {
$this->set_channel_state($channel, $difference); $this->set_channel_state($channel, $difference);
$this->handle_update_messages($difference['messages'], $channel); $this->handle_update_messages($difference['messages'], $channel);
unset($difference); unset($difference);
} finally { $this->load_channel_state($channel)['sync_loading'] = false; } } finally {
$this->load_channel_state($channel)['sync_loading'] = false;
}
$this->get_channel_difference($channel); $this->get_channel_difference($channel);
break; break;
default: default:
@ -274,8 +280,9 @@ trait UpdateHandler
} }
\danog\MadelineProto\Logger::log(['Got '.$difference['_']], \danog\MadelineProto\Logger::ULTRA_VERBOSE); \danog\MadelineProto\Logger::log(['Got '.$difference['_']], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
try { try {
switch ($difference['_']) { switch ($difference['_']) {
case 'updates.differenceEmpty': case 'updates.differenceEmpty':
$this->set_update_state($difference); $this->set_update_state($difference);
break; break;
@ -302,17 +309,22 @@ trait UpdateHandler
throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true)); throw new \danog\MadelineProto\Exception('Unrecognized update difference received: '.var_export($difference, true));
break; break;
} }
} finally { $this->updates_state['sync_loading'] = false; } } finally {
$this->updates_state['sync_loading'] = false;
}
} }
public function get_updates_state() public function get_updates_state()
{ {
$last = $this->updates_state['sync_loading']; $last = $this->updates_state['sync_loading'];
$this->updates_state['sync_loading'] = true; $this->updates_state['sync_loading'] = true;
try { try {
$data = $this->method_call('updates.getState', [], ['datacenter' => $this->datacenter->curdc]); $data = $this->method_call('updates.getState', [], ['datacenter' => $this->datacenter->curdc]);
$this->get_cdn_config($this->datacenter->curdc); $this->get_cdn_config($this->datacenter->curdc);
} finally { $this->updates_state['sync_loading'] = $last; } } finally {
$this->updates_state['sync_loading'] = $last;
}
return $data; return $data;
} }

View File

@ -23,26 +23,28 @@ trait DialogHandler
$res = ['dialogs' => [0], 'count' => 1]; $res = ['dialogs' => [0], 'count' => 1];
$datacenter = $this->datacenter->curdc; $datacenter = $this->datacenter->curdc;
$peers = []; $peers = [];
try { try {
while ($this->dialog_params['count'] < $res['count']) { while ($this->dialog_params['count'] < $res['count']) {
\danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['getting_dialogs']]); \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['getting_dialogs']]);
$res = $this->method_call('messages.getDialogs', $this->dialog_params, ['datacenter' => $datacenter, 'FloodWaitLimit' => 100]); $res = $this->method_call('messages.getDialogs', $this->dialog_params, ['datacenter' => $datacenter, 'FloodWaitLimit' => 100]);
foreach ($res['dialogs'] as $dialog) { foreach ($res['dialogs'] as $dialog) {
if (!in_array($dialog['peer'], $peers)) { if (!in_array($dialog['peer'], $peers)) {
$peers[] = $dialog['peer']; $peers[] = $dialog['peer'];
}
}
$this->dialog_params['count'] += count($res['dialogs']);
$this->dialog_params['offset_date'] = end($res['messages'])['date'];
$this->dialog_params['offset_peer'] = end($res['dialogs'])['peer'];
$this->dialog_params['offset_id'] = end($res['messages'])['id'] & 4294967296;
if (!isset($res['count'])) {
break;
} }
} }
$this->dialog_params['count'] += count($res['dialogs']);
$this->dialog_params['offset_date'] = end($res['messages'])['date'];
$this->dialog_params['offset_peer'] = end($res['dialogs'])['peer'];
$this->dialog_params['offset_id'] = end($res['messages'])['id'] & 4294967296;
if (!isset($res['count'])) {
break;
}
}
} finally { } finally {
$this->updates_state['sync_loading'] = false; $this->updates_state['sync_loading'] = false;
} }
return $peers; return $peers;
} }
} }