Fixed datacenter class

This commit is contained in:
danogentili 2016-10-09 19:40:20 +02:00
parent 352a7a249f
commit adff633caf
3 changed files with 14 additions and 6 deletions

View File

@ -13,7 +13,7 @@ If not, see <http://www.gnu.org/licenses/>.
namespace danog\MadelineProto; namespace danog\MadelineProto;
/** /**
* Manages all of the mtproto stuff. * Manages datacenters.
*/ */
class DataCenter extends Tools class DataCenter extends Tools
{ {
@ -36,10 +36,18 @@ class DataCenter extends Tools
]; ];
} }
} }
$this->dc_connect(2);
} }
public function connnect($dc_number, $settings = []) public function dc_disconnect($dc_number) {
unset($this->sockets[$dc_number]);
}
public function dc_connect($dc_number, $settings = [])
{ {
if (isset($this->sockets[$dc_number])) {
return;
}
if ($settings == []) { if ($settings == []) {
$settings = $this->settings[$dc_number]; $settings = $this->settings[$dc_number];
} }

View File

@ -62,6 +62,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
'all' => [ 'all' => [
'protocol' => 'tcp_full', 'protocol' => 'tcp_full',
'test_mode' => true, 'test_mode' => true,
'port' => '443',
], ],
], ],
'app_info' => [ 'app_info' => [
@ -104,8 +105,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
// Connect to servers // Connect to servers
$this->connection = new DataCenter($this->settings['connection'], $this->settings['connection_settings']); $this->connection = new DataCenter($this->settings['connection'], $this->settings['connection_settings']);
var_dump($this->connection); $this->connection->dc_connect(2);
$this->connection->connect(2);
// Load rsa key // Load rsa key
$this->key = new RSA($settings['authorization']['rsa_key']); $this->key = new RSA($settings['authorization']['rsa_key']);

View File

@ -419,7 +419,7 @@ class AuthKeyHandler extends AckHandler
throw new Exception('Handshake: wrong new_nonce_hash1'); throw new Exception('Handshake: wrong new_nonce_hash1');
} }
$this->log->log('Diffie Hellman key exchange processed successfully'); $this->log->log('Handshake: Diffie Hellman key exchange processed successfully');
$res_authorization['server_salt'] = $this->struct->unpack('<q', substr($new_nonce, 0, 8 - 0) ^ substr($server_nonce, 0, 8 - 0))[0]; $res_authorization['server_salt'] = $this->struct->unpack('<q', substr($new_nonce, 0, 8 - 0) ^ substr($server_nonce, 0, 8 - 0))[0];
$res_authorization['auth_key'] = $auth_key_str; $res_authorization['auth_key'] = $auth_key_str;
@ -429,7 +429,7 @@ class AuthKeyHandler extends AckHandler
$res_authorization['expires_in'] = $expires_in; $res_authorization['expires_in'] = $expires_in;
} }
$this->log->log('Auth key generated'); $this->log->log('Handshake: Auth key generated');
$this->timedelta = 0; $this->timedelta = 0;
return $res_authorization; return $res_authorization;