PFS fixes

This commit is contained in:
Daniil Gentili 2018-12-31 14:02:24 +01:00
parent 4fa1e606a3
commit 5ffae641d2
5 changed files with 24 additions and 11 deletions

View File

@ -80,6 +80,9 @@ class DataCenter
return false; return false;
} }
$ctxs = $this->generate_contexts($dc_number); $ctxs = $this->generate_contexts($dc_number);
if (empty($ctxs)) {
return false;
}
foreach ($ctxs as $ctx) { foreach ($ctxs as $ctx) {
try { try {
if (isset($this->sockets[$dc_number]->old)) { if (isset($this->sockets[$dc_number]->old)) {
@ -242,12 +245,10 @@ class DataCenter
foreach ($ipv6 as $ipv6) { foreach ($ipv6 as $ipv6) {
if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) { if (!isset($this->dclist[$test][$ipv6][$dc_number]['ip_address'])) {
unset($this->sockets[$dc_number]);
$this->API->logger->logger("No info for DC $dc_number", \danog\MadelineProto\Logger::ERROR);
continue; continue;
} }
$address = $this->dclist[$test][$ipv6][$dc_number]['ip_address']; $address = $this->dclist[$test][$ipv6][$dc_number]['ip_address'];
$port = $this->dclist[$test][$ipv6][$dc_number]['port']; $port = $this->dclist[$test][$ipv6][$dc_number]['port'];
@ -307,6 +308,13 @@ class DataCenter
$ctxs = array_merge($ctxs, $this->generate_contexts($dc_number.'_bk')); $ctxs = array_merge($ctxs, $this->generate_contexts($dc_number.'_bk'));
} }
if (empty($ctxs)) {
unset($this->sockets[$dc_number]);
$this->API->logger->logger("No info for DC $dc_number", \danog\MadelineProto\Logger::ERROR);
}
return $ctxs; return $ctxs;
} }

View File

@ -292,7 +292,7 @@ class WriteLoop extends ResumableSignalLoop
$connection->http_req_count++; $connection->http_req_count++;
$API->logger->logger("Sent encrypted payload to DC {$datacenter}, speed ".((($len * 8) / (microtime(true) - $t)) / 1000000).' mbps!', \danog\MadelineProto\Logger::ULTRA_VERBOSE); $API->logger->logger("Sent encrypted payload to DC {$datacenter}", \danog\MadelineProto\Logger::ULTRA_VERBOSE);
$sent = time(); $sent = time();

View File

@ -898,7 +898,7 @@ class MTProto implements TLCallback
} }
$curdc = $this->datacenter->curdc; $curdc = $this->datacenter->curdc;
$this->logger->logger('Got new DC options, reconnecting'); $this->logger->logger('Got new DC options, reconnecting');
yield $this->connect_to_all_dcs(); yield $this->connect_to_all_dcs_async();
$this->datacenter->curdc = $curdc; $this->datacenter->curdc = $curdc;
} }

View File

@ -556,7 +556,7 @@ trait AuthKeyHandler
}; };
} }
yield array_shift($dcs)(); yield array_shift($dcs)();
foreach ($dcs as &$dc) { foreach ($dcs as $id => &$dc) {
$dc = $dc(); $dc = $dc();
} }
yield $dcs; yield $dcs;
@ -592,6 +592,7 @@ trait AuthKeyHandler
$cdn = strpos($id, 'cdn'); $cdn = strpos($id, 'cdn');
$media = strpos($id, 'media'); $media = strpos($id, 'media');
if ($socket->temp_auth_key === null || $socket->auth_key === null) { if ($socket->temp_auth_key === null || $socket->auth_key === null) {
$dc_config_number = isset($this->settings['connection_settings'][$id]) ? $id : 'all'; $dc_config_number = isset($this->settings['connection_settings'][$id]) ? $id : 'all';
if ($socket->auth_key === null && !$cdn && !$media) { if ($socket->auth_key === null && !$cdn && !$media) {

View File

@ -308,12 +308,13 @@ trait ResponseHandler
unset($this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']); unset($this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']);
$request = &$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]; $request = &$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id];
if (isset($request['method']) && $request['method'] && $request['_'] !== 'auth.bindTempAuthKey' && $this->datacenter->sockets[$datacenter]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited'] === false)) {
$this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited'] = true;
}
if (isset($response['_'])) { if (isset($response['_'])) {
switch ($response['_']) { switch ($response['_']) {
case 'rpc_error': case 'rpc_error':
if (isset($request['method']) && $request['method'] && $request['_'] !== 'auth.bindTempAuthKey' && $this->datacenter->sockets[$datacenter]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited'] === false)) {
$this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited'] = true;
}
if (in_array($response['error_message'], ['PERSISTENT_TIMESTAMP_EMPTY', 'PERSISTENT_TIMESTAMP_OUTDATED', 'PERSISTENT_TIMESTAMP_INVALID'])) { if (in_array($response['error_message'], ['PERSISTENT_TIMESTAMP_EMPTY', 'PERSISTENT_TIMESTAMP_OUTDATED', 'PERSISTENT_TIMESTAMP_INVALID'])) {
$this->got_response_for_outgoing_message_id($request_id, $datacenter); $this->got_response_for_outgoing_message_id($request_id, $datacenter);
$this->handle_reject($datacenter, $request, new \danog\MadelineProto\PTSException($response['error_message'])); $this->handle_reject($datacenter, $request, new \danog\MadelineProto\PTSException($response['error_message']));
@ -488,7 +489,6 @@ trait ResponseHandler
break; break;
case 'bad_server_salt': case 'bad_server_salt':
case 'bad_msg_notification': case 'bad_msg_notification':
$this->logger->logger('Received bad_msg_notification: '.self::BAD_MSG_ERROR_CODES[$response['error_code']], \danog\MadelineProto\Logger::WARNING); $this->logger->logger('Received bad_msg_notification: '.self::BAD_MSG_ERROR_CODES[$response['error_code']], \danog\MadelineProto\Logger::WARNING);
switch ($response['error_code']) { switch ($response['error_code']) {
case 48: case 48:
@ -516,6 +516,10 @@ trait ResponseHandler
} }
} }
if (isset($request['method']) && $request['method'] && $request['_'] !== 'auth.bindTempAuthKey' && $this->datacenter->sockets[$datacenter]->temp_auth_key !== null && (!isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) || $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited'] === false)) {
$this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited'] = true;
}
if (!isset($request['promise'])) { if (!isset($request['promise'])) {
$this->logger->logger('Response: already got response for '.(isset($request['_']) ? $request['_'] : '-').' with message ID '.$this->unpack_signed_long($request_id)); $this->logger->logger('Response: already got response for '.(isset($request['_']) ? $request['_'] : '-').' with message ID '.$this->unpack_signed_long($request_id));