Applied fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-09-13 22:15:14 +00:00 committed by StyleCI Bot
parent 016bb106f6
commit 369673b5e9
5 changed files with 25 additions and 18 deletions

View File

@ -61,12 +61,12 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
'max_tries' => [
'query' => 5,
'authorization' => 5,
'response' => 5
'response' => 5,
],
'msg_array_limit' => [
'incoming' => 30,
'outgoing' => 30,
]
],
];
foreach ($default_settings as $key => $param) {
if (!isset($settings[$key])) {

View File

@ -17,7 +17,8 @@ namespace danog\MadelineProto\MTProtoTools;
*/
class CallHandler extends AuthKeyHandler
{
public function wait_for_response($res_id) {
public function wait_for_response($res_id)
{
$response = null;
$count = 0;
while ($response == null && $count++ < $this->settings['max_tries']['response']) {
@ -25,14 +26,14 @@ class CallHandler extends AuthKeyHandler
$deserialized = $this->tl->deserialize(\danog\MadelineProto\Tools::fopen_and_write('php://memory', 'rw+b', $server_answer));
$tempres = $this->handle_message($deserialized);
if ($tempres == null) {
if (isset($this->outgoing_messages[$res_id]["response"])) {
$response = $this->outgoing_messages[$res_id]["response"];
if (isset($this->outgoing_messages[$res_id]['response'])) {
$response = $this->outgoing_messages[$res_id]['response'];
}
} else {
$response = $tempres;
}
}
switch ($response["_"]) {
switch ($response['_']) {
case 'rpc_error':
throw new Exception('Got rpc error '.$response['error_code'].': '.$response['error_message']);
break;
@ -41,13 +42,14 @@ class CallHandler extends AuthKeyHandler
break;
}
}
public function method_call($method, $args)
{
foreach (range(1, $this->settings['max_tries']['query']) as $i) {
try {
$int_message_id = $this->send_message($this->tl->serialize_method($method, $args), $this->tl->content_related($method));
$this->outgoing_messages[$int_message_id]["method"] = $method;
$this->outgoing_messages[$int_message_id]["args"] = $args;
$this->outgoing_messages[$int_message_id]['method'] = $method;
$this->outgoing_messages[$int_message_id]['args'] = $args;
$server_answer = $this->wait_for_response($int_message_id);
} catch (Exception $e) {
$this->log->log('An error occurred while calling method '.$method.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call method...');
@ -58,6 +60,7 @@ class CallHandler extends AuthKeyHandler
if ($server_answer == null) {
throw new Exception('An error occurred while calling method '.$method.'.');
}
return $server_answer;
}
throw new Exception('An error occurred while calling method '.$method.'.');
@ -69,8 +72,8 @@ class CallHandler extends AuthKeyHandler
try {
$int_message_id = $this->send_message($this->tl->serialize_obj($object, $args), $this->tl->content_related($object));
// $server_answer = $this->recv_message();
$this->outgoing_messages[$int_message_id]["method"] = $object;
$this->outgoing_messages[$int_message_id]["args"] = $args;
$this->outgoing_messages[$int_message_id]['method'] = $object;
$this->outgoing_messages[$int_message_id]['args'] = $args;
} catch (Exception $e) {
$this->log->log('An error occurred while calling object '.$object.': '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine().'. Recreating connection and retrying to call object...');
unset($this->sock);

View File

@ -87,5 +87,4 @@ class Crypt extends CallHandler
return $ciphered;
}
}

View File

@ -38,6 +38,7 @@ class MessageHandler extends Crypt
$this->outgoing_messages[$int_message_id]['seq_no'] = $seq_no;
}
$this->sock->send_message($message);
return $int_message_id;
}

View File

@ -34,6 +34,7 @@ class ResponseHandler extends MsgIdHandler
if ($response['req_msg_id'] != key($this->outgoing_messages)) {
throw new Exception('Message id mismatch; req_msg_id ('.$response['req_msg_id'].') != last sent msg id ('.key($this->outgoing_messages).').');
}
return $this->handle_response($response['result'], $response['req_msg_id']);
break;
@ -44,13 +45,14 @@ class ResponseHandler extends MsgIdHandler
throw new Exception('Message id mismatch; req_msg_id ('.$response['req_msg_id'].') != last sent msg id ('.key($this->outgoing_messages).').');
}
$this->log->log('Received future salts.');
return $this->handle_response($response, $response['req_msg_id']);
break;
case 'pong':
foreach ($this->outgoing_messages as $omessage) {
if ($omessage["args"]["ping_id"] == $response["ping_id"]) {
$this->outgoing_messages[$response["msg_id"]]["response"] = $response;
if ($omessage['args']['ping_id'] == $response['ping_id']) {
$this->outgoing_messages[$response['msg_id']]['response'] = $response;
}
}
break;
@ -65,7 +67,7 @@ class ResponseHandler extends MsgIdHandler
$this->log->log('Received container.');
$this->log->log($response['messages']);
foreach ($response['messages'] as $message) {
$this->incoming_messages[$message['msg_id']] = [ 'seq_no' => $message['seqno']];
$this->incoming_messages[$message['msg_id']] = ['seq_no' => $message['seqno']];
$responses[] = $this->handle_message($message['body']);
}
foreach ($responses as $response) {
@ -91,7 +93,9 @@ class ResponseHandler extends MsgIdHandler
break;
}
}
public function handle_response($response, $res_id = null) {
public function handle_response($response, $res_id = null)
{
if ($res_id == null) {
return $response;
}
@ -100,7 +104,7 @@ class ResponseHandler extends MsgIdHandler
case 'rpc_answer_dropped':
$this->ack_outgoing_message_id($response['req_msg_id']); // Acknowledge that the server received the original query (the same one, the response to which we wish to forget)
default:
$this->outgoing_messages[$res_id]["response"] = $response;
$this->outgoing_messages[$res_id]['response'] = $response;
break;
}
}