2016-09-10 19:53:08 +02:00
< ? php
2018-02-24 17:54:13 +01:00
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
/**
* MTProto module .
*
* This file is part of MadelineProto .
* MadelineProto is free software : you can redistribute it and / or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation , either version 3 of the License , or ( at your option ) any later version .
* MadelineProto is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
* See the GNU Affero General Public License for more details .
* You should have received a copy of the GNU General Public License along with MadelineProto .
* If not , see < http :// www . gnu . org / licenses />.
*
* @ author Daniil Gentili < daniil @ daniil . it >
2020-02-17 14:13:46 +01:00
* @ copyright 2016 - 2020 Daniil Gentili < daniil @ daniil . it >
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
* @ license https :// opensource . org / licenses / AGPL - 3.0 AGPLv3
*
2019-10-31 15:07:35 +01:00
* @ link https :// docs . madelineproto . xyz MadelineProto documentation
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
*/
2018-02-24 17:54:39 +01:00
2016-09-10 19:53:08 +02:00
namespace danog\MadelineProto ;
2019-10-31 12:45:19 +01:00
use Amp\Dns\Resolver ;
2020-02-26 12:45:30 +01:00
use Amp\File\StatCache ;
2020-03-08 17:24:31 +01:00
use Amp\Http\Client\HttpClient ;
2020-09-24 11:45:20 +02:00
use Amp\Loop ;
2020-05-03 03:33:54 +02:00
use Amp\Promise ;
2020-09-24 23:25:54 +02:00
use Amp\Success ;
2020-09-22 11:48:12 +02:00
use Closure ;
2019-05-29 15:17:14 +02:00
use danog\MadelineProto\Async\AsyncConstruct ;
2020-04-25 21:57:55 +02:00
use danog\MadelineProto\Db\DbArray ;
2020-09-12 14:24:57 +02:00
use danog\MadelineProto\Db\DbPropertiesFactory ;
2020-06-07 00:00:44 +02:00
use danog\MadelineProto\Db\DbPropertiesTrait ;
2020-09-24 23:25:54 +02:00
use danog\MadelineProto\Db\MemoryArray ;
2020-07-11 20:01:54 +02:00
use danog\MadelineProto\Ipc\Server ;
2020-07-28 20:39:32 +02:00
use danog\MadelineProto\Loop\Generic\PeriodicLoopInternal ;
2019-05-30 13:28:50 +02:00
use danog\MadelineProto\Loop\Update\FeedLoop ;
use danog\MadelineProto\Loop\Update\SeqLoop ;
use danog\MadelineProto\Loop\Update\UpdateLoop ;
2019-05-29 15:17:14 +02:00
use danog\MadelineProto\MTProtoTools\CombinedUpdatesState ;
2020-06-16 17:52:55 +02:00
use danog\MadelineProto\MTProtoTools\GarbageCollector ;
2019-09-13 16:55:48 +02:00
use danog\MadelineProto\MTProtoTools\MinDatabase ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
use danog\MadelineProto\MTProtoTools\ReferenceDatabase ;
2019-05-11 20:38:26 +02:00
use danog\MadelineProto\MTProtoTools\UpdatesState ;
2020-09-22 11:48:12 +02:00
use danog\MadelineProto\Settings\Database\Memory ;
use danog\MadelineProto\Settings\TLSchema ;
2019-10-31 20:48:06 +01:00
use danog\MadelineProto\TL\TL ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
use danog\MadelineProto\TL\TLCallback ;
2020-09-26 17:11:41 +02:00
use Psr\Log\LoggerInterface ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
2020-02-26 12:45:30 +01:00
use function Amp\File\exists ;
use function Amp\File\size ;
2016-09-10 19:53:08 +02:00
/**
2016-09-12 22:28:27 +02:00
* Manages all of the mtproto stuff .
2020-10-17 12:47:05 +02:00
*
* @ internal
2016-09-10 19:53:08 +02:00
*/
2019-05-22 17:35:16 +02:00
class MTProto extends AsyncConstruct implements TLCallback
2016-09-10 19:53:28 +02:00
{
2017-05-16 15:12:04 +02:00
use \danog\Serializable ;
2016-12-19 16:56:52 +01:00
use \danog\MadelineProto\MTProtoTools\AuthKeyHandler ;
use \danog\MadelineProto\MTProtoTools\CallHandler ;
2016-12-23 12:19:13 +01:00
use \danog\MadelineProto\MTProtoTools\PeerHandler ;
use \danog\MadelineProto\MTProtoTools\UpdateHandler ;
2017-03-11 19:54:51 +01:00
use \danog\MadelineProto\MTProtoTools\Files ;
2017-03-24 21:01:08 +01:00
use \danog\MadelineProto\SecretChats\AuthKeyHandler ;
use \danog\MadelineProto\SecretChats\MessageHandler ;
2017-03-31 17:35:20 +02:00
use \danog\MadelineProto\SecretChats\ResponseHandler ;
use \danog\MadelineProto\SecretChats\SeqNoHandler ;
2017-03-24 21:01:08 +01:00
use \danog\MadelineProto\TL\Conversion\BotAPI ;
use \danog\MadelineProto\TL\Conversion\BotAPIFiles ;
use \danog\MadelineProto\TL\Conversion\TD ;
2017-04-01 13:20:57 +02:00
use \danog\MadelineProto\VoIP\AuthKeyHandler ;
2017-05-18 12:12:33 +02:00
use \danog\MadelineProto\Wrappers\DialogHandler ;
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
use \danog\MadelineProto\Wrappers\Events ;
use \danog\MadelineProto\Wrappers\Webhook ;
use \danog\MadelineProto\Wrappers\Callback ;
2017-05-18 12:12:33 +02:00
use \danog\MadelineProto\Wrappers\Login ;
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
use \danog\MadelineProto\Wrappers\Loop ;
2018-04-17 10:39:55 +02:00
use \danog\MadelineProto\Wrappers\Noop ;
Documentation rework (#349)
* Documentation rework
* Apply fixes from StyleCI
* Documentation fixes
* Login as bot through web/cli API, allow using invite links in joinChannel, full invite links in importChatInvite and checkChatInvite, non-invite links in importChatInvite
* Apply fixes from StyleCI
* Logging fixes
* Build docs
* Add methods to modify start template, bugfix to logging and keyboard conversion
* Add TL documentator
* Document MTProto methods
* Documenting methods...
* 7% documented
* Bugfixes
* Update docs
* Update docs
* Simplify file management
* Implement automatic object conversion for media, and more awesome stuff
* Implement automatic object conversion for media, and more awesome stuff
* Implement event update handler and file upload/download callback
* Auto-detect mime type, duration, width and height of media
* Update docs
* Document new file functions
* Fix links
* Fix links
* Update bot.php to use event loop
* Implement webhook update handler and forking in main loop
* Build docs
* Better docs
* Fixes to secret chats
* Almost finished updating docs
* Bugfixes, implemented infinite loop for loop() method, almost finished docs
* Finish writing docs
* Add automatic documentation builder script
* Finished writing docs
2018-03-20 12:48:05 +01:00
use \danog\MadelineProto\Wrappers\Start ;
use \danog\MadelineProto\Wrappers\Templates ;
2018-06-29 13:50:14 +02:00
use \danog\MadelineProto\Wrappers\TOS ;
2020-06-07 00:00:44 +02:00
use DbPropertiesTrait ;
2019-09-02 16:54:36 +02:00
/**
* Old internal version of MadelineProto .
*
* DO NOT REMOVE THIS COMMENTED OUT CONSTANT
*
* @ var int
*/
2017-08-27 20:21:24 +02:00
/*
2020-01-31 19:29:43 +01:00
const V = 71 ;
*/
2019-09-01 14:07:04 +02:00
/**
* Internal version of MadelineProto .
*
* Increased every time the default settings array or something big changes
*
2020-10-15 19:07:37 +02:00
* @ internal
*
2019-09-01 14:07:04 +02:00
* @ var int
*/
2020-09-12 19:06:42 +02:00
const V = 147 ;
2019-09-01 14:07:04 +02:00
/**
2020-10-08 11:27:37 +02:00
* Release version .
2019-09-01 14:07:04 +02:00
*
* @ var string
*/
const RELEASE = '5.0' ;
/**
* We ' re not logged in .
*
* @ var int
*/
2017-05-27 23:21:14 +02:00
const NOT_LOGGED_IN = 0 ;
2019-09-01 14:07:04 +02:00
/**
* We ' re waiting for the login code .
*
* @ var int
*/
2017-05-27 23:21:14 +02:00
const WAITING_CODE = 1 ;
2019-09-01 14:07:04 +02:00
/**
* We ' re waiting for parameters to sign up .
*
* @ var int
*/
2017-05-28 19:05:08 +02:00
const WAITING_SIGNUP = - 1 ;
2019-09-01 14:07:04 +02:00
/**
* We ' re waiting for the 2 FA password .
*
* @ var int
*/
2017-05-27 23:21:14 +02:00
const WAITING_PASSWORD = 2 ;
2019-09-01 14:07:04 +02:00
/**
* We ' re logged in .
*
* @ var int
*/
2017-05-27 23:21:14 +02:00
const LOGGED_IN = 3 ;
2019-09-01 14:07:04 +02:00
/**
* Bad message error codes .
*
2020-10-08 11:27:37 +02:00
* @ internal
2020-10-08 21:35:32 +02:00
*
2019-09-01 14:07:04 +02:00
* @ var array
*/
2020-01-31 19:29:43 +01:00
const BAD_MSG_ERROR_CODES = [ 16 => 'msg_id too low (most likely, client time is wrong; it would be worthwhile to synchronize it using msg_id notifications and re-send the original message with the “correct†msg_id or wrap it in a container with a new msg_id if the original message had waited too long on the client to be transmitted)' , 17 => 'msg_id too high (similar to the previous case, the client time has to be synchronized, and the message re-sent with the correct msg_id)' , 18 => 'incorrect two lower order msg_id bits (the server expects client message msg_id to be divisible by 4)' , 19 => 'container msg_id is the same as msg_id of a previously received message (this must never happen)' , 20 => 'message too old, and it cannot be verified whether the server has received a message with this msg_id or not' , 32 => 'msg_seqno too low (the server has already received a message with a lower msg_id but with either a higher or an equal and odd seqno)' , 33 => 'msg_seqno too high (similarly, there is a message with a higher msg_id but with either a lower or an equal and odd seqno)' , 34 => 'an even msg_seqno expected (irrelevant message), but odd received' , 35 => 'odd msg_seqno expected (relevant message), but even received' , 48 => 'incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it)' , 64 => 'invalid container' ];
2019-09-01 14:07:04 +02:00
/**
2019-09-01 23:39:29 +02:00
* Localized message info flags .
*
2020-10-08 11:27:37 +02:00
* @ internal
2020-10-08 21:35:32 +02:00
*
2019-09-01 14:07:04 +02:00
* @ var array
*/
2020-01-31 19:29:43 +01:00
const MSGS_INFO_FLAGS = [ 1 => 'nothing is known about the message (msg_id too low, the other party may have forgotten it)' , 2 => 'message not received (msg_id falls within the range of stored identifiers; however, the other party has certainly not received a message like that)' , 3 => 'message not received (msg_id too high; however, the other party has certainly not received it yet)' , 4 => 'message received (note that this response is also at the same time a receipt acknowledgment)' , 8 => ' and message already acknowledged' , 16 => ' and message not requiring acknowledgment' , 32 => ' and RPC query contained in message being processed or processing already complete' , 64 => ' and content-related response to message already generated' , 128 => ' and other party knows for a fact that message is already received' ];
2019-10-31 20:48:06 +01:00
/**
* Secret chat was not found .
*
* @ var int
*/
const SECRET_EMPTY = 0 ;
/**
* Secret chat was requested .
*
* @ var int
*/
const SECRET_REQUESTED = 1 ;
/**
* Secret chat was found .
*
* @ var int
*/
const SECRET_READY = 2 ;
2020-10-08 11:27:37 +02:00
/**
* @ internal
*/
2020-09-22 11:48:12 +02:00
const GETUPDATES_HANDLER = 'getUpdates' ;
2020-10-08 11:27:37 +02:00
/**
* @ internal
*/
2020-10-01 18:02:54 +02:00
const TD_PARAMS_CONVERSION = [ 'updateNewMessage' => [ '_' => 'updateNewMessage' , 'disable_notification' => [ 'message' , 'silent' ], 'message' => [ 'message' ]], 'message' => [ '_' => 'message' , 'id' => [ 'id' ], 'sender_user_id' => [ 'from_id' ], 'chat_id' => [ 'peer_id' , 'choose_chat_id_from_botapi' ], 'send_state' => [ 'choose_incoming_or_sent' ], 'can_be_edited' => [ 'choose_can_edit' ], 'can_be_deleted' => [ 'choose_can_delete' ], 'is_post' => [ 'post' ], 'date' => [ 'date' ], 'edit_date' => [ 'edit_date' ], 'forward_info' => [ 'fwd_info' , 'choose_forward_info' ], 'reply_to_message_id' => [ 'reply_to_msg_id' ], 'ttl' => [ 'choose_ttl' ], 'ttl_expires_in' => [ 'choose_ttl_expires_in' ], 'via_bot_user_id' => [ 'via_bot_id' ], 'views' => [ 'views' ], 'content' => [ 'choose_message_content' ], 'reply_markup' => [ 'reply_markup' ]], 'messages.sendMessage' => [ 'chat_id' => [ 'peer' ], 'reply_to_message_id' => [ 'reply_to_msg_id' ], 'disable_notification' => [ 'silent' ], 'from_background' => [ 'background' ], 'input_message_content' => [ 'choose_message_content' ], 'reply_markup' => [ 'reply_markup' ]]];
2020-10-08 11:27:37 +02:00
/**
* @ internal
*/
2018-02-24 17:54:13 +01:00
const TD_REVERSE = [ 'sendMessage' => 'messages.sendMessage' ];
2020-10-08 11:27:37 +02:00
/**
* @ internal
*/
2017-05-28 04:32:42 +02:00
const TD_IGNORE = [ 'updateMessageID' ];
2020-10-08 11:27:37 +02:00
/**
* @ internal
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
const BOTAPI_PARAMS_CONVERSION = [ 'disable_web_page_preview' => 'no_webpage' , 'disable_notification' => 'silent' , 'reply_to_message_id' => 'reply_to_msg_id' , 'chat_id' => 'peer' , 'text' => 'message' ];
2020-10-08 11:27:37 +02:00
/**
* @ internal
*/
2020-09-22 23:10:56 +02:00
const DEFAULT_GETUPDATES_PARAMS = [ 'offset' => 0 , 'limit' => null , 'timeout' => 100 ];
2020-09-27 21:51:55 +02:00
/**
* Array of references to all instances of MTProto .
*
* This seems like a recipe for memory leaks , but this is actually required to allow saving the session on shutdown .
* When using a network I / O - based database + the EvDriver of AMPHP , calling die (); causes premature garbage collection of the event loop .
* This garbage collection happens always , even if a reference to the event handler is already present elsewhere ( probably ev dark magic ) .
*
* Finally , this causes the process to hang on shutdown , since the database driver cannot receive a reply from the server , because the event loop is down .
*
* To avoid this , we store each MTProto instance in here ( unreferencing on shutdown in unreference ()), and call serialize () on all instances before calling die ; in Magic .
*
* @ var self []
*/
public static array $references = [];
2019-09-01 14:07:04 +02:00
/**
* Instance of wrapper API .
*
2020-09-25 19:17:16 +02:00
* @ var APIWrapper
2019-09-01 14:07:04 +02:00
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public $wrapper ;
2019-09-01 14:07:04 +02:00
/**
* PWRTelegram webhook URL .
*
* @ var boolean | string
*/
2017-06-15 14:27:59 +02:00
public $hook_url = false ;
2019-09-01 14:07:04 +02:00
/**
* Settings array .
*
2020-09-22 11:48:12 +02:00
* @ var Settings
2019-09-01 14:07:04 +02:00
*/
2020-09-22 11:48:12 +02:00
public $settings ;
2019-09-01 14:07:04 +02:00
/**
* Config array .
*
* @ var array
*/
2017-05-27 23:21:14 +02:00
private $config = [ 'expires' => - 1 ];
2019-09-01 14:07:04 +02:00
/**
* TOS info .
*
* @ var array
*/
2018-06-29 13:50:14 +02:00
private $tos = [ 'expires' => 0 , 'accepted' => true ];
2019-09-01 14:07:04 +02:00
/**
* Whether we ' re initing authorization .
*
* @ var boolean
*/
2018-02-18 14:18:18 +01:00
private $initing_authorization = false ;
2019-09-01 14:07:04 +02:00
/**
* Authorization info ( User ) .
*
2019-10-31 15:06:25 +01:00
* @ var array | null
2019-09-01 14:07:04 +02:00
*/
2017-05-27 23:21:14 +02:00
public $authorization = null ;
2019-09-01 14:07:04 +02:00
/**
* Whether we ' re authorized .
*
2020-10-03 15:04:35 +02:00
* @ var int
* @ psalm - var self :: NOT_LOGGED_IN | self :: WAITING_ *| self :: LOGGED_IN
2019-09-01 14:07:04 +02:00
*/
public $authorized = self :: NOT_LOGGED_IN ;
/**
* Main authorized DC ID .
*
* @ var integer
*/
2018-02-18 14:18:18 +01:00
public $authorized_dc = - 1 ;
2019-09-01 14:07:04 +02:00
/**
* RSA keys .
*
* @ var array < RSA >
*/
2017-05-27 23:21:14 +02:00
private $rsa_keys = [];
2019-09-01 14:07:04 +02:00
/**
* CDN RSA keys .
*
* @ var array
*/
2019-06-29 14:54:12 +02:00
private $cdn_rsa_keys = [];
2019-09-01 14:07:04 +02:00
/**
* Diffie - hellman config .
*
* @ var array
*/
2017-05-27 23:21:14 +02:00
private $dh_config = [ 'version' => 0 ];
2019-09-01 14:07:04 +02:00
/**
* Internal peer database .
*
2020-08-31 00:39:25 +02:00
* @ var DbArray | Promise []
2019-09-01 14:07:04 +02:00
*/
2020-04-25 21:57:55 +02:00
public $chats ;
2020-04-28 02:41:06 +02:00
/**
2020-06-16 17:52:55 +02:00
* Cache of usernames for chats .
2020-04-28 02:41:06 +02:00
*
2020-05-03 03:33:54 +02:00
* @ var DbArray | Promise []
2020-04-28 02:41:06 +02:00
*/
public $usernames ;
2019-09-01 14:07:04 +02:00
/**
* Cached parameters for fetching channel participants .
*
2020-05-03 03:33:54 +02:00
* @ var DbArray | Promise []
2019-09-01 14:07:04 +02:00
*/
2020-04-25 21:57:55 +02:00
public $channel_participants ;
2019-09-01 23:39:29 +02:00
/**
* When we last stored data in remote peer database ( now doesn ' t exist anymore ) .
*
* @ var integer
*/
2017-05-27 23:21:14 +02:00
public $last_stored = 0 ;
2019-09-01 23:39:29 +02:00
/**
* Temporary array of data to be sent to remote peer database .
*
* @ var array
*/
2017-05-27 23:21:14 +02:00
public $qres = [];
2019-09-01 23:39:29 +02:00
/**
* Full chat info database .
*
2020-05-03 03:33:54 +02:00
* @ var DbArray | Promise []
2019-09-01 23:39:29 +02:00
*/
2020-04-25 21:57:55 +02:00
public $full_chats ;
2019-09-01 23:39:29 +02:00
/**
* Latest chat message ID map for update handling .
*
* @ var array
*/
2017-05-18 12:12:33 +02:00
private $msg_ids = [];
2019-09-01 23:39:29 +02:00
/**
* Version integer for upgrades .
*
* @ var integer
*/
2017-05-27 23:21:14 +02:00
private $v = 0 ;
2019-09-01 23:39:29 +02:00
/**
* Cached getdialogs params .
*
* @ var array
*/
private $dialog_params = [ 'limit' => 0 , 'offset_date' => 0 , 'offset_id' => 0 , 'offset_peer' => [ '_' => 'inputPeerEmpty' ], 'count' => 0 ];
/**
* Support user ID .
*
* @ var integer
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
private $supportUser = 0 ;
2019-09-01 23:39:29 +02:00
/**
* File reference database .
*
* @ var \danog\MadelineProto\MTProtoTools\ReferenceDatabase
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public $referenceDatabase ;
2019-09-13 16:55:48 +02:00
/**
* min database .
*
* @ var \danog\MadelineProto\MTProtoTools\MinDatabase
*/
public $minDatabase ;
2019-09-17 21:35:53 +02:00
/**
* TOS check loop .
*/
2020-07-28 20:39:32 +02:00
public ? PeriodicLoopInternal $checkTosLoop = null ;
2019-09-01 23:39:29 +02:00
/**
* Phone config loop .
*/
2020-07-28 20:39:32 +02:00
public ? PeriodicLoopInternal $phoneConfigLoop = null ;
2019-09-17 21:35:53 +02:00
/**
* Config loop .
*/
2020-07-28 20:39:32 +02:00
public ? PeriodicLoopInternal $configLoop = null ;
2019-09-01 23:39:29 +02:00
/**
* Call checker loop .
*/
2020-07-28 20:39:32 +02:00
private ? PeriodicLoopInternal $callCheckerLoop = null ;
2019-09-01 23:39:29 +02:00
/**
* Autoserialization loop .
*/
2020-07-28 20:39:32 +02:00
private ? PeriodicLoopInternal $serializeLoop = null ;
2020-07-09 18:23:16 +02:00
/**
* RPC reporting loop .
*/
2020-07-28 20:39:32 +02:00
private ? PeriodicLoopInternal $rpcLoop = null ;
2020-10-03 15:04:35 +02:00
/**
* SEQ update loop .
*/
private ? SeqLoop $seqUpdater = null ;
2020-07-11 20:01:54 +02:00
/**
* IPC server .
*/
2020-07-28 20:39:32 +02:00
private ? Server $ipcServer = null ;
2019-09-01 23:39:29 +02:00
/**
* Feeder loops .
*
* @ var array < \danog\MadelineProto\Loop\Update\FeedLoop >
*/
2019-05-29 15:17:14 +02:00
public $feeders = [];
2019-09-01 23:39:29 +02:00
/**
* Updater loops .
*
* @ var array < \danog\MadelineProto\Loop\Update\UpdateLoop >
*/
2019-05-29 15:17:14 +02:00
public $updaters = [];
2019-09-01 14:07:04 +02:00
/**
* DataCenter instance .
*
* @ var DataCenter
*/
public $datacenter ;
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Logger instance .
2019-10-31 12:45:19 +01:00
*
* @ var Logger
*/
public $logger ;
2019-10-31 20:48:06 +01:00
/**
* TL serializer .
*
* @ var \danog\MadelineProto\TL\TL
*/
private $TL ;
2020-04-25 21:57:55 +02:00
2020-07-09 20:53:01 +02:00
/**
* Snitch .
*/
private Snitch $snitch ;
2020-09-22 11:48:12 +02:00
/**
* DC list .
*/
protected array $dcList = [
'test' => [
// Test datacenters
'ipv4' => [
// ipv4 addresses
2 => [
// The rest will be fetched using help.getConfig
'ip_address' => '149.154.167.40' ,
'port' => 443 ,
'media_only' => false ,
'tcpo_only' => false ,
],
],
'ipv6' => [
// ipv6 addresses
2 => [
// The rest will be fetched using help.getConfig
'ip_address' => '2001:067c:04e8:f002:0000:0000:0000:000e' ,
'port' => 443 ,
'media_only' => false ,
'tcpo_only' => false ,
],
],
],
'main' => [
// Main datacenters
'ipv4' => [
// ipv4 addresses
2 => [
// The rest will be fetched using help.getConfig
'ip_address' => '149.154.167.51' ,
'port' => 443 ,
'media_only' => false ,
'tcpo_only' => false ,
],
],
'ipv6' => [
// ipv6 addresses
2 => [
// The rest will be fetched using help.getConfig
'ip_address' => '2001:067c:04e8:f002:0000:0000:0000:000a' ,
'port' => 443 ,
'media_only' => false ,
'tcpo_only' => false ,
],
],
]
];
2020-09-24 23:25:54 +02:00
/**
* Nullcache array for storing main session file to DB .
*
* @ var DbArray | Promise []
*/
public $session ;
2020-04-25 21:57:55 +02:00
/**
2020-06-16 17:52:55 +02:00
* List of properties stored in database ( memory or external ) .
2020-09-12 14:24:57 +02:00
* @ see DbPropertiesFactory
2020-04-25 21:57:55 +02:00
* @ var array
*/
2020-09-12 15:14:26 +02:00
protected static array $dbProperties = [
2020-04-25 21:57:55 +02:00
'chats' => 'array' ,
'full_chats' => 'array' ,
2020-04-27 02:21:18 +02:00
'channel_participants' => 'array' ,
2020-04-28 02:41:06 +02:00
'usernames' => 'array' ,
2020-09-25 22:17:05 +02:00
'session' => [
'type' => 'array' ,
'config' => [ 'enableCache' => false ]
]
2020-04-25 21:57:55 +02:00
];
2020-09-24 23:25:54 +02:00
/**
* Serialize session , returning object to serialize to db .
*
* @ return \Generator
*/
public function serializeSession ( object $data ) : \Generator
{
2020-09-24 23:46:15 +02:00
if ( ! $this -> session || $this -> session instanceof MemoryArray ) {
2020-09-24 23:25:54 +02:00
return $data ;
}
2020-09-27 19:36:17 +02:00
yield $this -> session -> offsetSet ( 'data' , $data );
2020-09-24 23:25:54 +02:00
return $this -> session ;
}
2020-09-27 21:51:55 +02:00
/**
* Serialize all instances .
*
* CALLED ONLY ON SHUTDOWN .
*
* @ return void
*/
public static function serializeAll () : void
{
Logger :: log ( 'Prompting final serialization (SHUTDOWN)...' );
foreach ( self :: $references as $instance ) {
Tools :: wait ( $instance -> wrapper -> serialize ());
}
Logger :: log ( 'Done final serialization (SHUTDOWN)!' );
}
2020-09-24 23:25:54 +02:00
2019-09-01 23:39:29 +02:00
/**
* Constructor function .
*
2020-09-22 11:48:12 +02:00
* @ param Settings | SettingsEmpty $settings Settings
* @ param APIWrapper $wrapper API wrapper
2019-09-01 23:39:29 +02:00
*
* @ return void
*/
2020-09-22 11:48:12 +02:00
public function __magic_construct ( SettingsAbstract $settings , APIWrapper $wrapper )
2019-05-02 21:30:50 +02:00
{
2020-09-27 21:51:55 +02:00
self :: $references [ \spl_object_hash ( $this )] = $this ;
2020-09-22 11:48:12 +02:00
$this -> wrapper = $wrapper ;
2019-05-22 17:35:16 +02:00
$this -> setInitPromise ( $this -> __construct_async ( $settings ));
2019-05-02 21:30:50 +02:00
}
2019-09-01 23:39:29 +02:00
/**
* Async constructor function .
*
2020-09-22 11:48:12 +02:00
* @ param Settings | SettingsEmpty $settings Settings
2019-09-01 23:39:29 +02:00
*
2020-07-28 20:39:32 +02:00
* @ return \Generator
2019-09-01 23:39:29 +02:00
*/
2020-09-22 11:48:12 +02:00
public function __construct_async ( SettingsAbstract $settings ) : \Generator
2016-09-12 22:28:27 +02:00
{
2020-09-22 11:48:12 +02:00
// Initialize needed stuffs
2019-10-31 15:06:25 +01:00
Magic :: classExists ();
// Parse and store settings
2020-09-26 17:11:41 +02:00
$this -> updateSettingsInternal ( $settings );
2020-09-22 11:48:12 +02:00
// Actually instantiate needed classes like a boss
2020-05-03 03:33:54 +02:00
yield from $this -> cleanupProperties ();
2017-05-27 23:21:14 +02:00
// Load rsa keys
2019-06-29 14:54:12 +02:00
$this -> rsa_keys = [];
2020-09-22 11:48:12 +02:00
foreach ( $this -> settings -> getAuth () -> getRsaKeys () as $key ) {
2020-01-31 19:49:58 +01:00
$key = ( yield from ( new RSA ()) -> load ( $this -> TL , $key ));
2017-05-16 15:12:04 +02:00
$this -> rsa_keys [ $key -> fp ] = $key ;
}
2019-10-31 20:48:06 +01:00
// (re)-initialize TL
2019-09-13 16:55:48 +02:00
$callbacks = [ $this , $this -> referenceDatabase ];
if ( ! ( $this -> authorization [ 'user' ][ 'bot' ] ? ? false )) {
2020-01-31 19:29:43 +01:00
$callbacks [] = $this -> minDatabase ;
2019-09-13 16:55:48 +02:00
}
2020-09-22 11:48:12 +02:00
$this -> TL -> init ( $this -> settings -> getSchema (), $callbacks );
2020-01-31 19:29:43 +01:00
yield from $this -> connectToAllDcs ();
2019-07-18 23:48:35 +02:00
$this -> startLoops ();
2017-03-24 21:01:08 +01:00
$this -> datacenter -> curdc = 2 ;
2019-09-01 23:39:29 +02:00
if (( ! isset ( $this -> authorization [ 'user' ][ 'bot' ]) || ! $this -> authorization [ 'user' ][ 'bot' ]) && $this -> datacenter -> getDataCenterConnection ( $this -> datacenter -> curdc ) -> hasTempAuthKey ()) {
2017-05-31 11:22:42 +02:00
try {
2020-02-05 17:37:01 +01:00
$nearest_dc = yield from $this -> methodCallAsyncRead ( 'help.getNearestDc' , [], [ 'datacenter' => $this -> datacenter -> curdc ]);
2019-10-31 15:06:25 +01:00
$this -> logger -> logger ( \sprintf ( Lang :: $current_lang [ 'nearest_dc' ], $nearest_dc [ 'country' ], $nearest_dc [ 'nearest_dc' ]), Logger :: NOTICE );
2017-05-31 11:22:42 +02:00
if ( $nearest_dc [ 'nearest_dc' ] != $nearest_dc [ 'this_dc' ]) {
2020-09-22 11:48:12 +02:00
$this -> settings -> setDefaultDc ( $this -> datacenter -> curdc = ( int ) $nearest_dc [ 'nearest_dc' ]);
2017-05-31 11:22:42 +02:00
}
} catch ( RPCErrorException $e ) {
2017-05-31 11:23:36 +02:00
if ( $e -> rpc !== 'BOT_METHOD_INVALID' ) {
throw $e ;
}
2017-04-22 02:24:12 +02:00
}
2017-04-22 02:23:46 +02:00
}
2020-01-31 19:29:43 +01:00
yield from $this -> getConfig ([], [ 'datacenter' => $this -> datacenter -> curdc ]);
2019-06-04 17:53:42 +02:00
$this -> startUpdateSystem ( true );
2017-07-23 16:11:02 +02:00
$this -> v = self :: V ;
2020-05-22 12:30:14 +02:00
2020-09-26 17:11:41 +02:00
$this -> settings -> applyChanges ();
2020-05-22 12:30:14 +02:00
GarbageCollector :: start ();
2017-03-24 21:01:08 +01:00
}
2020-09-22 11:48:12 +02:00
/**
* Set API wrapper needed for triggering serialization functions .
2020-10-07 19:31:52 +02:00
*
* @ internal
2020-09-22 11:48:12 +02:00
*/
public function setWrapper ( APIWrapper $wrapper ) : void
{
$this -> wrapper = $wrapper ;
}
2020-10-07 19:31:52 +02:00
/**
* Get API wrapper .
*
* @ internal
*/
public function getWrapper () : APIWrapper
{
return $this -> wrapper ;
}
2019-10-31 11:17:22 +01:00
/**
2019-10-31 15:06:25 +01:00
* Sleep function .
2019-10-31 11:17:22 +01:00
*
* @ return array
*/
public function __sleep () : array
2017-04-21 13:13:24 +02:00
{
2020-09-22 11:48:12 +02:00
$db = $this -> settings -> getDb ();
if ( $db instanceof Memory && $db -> getCleanup ()) {
2020-10-06 11:11:49 +02:00
Tools :: wait ( $this -> cleanup ());
2019-06-22 19:54:44 +02:00
}
2020-09-22 11:48:12 +02:00
$res = [
2019-10-31 15:06:25 +01:00
// Databases
2019-10-31 20:48:06 +01:00
'chats' ,
'full_chats' ,
'referenceDatabase' ,
'minDatabase' ,
'channel_participants' ,
2020-04-28 02:41:06 +02:00
'usernames' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Misc caching
2019-10-31 20:48:06 +01:00
'dialog_params' ,
'last_stored' ,
'qres' ,
'supportUser' ,
2019-10-31 15:06:25 +01:00
'tos' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Event handler
2019-10-31 20:48:06 +01:00
'event_handler' ,
'event_handler_instance' ,
2019-10-31 15:06:25 +01:00
'loop_callback' ,
2019-10-31 20:48:06 +01:00
'updates' ,
'updates_key' ,
2019-10-31 15:06:25 +01:00
'hook_url' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Web login template
2020-09-26 21:57:06 +02:00
'webTemplate' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Settings
2019-10-31 20:48:06 +01:00
'settings' ,
'config' ,
2020-09-22 11:48:12 +02:00
'dcList' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Authorization keys
2019-10-31 20:48:06 +01:00
'datacenter' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Authorization state
2019-10-31 20:48:06 +01:00
'authorization' ,
'authorized' ,
'authorized_dc' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Authorization cache
2019-10-31 20:48:06 +01:00
'rsa_keys' ,
'dh_config' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Update state
2019-10-31 20:48:06 +01:00
'got_state' ,
'channels_state' ,
'msg_ids' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Version
2019-10-31 20:48:06 +01:00
'v' ,
2020-02-23 19:28:42 +01:00
2019-10-31 20:48:06 +01:00
// TL
'TL' ,
2020-02-23 19:28:42 +01:00
2019-10-31 15:06:25 +01:00
// Secret chats
2019-10-31 20:48:06 +01:00
'secret_chats' ,
'temp_requested_secret_chats' ,
'temp_rekeyed_secret_chats' ,
2020-02-23 19:28:42 +01:00
// Report URI
2020-07-09 20:53:01 +02:00
'reportDest' ,
2019-10-31 20:48:06 +01:00
];
2020-09-22 11:48:12 +02:00
if ( ! $this -> updateHandler instanceof Closure ) {
$res [] = 'updateHandler' ;
}
return $res ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2020-04-25 21:57:55 +02:00
2019-06-22 19:54:44 +02:00
/**
* Cleanup memory and session file .
2019-09-01 23:39:29 +02:00
*
2020-10-06 11:11:49 +02:00
* @ return \Generator
2019-06-22 19:54:44 +02:00
*/
2020-10-06 11:11:49 +02:00
public function cleanup () : \Generator
2019-06-22 19:54:44 +02:00
{
$this -> referenceDatabase = new ReferenceDatabase ( $this );
2020-10-06 10:44:53 +02:00
yield from $this -> referenceDatabase -> init ();
2019-09-13 16:55:48 +02:00
$callbacks = [ $this , $this -> referenceDatabase ];
if ( ! ( $this -> authorization [ 'user' ][ 'bot' ] ? ? false )) {
2020-01-31 19:29:43 +01:00
$callbacks [] = $this -> minDatabase ;
2019-09-13 16:55:48 +02:00
}
2020-09-12 15:14:26 +02:00
$this -> TL -> updateCallbacks ( $callbacks );
2019-06-22 19:54:44 +02:00
}
2020-08-31 00:39:25 +02:00
private function fillUsernamesCache () : \Generator
{
if ( yield $this -> usernames -> count () === 0 ) {
$this -> logger ( 'Filling database cache. This can take few minutes.' , Logger :: WARNING );
$iterator = $this -> chats -> getIterator ();
while ( yield $iterator -> advance ()) {
[ $id , $chat ] = $iterator -> getCurrent ();
if ( isset ( $chat [ 'username' ])) {
$this -> usernames [ \strtolower ( $chat [ 'username' ])] = $this -> getId ( $chat );
}
}
$this -> logger ( 'Cache filled.' , Logger :: WARNING );
}
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Logger .
2019-10-31 12:45:19 +01:00
*
* @ param string $param Parameter
2019-10-31 15:06:25 +01:00
* @ param int $level Logging level
2019-10-31 12:45:19 +01:00
* @ param string $file File where the message originated
2019-10-31 15:06:25 +01:00
*
2019-10-31 12:45:19 +01:00
* @ return void
*/
2019-12-28 16:07:09 +01:00
public function logger ( $param , int $level = Logger :: NOTICE , string $file = '' ) : void
2019-06-04 13:49:01 +02:00
{
2019-06-14 12:00:21 +02:00
if ( $file === null ) {
2019-09-01 01:52:28 +02:00
$file = \basename ( \debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 1 )[ 0 ][ 'file' ], '.php' );
2019-06-14 12:00:21 +02:00
}
2019-12-28 16:07:09 +01:00
isset ( $this -> logger ) ? $this -> logger -> logger ( $param , $level , $file ) : Logger :: $default -> logger ( $param , $level , $file );
2019-06-04 13:49:01 +02:00
}
2019-10-31 20:48:06 +01:00
/**
* Get TL namespaces .
*
* @ return array
*/
public function getMethodNamespaces () : array
{
return $this -> TL -> getMethodNamespaces ();
}
/**
* Get namespaced methods ( method => namespace ) .
*
* @ return array
*/
public function getMethodsNamespaced () : array
{
return $this -> TL -> getMethodsNamespaced ();
}
/**
* Get TL serializer .
*
* @ return TL
*/
2019-12-13 15:37:57 +01:00
public function getTL () : \danog\MadelineProto\TL\TL
2019-10-31 20:48:06 +01:00
{
return $this -> TL ;
}
2019-12-13 15:37:57 +01:00
/**
* Get logger .
*/
public function getLogger () : Logger
{
return $this -> logger ;
}
2020-09-26 17:11:41 +02:00
/**
* Get PSR logger .
*/
public function getPsrLogger () : LoggerInterface
{
return $this -> logger -> getPsrLogger ();
}
2019-10-31 11:17:22 +01:00
/**
2019-10-31 15:06:25 +01:00
* Get async HTTP client .
2019-10-31 11:17:22 +01:00
*
2020-03-08 17:24:31 +01:00
* @ return \Amp\Http\Client\HttpClient
2019-10-31 11:17:22 +01:00
*/
2020-03-08 17:24:31 +01:00
public function getHTTPClient () : HttpClient
2019-05-30 14:09:15 +02:00
{
return $this -> datacenter -> getHTTPClient ();
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Get async DNS client .
2019-10-31 12:45:19 +01:00
*
* @ return \Amp\Dns\Resolver
*/
public function getDNSClient () : Resolver
2019-06-13 14:43:30 +02:00
{
return $this -> datacenter -> getDNSClient ();
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Get contents of remote file asynchronously .
2019-10-31 12:45:19 +01:00
*
* @ param string $url URL
2019-10-31 15:06:25 +01:00
*
2020-10-01 21:36:07 +02:00
* @ return \Generator
*
* @ psalm - return \Generator < int , Promise < string > , mixed , string >
2019-10-31 12:45:19 +01:00
*/
public function fileGetContents ( string $url ) : \Generator
2019-06-04 23:55:02 +02:00
{
return $this -> datacenter -> fileGetContents ( $url );
2019-09-18 20:46:20 +02:00
}
2019-09-01 14:07:04 +02:00
/**
* Get all datacenter connections .
*
2019-09-18 20:46:20 +02:00
* @ return array < DataCenterConnection >
2019-09-01 14:07:04 +02:00
*/
public function getDataCenterConnections () : array
{
return $this -> datacenter -> getDataCenterConnections ();
}
2020-07-11 20:01:54 +02:00
/**
* Get main DC ID .
*
2020-10-01 21:36:07 +02:00
* @ return int | string
2020-07-11 20:01:54 +02:00
*/
2020-10-01 21:36:07 +02:00
public function getDataCenterId ()
2020-07-11 20:01:54 +02:00
{
return $this -> datacenter -> curdc ;
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Prompt serialization of instance .
2019-10-31 12:45:19 +01:00
*
2020-02-25 18:02:32 +01:00
* @ internal
*
2019-10-31 12:45:19 +01:00
* @ return void
*/
2019-09-01 23:39:29 +02:00
public function serialize ()
2019-09-01 01:52:28 +02:00
{
2020-02-25 18:02:32 +01:00
if ( $this -> wrapper && $this -> inited ()) {
$this -> wrapper -> serialize ();
2019-09-01 01:52:28 +02:00
}
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Start all internal loops .
2019-10-31 12:45:19 +01:00
*
* @ return void
*/
private function startLoops ()
2019-07-18 23:48:35 +02:00
{
if ( ! $this -> callCheckerLoop ) {
2020-07-28 20:39:32 +02:00
$this -> callCheckerLoop = new PeriodicLoopInternal ( $this , [ $this , 'checkCalls' ], 'call check' , 10 * 1000 );
2019-07-18 23:48:35 +02:00
}
2019-09-01 01:52:28 +02:00
if ( ! $this -> serializeLoop ) {
2020-09-22 11:48:12 +02:00
$this -> serializeLoop = new PeriodicLoopInternal ( $this , [ $this , 'serialize' ], 'serialize' , $this -> settings -> getSerialization () -> getInterval () * 1000 );
2019-09-01 23:39:29 +02:00
}
if ( ! $this -> phoneConfigLoop ) {
2020-07-28 20:39:32 +02:00
$this -> phoneConfigLoop = new PeriodicLoopInternal ( $this , [ $this , 'getPhoneConfig' ], 'phone config' , 24 * 3600 * 1000 );
2019-09-17 21:35:53 +02:00
}
if ( ! $this -> checkTosLoop ) {
2020-07-28 20:39:32 +02:00
$this -> checkTosLoop = new PeriodicLoopInternal ( $this , [ $this , 'checkTos' ], 'TOS' , 24 * 3600 * 1000 );
2019-09-17 21:35:53 +02:00
}
if ( ! $this -> configLoop ) {
2020-07-28 20:39:32 +02:00
$this -> configLoop = new PeriodicLoopInternal ( $this , [ $this , 'getConfig' ], 'config' , 24 * 3600 * 1000 );
2019-09-01 01:52:28 +02:00
}
2020-07-09 18:23:16 +02:00
if ( ! $this -> rpcLoop ) {
2020-07-28 20:39:32 +02:00
$this -> rpcLoop = new PeriodicLoopInternal ( $this , [ $this , 'rpcReport' ], 'config' , 60 * 1000 );
2020-07-09 18:23:16 +02:00
}
2020-07-11 20:01:54 +02:00
if ( ! $this -> ipcServer ) {
2020-10-13 10:03:35 +02:00
try {
$this -> ipcServer = new Server ( $this );
$this -> ipcServer -> setSettings ( $this -> settings -> getIpc ());
$this -> ipcServer -> setIpcPath ( $this -> wrapper -> session );
} catch ( \Throwable $e ) {
$this -> logger -> logger ( " Error while starting IPC server: $e " , Logger :: FATAL_ERROR );
}
2020-07-11 20:01:54 +02:00
}
2019-09-01 23:39:29 +02:00
$this -> callCheckerLoop -> start ();
2019-09-01 01:52:28 +02:00
$this -> serializeLoop -> start ();
2019-09-01 23:39:29 +02:00
$this -> phoneConfigLoop -> start ();
2019-09-17 21:35:53 +02:00
$this -> configLoop -> start ();
$this -> checkTosLoop -> start ();
2020-07-09 18:23:16 +02:00
$this -> rpcLoop -> start ();
2020-10-13 10:03:35 +02:00
try {
$this -> ipcServer -> start ();
} catch ( \Throwable $e ) {
$this -> logger -> logger ( " Error while starting IPC server: $e " , Logger :: FATAL_ERROR );
}
2019-07-18 23:48:35 +02:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Stop all internal loops .
2019-10-31 12:45:19 +01:00
*
* @ return void
*/
private function stopLoops ()
2019-07-18 23:48:35 +02:00
{
if ( $this -> callCheckerLoop ) {
2019-07-18 23:59:02 +02:00
$this -> callCheckerLoop -> signal ( true );
2019-07-18 23:48:35 +02:00
$this -> callCheckerLoop = null ;
}
2019-09-01 01:52:28 +02:00
if ( $this -> serializeLoop ) {
$this -> serializeLoop -> signal ( true );
$this -> serializeLoop = null ;
}
2019-09-01 23:39:29 +02:00
if ( $this -> phoneConfigLoop ) {
$this -> phoneConfigLoop -> signal ( true );
$this -> phoneConfigLoop = null ;
}
2019-09-17 21:35:53 +02:00
if ( $this -> configLoop ) {
$this -> configLoop -> signal ( true );
$this -> configLoop = null ;
}
if ( $this -> checkTosLoop ) {
$this -> checkTosLoop -> signal ( true );
$this -> checkTosLoop = null ;
}
2020-07-09 18:23:16 +02:00
if ( $this -> rpcLoop ) {
$this -> rpcLoop -> signal ( true );
$this -> rpcLoop = null ;
}
2020-07-11 20:01:54 +02:00
if ( $this -> ipcServer ) {
$this -> ipcServer -> signal ( null );
$this -> ipcServer = null ;
}
2020-07-09 18:23:16 +02:00
}
/**
* Report RPC errors .
*
* @ internal
*
* @ return \Generator
*/
public function rpcReport () : \Generator
{
$toReport = RPCErrorException :: $toReport ;
RPCErrorException :: $toReport = [];
foreach ( $toReport as [ $method , $code , $error , $time ]) {
try {
$res = \json_decode ( yield from $this -> fileGetContents ( 'https://rpc.pwrtelegram.xyz/?method=' . $method . '&code=' . $code . '&error=' . $error . '&t=' . $time ), true );
if ( isset ( $res [ 'ok' ]) && $res [ 'ok' ] && isset ( $res [ 'result' ])) {
$description = $res [ 'result' ];
RPCErrorException :: $descriptions [ $error ] = $description ;
RPCErrorException :: $errorMethodMap [ $code ][ $method ][ $error ] = $error ;
}
} catch ( \Throwable $e ) {
}
}
2019-07-18 23:48:35 +02:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Clean up properties from previous versions of MadelineProto .
*
2019-12-28 16:07:09 +01:00
* @ internal
*
2020-10-01 21:36:07 +02:00
* @ return \Generator
*
* @ psalm - return \Generator < mixed , mixed , mixed , void >
2019-10-31 15:06:25 +01:00
*/
2020-10-01 21:36:07 +02:00
private function cleanupProperties () : \Generator
2019-10-31 15:06:25 +01:00
{
2020-01-31 19:29:43 +01:00
if ( ! $this -> channels_state instanceof CombinedUpdatesState ) {
2019-10-31 15:06:25 +01:00
$this -> channels_state = new CombinedUpdatesState ( $this -> channels_state );
}
if ( isset ( $this -> updates_state )) {
2020-01-31 19:29:43 +01:00
if ( ! $this -> updates_state instanceof UpdatesState ) {
2019-10-31 15:06:25 +01:00
$this -> updates_state = new UpdatesState ( $this -> updates_state );
}
2020-07-28 20:39:32 +02:00
$this -> channels_state -> __construct ([ UpdateLoop :: GENERIC => $this -> updates_state ]);
2019-10-31 15:06:25 +01:00
unset ( $this -> updates_state );
}
if ( ! isset ( $this -> datacenter )) {
2020-09-22 11:48:12 +02:00
$this -> datacenter ? ? = new DataCenter ( $this , $this -> dcList , $this -> settings -> getConnection ());
2019-10-31 15:06:25 +01:00
}
if ( ! isset ( $this -> referenceDatabase )) {
$this -> referenceDatabase = new ReferenceDatabase ( $this );
2020-09-12 14:24:57 +02:00
yield from $this -> referenceDatabase -> init ();
} else {
yield from $this -> referenceDatabase -> init ();
2019-10-31 15:06:25 +01:00
}
if ( ! isset ( $this -> minDatabase )) {
$this -> minDatabase = new MinDatabase ( $this );
2020-09-12 14:24:57 +02:00
yield from $this -> minDatabase -> init ();
} else {
yield from $this -> minDatabase -> init ();
2019-10-31 15:06:25 +01:00
}
2019-10-31 20:48:06 +01:00
if ( ! isset ( $this -> TL )) {
$this -> TL = new TL ( $this );
$callbacks = [ $this , $this -> referenceDatabase ];
if ( ! ( $this -> authorization [ 'user' ][ 'bot' ] ? ? false )) {
2020-01-31 19:29:43 +01:00
$callbacks [] = $this -> minDatabase ;
2019-10-31 20:48:06 +01:00
}
2020-09-22 11:48:12 +02:00
$this -> TL -> init ( $this -> settings -> getSchema (), $callbacks );
2019-10-31 20:48:06 +01:00
}
2020-04-25 21:57:55 +02:00
2020-06-07 00:00:44 +02:00
yield from $this -> initDb ( $this );
2020-08-31 00:39:25 +02:00
yield from $this -> fillUsernamesCache ();
2019-10-31 15:06:25 +01:00
}
2020-05-03 03:33:54 +02:00
2019-10-31 15:06:25 +01:00
/**
2019-10-31 20:48:06 +01:00
* Upgrade MadelineProto instance .
2019-10-31 15:06:25 +01:00
*
* @ return \Generator
2020-05-03 03:33:54 +02:00
* @ throws Exception
* @ throws RPCErrorException
* @ throws \Throwable
2019-10-31 15:06:25 +01:00
*/
private function upgradeMadelineProto () : \Generator
{
2020-07-09 20:53:01 +02:00
if ( ! isset ( $this -> snitch )) {
$this -> snitch = new Snitch ;
}
2019-10-31 15:06:25 +01:00
$this -> logger -> logger ( Lang :: $current_lang [ 'serialization_ofd' ], Logger :: WARNING );
foreach ( $this -> datacenter -> getDataCenterConnections () as $dc_id => $socket ) {
if ( $this -> authorized === self :: LOGGED_IN && \strpos ( $dc_id , '_' ) === false && $socket -> hasPermAuthKey () && $socket -> hasTempAuthKey ()) {
$socket -> bind ();
$socket -> authorized ( true );
}
}
2020-09-22 11:48:12 +02:00
$this -> settings -> setSchema ( new TLSchema );
2020-04-25 21:57:55 +02:00
2020-06-07 00:00:44 +02:00
yield from $this -> initDb ( $this );
2020-04-25 21:57:55 +02:00
2019-10-31 15:06:25 +01:00
if ( ! isset ( $this -> secret_chats )) {
$this -> secret_chats = [];
}
2020-05-03 03:33:54 +02:00
$iterator = $this -> full_chats -> getIterator ();
while ( yield $iterator -> advance ()) {
[ $id , $full ] = $iterator -> getCurrent ();
2019-10-31 15:06:25 +01:00
if ( isset ( $full [ 'full' ], $full [ 'last_update' ])) {
2020-09-27 19:36:17 +02:00
yield $this -> full_chats -> offsetSet ( $id , [ 'full' => $full [ 'full' ], 'last_update' => $full [ 'last_update' ]]);
2019-10-31 15:06:25 +01:00
}
}
2020-05-03 03:33:54 +02:00
2019-10-31 15:06:25 +01:00
foreach ( $this -> secret_chats as $key => & $chat ) {
if ( ! \is_array ( $chat )) {
unset ( $this -> secret_chats [ $key ]);
continue ;
}
if ( $chat [ 'layer' ] >= 73 ) {
$chat [ 'mtproto' ] = 2 ;
} else {
$chat [ 'mtproto' ] = 1 ;
}
}
2020-04-25 21:57:55 +02:00
unset ( $chat );
2019-10-31 15:06:25 +01:00
$this -> resetMTProtoSession ( true , true );
$this -> config = [ 'expires' => - 1 ];
$this -> dh_config = [ 'version' => 0 ];
2020-09-22 11:48:12 +02:00
yield from $this -> __construct_async ( $this -> settings );
2019-10-31 15:06:25 +01:00
foreach ( $this -> secret_chats as $chat => $data ) {
try {
if ( isset ( $this -> secret_chats [ $chat ]) && $this -> secret_chats [ $chat ][ 'InputEncryptedChat' ] !== null ) {
2020-01-31 19:49:58 +01:00
yield from $this -> notifyLayer ( $chat );
2019-10-31 15:06:25 +01:00
}
} catch ( \danog\MadelineProto\RPCErrorException $e ) {
}
}
}
/**
2020-09-22 11:48:12 +02:00
* Post - deserialization initialization function .
*
* @ param Settings | SettingsEmpty $settings New settings
* @ param APIWrapper $wrapper API wrapper
*
* @ internal
*
* @ return \Generator
2019-10-31 12:45:19 +01:00
*/
2020-09-22 11:48:12 +02:00
public function wakeup ( SettingsAbstract $settings , APIWrapper $wrapper ) : \Generator
2019-05-02 21:30:50 +02:00
{
2020-09-27 21:51:55 +02:00
// Set reference to itself
self :: $references [ \spl_object_hash ( $this )] = $this ;
2020-09-22 11:48:12 +02:00
// Set API wrapper
$this -> wrapper = $wrapper ;
// BC stuff
if ( $this -> authorized === true ) {
$this -> authorized = self :: LOGGED_IN ;
}
// Convert old array settings to new settings object
if ( \is_array ( $this -> settings )) {
if (( $this -> settings [ 'updates' ][ 'callback' ] ? ? '' ) === 'getUpdatesUpdateHandler' ) {
2020-10-04 16:27:22 +02:00
/** @psalm-suppress InvalidPropertyAssignmentValue */
2020-09-22 11:48:12 +02:00
$this -> settings [ 'updates' ][ 'callback' ] = [ $this , 'getUpdatesUpdateHandler' ];
}
if ( \is_callable ( $this -> settings [ 'updates' ][ 'callback' ] ? ? null )) {
$this -> updateHandler = $this -> settings [ 'updates' ][ 'callback' ];
}
2020-10-04 14:55:05 +02:00
/** @psalm-suppress InvalidArrayOffset */
2020-09-22 11:48:12 +02:00
$this -> dcList = $this -> settings [ 'connection' ] ? ? $this -> dcList ;
}
$this -> settings = Settings :: parseFromLegacy ( $this -> settings );
// Clean up phone call array
foreach ( $this -> calls as $id => $controller ) {
if ( ! \is_object ( $controller )) {
unset ( $this -> calls [ $id ]);
} elseif ( $controller -> getCallState () === VoIP :: CALL_STATE_ENDED ) {
$controller -> setMadeline ( $this );
$controller -> discard ();
} else {
$controller -> setMadeline ( $this );
}
}
2020-02-25 18:02:32 +01:00
$this -> forceInit ( false );
2020-09-22 11:48:12 +02:00
$this -> setInitPromise ( $this -> wakeupAsync ( $settings ));
return $this -> initAsynchronously ();
2019-05-02 21:30:50 +02:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Async wakeup function .
2019-10-31 12:45:19 +01:00
*
2020-09-22 11:48:12 +02:00
* @ param Settings | SettingsEmpty $settings New settings
2019-10-31 15:06:25 +01:00
*
2019-10-31 12:45:19 +01:00
* @ return \Generator
*/
2020-09-22 11:48:12 +02:00
private function wakeupAsync ( SettingsAbstract $settings ) : \Generator
2016-12-26 18:23:46 +01:00
{
2019-10-31 15:06:25 +01:00
// Setup one-time stuffs
Magic :: classExists ();
2020-09-22 11:48:12 +02:00
$this -> settings -> getConnection () -> init ();
2019-10-31 15:06:25 +01:00
// Setup logger
2019-10-29 21:33:23 +01:00
$this -> setupLogger ();
2019-10-31 15:06:25 +01:00
// Setup language
2020-01-31 19:29:43 +01:00
Lang :: $current_lang =& Lang :: $lang [ 'en' ];
2020-09-22 11:48:12 +02:00
if ( Lang :: $lang [ $this -> settings -> getAppInfo () -> getLangCode ()] ? ? false ) {
Lang :: $current_lang =& Lang :: $lang [ $this -> settings -> getAppInfo () -> getLangCode ()];
2017-05-28 04:34:25 +02:00
}
2020-09-22 11:48:12 +02:00
// Reset MTProto session (not related to user session)
2019-09-01 23:39:29 +02:00
$this -> resetMTProtoSession ();
2020-09-22 11:48:12 +02:00
// Update settings from constructor
2020-09-26 17:11:41 +02:00
$this -> updateSettingsInternal ( $settings );
2020-09-22 11:48:12 +02:00
// Session update process for BC
$forceDialogs = false ;
if ( ! isset ( $this -> v )
|| $this -> v !== self :: V
|| $this -> settings -> getSchema () -> needsUpgrade ()) {
2020-01-31 19:29:43 +01:00
yield from $this -> upgradeMadelineProto ();
2020-09-22 11:48:12 +02:00
$forceDialogs = true ;
2017-02-13 13:27:59 +01:00
}
2019-12-27 15:25:33 +01:00
// Cleanup old properties, init new stuffs
2020-05-03 03:33:54 +02:00
yield from $this -> cleanupProperties ();
2019-12-27 15:25:33 +01:00
// Update TL callbacks
$callbacks = [ $this , $this -> referenceDatabase ];
if ( ! ( $this -> authorization [ 'user' ][ 'bot' ] ? ? false )) {
2020-01-31 19:29:43 +01:00
$callbacks [] = $this -> minDatabase ;
2019-12-27 15:25:33 +01:00
}
$this -> TL -> updateCallbacks ( $callbacks );
2020-09-22 11:48:12 +02:00
// Connect to all DCs, start internal loops
2020-01-31 19:29:43 +01:00
yield from $this -> connectToAllDcs ();
2019-07-18 23:48:35 +02:00
$this -> startLoops ();
2020-02-25 18:02:32 +01:00
if ( yield from $this -> fullGetSelf ()) {
2017-09-25 22:33:37 +02:00
$this -> authorized = self :: LOGGED_IN ;
2019-10-29 21:33:23 +01:00
$this -> setupLogger ();
2020-07-23 18:08:14 +02:00
yield from $this -> getCdnConfig ( $this -> datacenter -> curdc );
yield from $this -> initAuthorization ();
2017-05-31 12:14:38 +02:00
}
2020-09-22 11:48:12 +02:00
// onStart event handler
if ( $this -> event_handler && \class_exists ( $this -> event_handler ) && \is_subclass_of ( $this -> event_handler , EventHandler :: class )) {
yield from $this -> setEventHandler ( $this -> event_handler );
}
2019-06-04 17:53:42 +02:00
$this -> startUpdateSystem ( true );
2020-09-22 11:48:12 +02:00
if ( $this -> authorized === self :: LOGGED_IN && ! $this -> authorization [ 'user' ][ 'bot' ] && $this -> settings -> getPeer () -> getCacheAllPeersOnStartup ()) {
yield from $this -> getDialogs ( $forceDialogs );
2017-05-17 18:10:36 +02:00
}
2020-09-22 11:48:12 +02:00
if ( $this -> authorized === self :: LOGGED_IN ) {
2019-10-31 15:06:25 +01:00
$this -> logger -> logger ( Lang :: $current_lang [ 'getupdates_deserialization' ], Logger :: NOTICE );
2020-07-28 20:39:32 +02:00
yield $this -> updaters [ UpdateLoop :: GENERIC ] -> resume ();
2016-12-26 18:23:46 +01:00
}
2020-07-28 20:39:32 +02:00
$this -> updaters [ UpdateLoop :: GENERIC ] -> start ();
2020-05-22 12:30:14 +02:00
GarbageCollector :: start ();
2016-12-26 18:23:46 +01:00
}
2019-10-31 12:45:19 +01:00
/**
2020-02-25 18:02:32 +01:00
* Unreference instance , allowing destruction .
*
* @ internal
*
* @ return void
2019-10-31 12:45:19 +01:00
*/
2020-02-25 19:10:49 +01:00
public function unreference () : void
2017-03-24 21:01:36 +01:00
{
2020-10-13 10:03:35 +02:00
if ( ! isset ( $this -> logger )) {
$this -> logger = new Logger ( new \danog\MadelineProto\Settings\Logger );
}
2020-02-25 19:10:49 +01:00
$this -> logger -> logger ( " Will unreference instance " );
2020-09-27 21:51:55 +02:00
if ( isset ( self :: $references [ \spl_object_hash ( $this )])) {
unset ( self :: $references [ \spl_object_hash ( $this )]);
}
2019-07-18 23:48:35 +02:00
$this -> stopLoops ();
2019-06-17 12:19:46 +02:00
if ( isset ( $this -> seqUpdater )) {
$this -> seqUpdater -> signal ( true );
}
2020-10-13 10:03:35 +02:00
if ( isset ( $this -> channels_state )) {
$channelIds = [];
foreach ( $this -> channels_state -> get () as $state ) {
$channelIds [] = $state -> getChannel ();
2019-06-08 21:01:57 +02:00
}
2020-10-13 10:03:35 +02:00
\sort ( $channelIds );
foreach ( $channelIds as $channelId ) {
if ( isset ( $this -> feeders [ $channelId ])) {
$this -> feeders [ $channelId ] -> signal ( true );
}
if ( isset ( $this -> updaters [ $channelId ])) {
$this -> updaters [ $channelId ] -> signal ( true );
}
2019-06-08 21:01:57 +02:00
}
}
2020-10-13 10:03:35 +02:00
if ( isset ( $this -> datacenter )) {
foreach ( $this -> datacenter -> getDataCenterConnections () as $datacenter ) {
$datacenter -> disconnect ();
}
2017-05-16 15:12:04 +02:00
}
2020-09-27 19:36:17 +02:00
$this -> logger -> logger ( " Unreferenced instance " );
2020-02-25 18:02:32 +01:00
}
/**
* Destructor .
*/
public function __destruct ()
{
$this -> logger ( 'Shutting down MadelineProto (MTProto)' );
$this -> unreference ();
2019-06-08 21:01:57 +02:00
$this -> logger ( " Successfully destroyed MadelineProto " );
2017-04-21 13:13:24 +02:00
}
2020-09-24 23:25:54 +02:00
/**
* Restart IPC server instance .
*
* @ internal
*/
public function restartIpcServer () : Promise
{
return new Success (); // Can only be called from client
}
/**
* Whether we ' re an IPC client instance .
*
* @ return boolean
*/
public function isIpc () : bool
{
return false ;
}
2019-10-31 12:45:19 +01:00
/**
2020-09-22 11:48:12 +02:00
* Parse , update and store settings .
2019-10-31 15:06:25 +01:00
*
2020-09-26 17:11:41 +02:00
* @ param SettingsAbstract $settings Settings
2020-02-26 18:12:00 +01:00
*
2020-09-22 11:48:12 +02:00
* @ return \Generator
2019-10-31 12:45:19 +01:00
*/
2020-09-26 17:11:41 +02:00
public function updateSettings ( SettingsAbstract $settings ) : \Generator
{
$this -> updateSettingsInternal ( $settings );
if ( $this -> settings -> getDb () -> hasChanged ()) {
yield from $this -> initDb ( $this );
$this -> settings -> getDb () -> applyChanges ();
}
if ( $this -> settings -> getIpc () -> hasChanged ()) {
$this -> ipcServer -> setSettings ( $this -> settings -> getIpc () -> applyChanges ());
}
if ( $this -> settings -> getSerialization () -> hasChanged ()) {
$this -> serializeLoop -> signal ( true );
$this -> serializeLoop = new PeriodicLoopInternal ( $this , [ $this , 'serialize' ], 'serialize' , $this -> settings -> getSerialization () -> applyChanges () -> getInterval () * 1000 );
}
if ( $this -> settings -> getAuth () -> hasChanged ()
|| $this -> settings -> getConnection () -> hasChanged ()
|| $this -> settings -> getSchema () -> hasChanged ()
|| $this -> settings -> getSchema () -> needsUpgrade ()) {
yield from $this -> __construct_async ( $this -> settings );
}
}
/**
* Parse , update and store settings .
*
* @ param SettingsAbstract $settings Settings
*
* @ return void
*/
private function updateSettingsInternal ( SettingsAbstract $settings ) : void
2016-12-26 20:24:24 +01:00
{
2020-09-22 11:48:12 +02:00
if ( $settings instanceof SettingsEmpty ) {
if ( ! isset ( $this -> settings )) {
$this -> settings = new Settings ;
2018-03-23 11:14:29 +01:00
} else {
2020-09-22 11:48:12 +02:00
return ;
}
} else {
if ( ! isset ( $this -> settings )) {
2020-09-24 20:49:34 +02:00
if ( $settings instanceof Settings ) {
$this -> settings = $settings ;
} else {
$this -> settings = new Settings ;
$this -> settings -> merge ( $settings );
}
2020-09-22 11:48:12 +02:00
} else {
$this -> settings -> merge ( $settings );
2018-03-23 11:14:29 +01:00
}
}
2020-09-22 11:48:12 +02:00
if ( ! $this -> settings -> getAppInfo () -> hasApiInfo ()) {
2019-10-31 15:06:25 +01:00
throw new \danog\MadelineProto\Exception ( Lang :: $current_lang [ 'api_not_set' ], 0 , null , 'MadelineProto' , 1 );
2019-06-20 20:21:31 +02:00
}
2020-09-22 11:48:12 +02:00
2017-01-26 03:50:09 +01:00
// Setup logger
2020-09-26 17:11:41 +02:00
if ( $this -> settings -> getLogger () -> hasChanged () || ! $this -> logger ) {
$this -> setupLogger ();
2020-02-25 18:02:32 +01:00
}
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
}
2020-02-26 18:12:00 +01:00
/**
2020-09-22 11:48:12 +02:00
* Return current settings .
2020-02-26 18:12:00 +01:00
*
2020-09-22 11:48:12 +02:00
* @ return Settings
2020-02-26 18:12:00 +01:00
*/
2020-09-22 11:48:12 +02:00
public function getSettings () : Settings
2020-02-26 18:12:00 +01:00
{
return $this -> settings ;
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Setup logger .
2019-10-31 12:45:19 +01:00
*
* @ return void
*/
2019-12-28 16:07:09 +01:00
public function setupLogger () : void
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
{
2020-09-22 11:48:12 +02:00
$this -> logger = new Logger (
$this -> settings -> getLogger (),
$this -> authorization [ 'user' ][ 'username' ] ? ? $this -> authorization [ 'user' ][ 'id' ] ? ? ''
);
Added APIFactory for calling namespaced mtproto methods, cleaned up testing.php and API.php, moved authorization keys, session_id, seq_no and time delta to the Connection class, added close_and_reopen method to the Connection class, improved DataCenter class, renamed Logging class to Logger, added a bit more logging, added setup_logger, switch_dc, init_authorization methods to the MTProto class, added parameter to disable automatic switching to nearest DC in write_client_info, added a try catch block in the create_auth_key method, fixed switching of DCs in wait_for_response method, added arguments check in the method calling methods, added a message id check in MessageHandler, added method_name_namespaced array in TL for APIFactory, renamed a lot of stuff and removed a few checks in the TL class, moved sendCode test call to testing.php
2016-11-16 15:05:27 +01:00
}
2019-09-01 14:07:04 +02:00
/**
* Reset all MTProto sessions .
*
* @ param boolean $de Whether to reset the session ID
* @ param boolean $auth_key Whether to reset the auth key
*
2019-12-28 16:07:09 +01:00
* @ internal
*
2019-09-01 14:07:04 +02:00
* @ return void
*/
2019-12-28 16:07:09 +01:00
public function resetMTProtoSession ( bool $de = true , bool $auth_key = false ) : void
2016-11-26 11:50:39 +01:00
{
2019-09-01 01:52:28 +02:00
if ( ! \is_object ( $this -> datacenter )) {
2019-10-31 15:06:25 +01:00
throw new Exception ( Lang :: $current_lang [ 'session_corrupted' ]);
2017-08-06 15:03:50 +02:00
}
2019-09-01 14:07:04 +02:00
foreach ( $this -> datacenter -> getDataCenterConnections () as $id => $socket ) {
2017-01-18 10:24:57 +01:00
if ( $de ) {
2019-09-01 14:07:04 +02:00
$socket -> resetSession ();
2017-01-18 10:24:57 +01:00
}
2017-04-21 13:13:24 +02:00
if ( $auth_key ) {
2019-09-01 14:07:04 +02:00
$socket -> setAuthKey ( null );
2017-04-21 13:13:24 +02:00
}
2016-11-26 11:50:20 +01:00
}
}
2019-09-02 14:37:30 +02:00
/**
2019-09-02 17:08:36 +02:00
* Check if connected to datacenter using HTTP .
2019-09-02 14:37:30 +02:00
*
* @ param string $datacenter DC ID
2019-09-02 17:08:36 +02:00
*
2019-12-28 17:38:09 +01:00
* @ internal
*
2019-09-02 14:37:30 +02:00
* @ return boolean
*/
2019-10-31 11:17:22 +01:00
public function isHttp ( string $datacenter ) : bool
2017-12-28 11:58:29 +01:00
{
2019-09-02 14:37:30 +02:00
return $this -> datacenter -> isHttp ( $datacenter );
2017-12-28 11:57:55 +01:00
}
2019-10-31 20:48:06 +01:00
/**
* Checks whether all datacenters are authorized .
*
* @ return boolean
*/
2019-10-31 15:06:25 +01:00
public function hasAllAuth () : bool
{
if ( $this -> isInitingAuthorization ()) {
return false ;
}
foreach ( $this -> datacenter -> getDataCenterConnections () as $dc ) {
2020-07-23 18:08:14 +02:00
if (( ! $dc -> isAuthorized () || ! $dc -> hasTempAuthKey ()) && ! $dc -> isCDN ()) {
2019-10-31 15:06:25 +01:00
return false ;
}
}
return true ;
}
2019-10-31 20:48:06 +01:00
/**
* Whether we ' re initing authorization .
*
2019-12-28 16:07:09 +01:00
* @ internal
*
2019-10-31 20:48:06 +01:00
* @ return boolean
*/
2019-10-31 12:45:19 +01:00
public function isInitingAuthorization ()
{
return $this -> initing_authorization ;
}
/**
2019-10-31 15:06:25 +01:00
* Connects to all datacenters and if necessary creates authorization keys , binds them and writes client info .
2019-10-31 12:45:19 +01:00
*
* @ param boolean $reconnectAll Whether to reconnect to all DCs
2019-10-31 15:06:25 +01:00
*
2019-10-31 12:45:19 +01:00
* @ return \Generator
*/
2019-10-29 21:33:23 +01:00
public function connectToAllDcs ( bool $reconnectAll = true ) : \Generator
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
2020-07-28 20:39:32 +02:00
$this -> channels_state -> get ( FeedLoop :: GENERIC );
2019-05-30 13:28:50 +02:00
foreach ( $this -> channels_state -> get () as $state ) {
$channelId = $state -> getChannel ();
if ( ! isset ( $this -> feeders [ $channelId ])) {
$this -> feeders [ $channelId ] = new FeedLoop ( $this , $channelId );
}
if ( ! isset ( $this -> updaters [ $channelId ])) {
$this -> updaters [ $channelId ] = new UpdateLoop ( $this , $channelId );
}
}
if ( ! isset ( $this -> seqUpdater )) {
$this -> seqUpdater = new SeqLoop ( $this );
}
2020-09-22 11:48:12 +02:00
$this -> datacenter -> __construct ( $this , $this -> dcList , $this -> settings -> getConnection (), $reconnectAll );
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
$dcs = [];
2019-10-29 21:33:23 +01:00
foreach ( $this -> datacenter -> getDcs () as $new_dc ) {
$dcs [] = $this -> datacenter -> dcConnect ( $new_dc );
2016-09-12 22:28:27 +02:00
}
2019-10-29 23:02:47 +01:00
yield \danog\MadelineProto\Tools :: all ( $dcs );
2020-01-31 19:49:58 +01:00
yield from $this -> initAuthorization ();
2020-01-31 19:29:43 +01:00
yield from $this -> parseConfig ();
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
$dcs = [];
2019-10-29 21:33:23 +01:00
foreach ( $this -> datacenter -> getDcs ( false ) as $new_dc ) {
$dcs [] = $this -> datacenter -> dcConnect ( $new_dc );
2017-12-28 10:29:29 +01:00
}
2019-10-29 23:02:47 +01:00
yield \danog\MadelineProto\Tools :: all ( $dcs );
2020-01-31 19:49:58 +01:00
yield from $this -> initAuthorization ();
2020-01-31 19:29:43 +01:00
yield from $this -> parseConfig ();
yield from $this -> getPhoneConfig ();
2019-06-01 15:42:17 +02:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Clean up MadelineProto session after logout .
2019-10-31 12:45:19 +01:00
*
2019-12-28 17:34:04 +01:00
* @ internal
*
2020-05-03 03:33:54 +02:00
* @ return \Generator < void >
2019-10-31 12:45:19 +01:00
*/
2020-05-03 03:33:54 +02:00
public function resetSession () : \Generator
2019-06-14 12:00:21 +02:00
{
if ( isset ( $this -> seqUpdater )) {
$this -> seqUpdater -> signal ( true );
unset ( $this -> seqUpdater );
}
$channelIds = [];
foreach ( $this -> channels_state -> get () as $state ) {
$channelIds [] = $state -> getChannel ();
}
2019-09-01 01:52:28 +02:00
\sort ( $channelIds );
2019-06-14 12:00:21 +02:00
foreach ( $channelIds as $channelId ) {
if ( isset ( $this -> feeders [ $channelId ])) {
$this -> feeders [ $channelId ] -> signal ( true );
unset ( $this -> feeders [ $channelId ]);
}
2020-02-25 18:02:32 +01:00
if ( isset ( $this -> updaters [ $channelId ])) {
2019-06-14 12:00:21 +02:00
$this -> updaters [ $channelId ] -> signal ( true );
unset ( $this -> updaters [ $channelId ]);
}
}
2019-09-01 14:07:04 +02:00
foreach ( $this -> datacenter -> getDataCenterConnections () as $socket ) {
$socket -> authorized ( false );
2019-06-14 12:00:21 +02:00
}
$this -> channels_state = new CombinedUpdatesState ();
$this -> got_state = false ;
$this -> msg_ids = [];
$this -> authorized = self :: NOT_LOGGED_IN ;
$this -> authorized_dc = - 1 ;
$this -> authorization = null ;
$this -> updates = [];
$this -> secret_chats = [];
2020-04-25 21:57:55 +02:00
2020-06-16 17:52:55 +02:00
yield from $this -> initDb ( $this , true );
2020-04-25 21:57:55 +02:00
2019-06-14 12:00:21 +02:00
$this -> tos = [ 'expires' => 0 , 'accepted' => true ];
2020-09-12 14:24:57 +02:00
$this -> dialog_params = [ '_' => 'MadelineProto.dialogParams' , 'limit' => 0 , 'offset_date' => 0 , 'offset_id' => 0 , 'offset_peer' => [ '_' => 'inputPeerEmpty' ], 'count' => 0 ];
2019-06-14 12:00:21 +02:00
$this -> referenceDatabase = new ReferenceDatabase ( $this );
2020-09-12 14:24:57 +02:00
yield from $this -> referenceDatabase -> init ();
2019-09-13 16:55:48 +02:00
$this -> minDatabase = new MinDatabase ( $this );
2020-09-12 14:24:57 +02:00
yield from $this -> minDatabase -> init ();
2019-06-14 12:00:21 +02:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Reset the update state and fetch all updates from the beginning .
2019-10-31 12:45:19 +01:00
*
* @ return void
*/
2019-12-28 16:07:09 +01:00
public function resetUpdateState () : void
2019-06-03 22:33:53 +02:00
{
2019-07-20 20:50:00 +02:00
if ( isset ( $this -> seqUpdater )) {
$this -> seqUpdater -> signal ( true );
}
$channelIds = [];
$newStates = [];
2019-06-03 22:33:53 +02:00
foreach ( $this -> channels_state -> get () as $state ) {
2019-07-20 20:50:00 +02:00
$channelIds [] = $state -> getChannel ();
2019-06-03 22:33:53 +02:00
$channelId = $state -> getChannel ();
2019-07-20 20:50:00 +02:00
$pts = $state -> pts ();
2020-01-31 19:29:43 +01:00
$pts = $channelId ? \max ( 1 , $pts - 1000000 ) : ( $pts > 4000000 ? $pts - 1000000 : \max ( 1 , $pts - 1000000 ));
2019-07-20 20:50:00 +02:00
$newStates [ $channelId ] = new UpdatesState ([ 'pts' => $pts ], $channelId );
}
2019-09-01 01:52:28 +02:00
\sort ( $channelIds );
2019-07-20 20:50:00 +02:00
foreach ( $channelIds as $channelId ) {
if ( isset ( $this -> feeders [ $channelId ])) {
$this -> feeders [ $channelId ] -> signal ( true );
}
2020-02-25 18:02:32 +01:00
if ( isset ( $this -> updaters [ $channelId ])) {
2019-07-20 20:50:00 +02:00
$this -> updaters [ $channelId ] -> signal ( true );
}
2019-06-03 22:33:53 +02:00
}
2019-07-20 20:50:00 +02:00
$this -> channels_state -> __construct ( $newStates );
2019-06-03 22:33:53 +02:00
$this -> startUpdateSystem ();
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Start the update system .
2019-10-31 12:45:19 +01:00
*
* @ param boolean $anyway Force start update system ?
2019-10-31 15:06:25 +01:00
*
2019-12-28 16:07:09 +01:00
* @ internal
*
2019-10-31 12:45:19 +01:00
* @ return void
*/
2019-12-28 16:07:09 +01:00
public function startUpdateSystem ( $anyway = false ) : void
2019-06-01 15:42:17 +02:00
{
2020-02-25 18:02:32 +01:00
if ( ! $this -> inited () && ! $anyway ) {
2019-06-05 15:38:32 +02:00
$this -> logger ( " Not starting update system " );
2019-06-03 22:33:53 +02:00
return ;
}
2019-06-05 15:38:32 +02:00
$this -> logger ( " Starting update system " );
2019-06-01 15:42:17 +02:00
if ( ! isset ( $this -> seqUpdater )) {
$this -> seqUpdater = new SeqLoop ( $this );
}
2020-07-28 20:39:32 +02:00
$this -> channels_state -> get ( FeedLoop :: GENERIC );
2019-06-07 19:15:12 +02:00
$channelIds = [];
2019-05-30 14:09:15 +02:00
foreach ( $this -> channels_state -> get () as $state ) {
2019-06-14 12:00:21 +02:00
$channelIds [] = $state -> getChannel ();
2019-06-07 19:15:12 +02:00
}
2019-09-01 01:52:28 +02:00
\sort ( $channelIds );
2019-06-07 19:15:12 +02:00
foreach ( $channelIds as $channelId ) {
2019-05-30 14:09:15 +02:00
if ( ! isset ( $this -> feeders [ $channelId ])) {
$this -> feeders [ $channelId ] = new FeedLoop ( $this , $channelId );
}
if ( ! isset ( $this -> updaters [ $channelId ])) {
$this -> updaters [ $channelId ] = new UpdateLoop ( $this , $channelId );
}
2019-06-07 02:48:25 +02:00
if ( $this -> feeders [ $channelId ] -> start () && isset ( $this -> feeders [ $channelId ])) {
2019-06-01 22:04:37 +02:00
$this -> feeders [ $channelId ] -> resume ();
}
2019-06-07 02:48:25 +02:00
if ( $this -> updaters [ $channelId ] -> start () && isset ( $this -> updaters [ $channelId ])) {
2019-06-01 22:04:37 +02:00
$this -> updaters [ $channelId ] -> resume ();
}
}
2019-09-01 14:07:04 +02:00
foreach ( $this -> datacenter -> getDataCenterConnections () as $datacenter ) {
$datacenter -> flush ();
2019-09-01 01:52:28 +02:00
}
2019-06-01 22:04:37 +02:00
if ( $this -> seqUpdater -> start ()) {
$this -> seqUpdater -> resume ();
2019-05-30 14:09:15 +02:00
}
2016-10-18 16:44:44 +02:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Store shared phone config .
2019-10-31 12:45:19 +01:00
*
* @ param mixed $watcherId Watcher ID
2019-10-31 15:06:25 +01:00
*
2019-12-28 16:07:09 +01:00
* @ internal
*
* @ return \Generator < void >
2019-10-31 12:45:19 +01:00
*/
2019-12-28 16:07:09 +01:00
public function getPhoneConfig ( $watcherId = null ) : \Generator
2019-03-30 00:30:07 +01:00
{
2020-09-22 11:48:12 +02:00
if ( $this -> authorized === self :: LOGGED_IN
&& \class_exists ( VoIPServerConfigInternal :: class )
&& ! $this -> authorization [ 'user' ][ 'bot' ]
&& $this -> datacenter -> getDataCenterConnection ( $this -> settings -> getDefaultDc ()) -> hasTempAuthKey ()) {
2019-06-04 14:55:58 +02:00
$this -> logger -> logger ( 'Fetching phone config...' );
2020-09-22 11:48:12 +02:00
VoIPServerConfig :: updateDefault ( yield from $this -> methodCallAsyncRead ( 'phone.getCallConfig' , [], $this -> settings -> getDefaultDcParams ()));
2019-03-30 00:30:07 +01:00
} else {
2019-06-04 14:55:58 +02:00
$this -> logger -> logger ( 'Not fetching phone config' );
2019-03-30 00:30:07 +01:00
}
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Store RSA keys for CDN datacenters .
2019-10-31 12:45:19 +01:00
*
* @ param string $datacenter DC ID
2019-10-31 15:06:25 +01:00
*
2019-10-31 12:45:19 +01:00
* @ return \Generator
*/
public function getCdnConfig ( string $datacenter ) : \Generator
2017-06-09 21:56:57 +02:00
{
2017-07-21 23:06:47 +02:00
try {
2020-02-05 17:37:01 +01:00
foreach (( yield from $this -> methodCallAsyncRead ( 'help.getCdnConfig' , [], [ 'datacenter' => $datacenter ]))[ 'public_keys' ] as $curkey ) {
2020-01-31 19:49:58 +01:00
$curkey = ( yield from ( new RSA ()) -> load ( $this -> TL , $curkey [ 'public_key' ]));
2019-11-10 19:31:11 +01:00
$this -> cdn_rsa_keys [ $curkey -> fp ] = $curkey ;
2017-07-21 23:06:47 +02:00
}
} catch ( \danog\MadelineProto\TL\Exception $e ) {
2018-04-08 19:53:30 +02:00
$this -> logger -> logger ( $e -> getMessage (), \danog\MadelineProto\Logger :: FATAL_ERROR );
2017-06-09 21:56:13 +02:00
}
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Get cached server - side config .
2019-10-31 12:45:19 +01:00
*
* @ return array
*/
public function getCachedConfig () : array
2019-09-17 22:42:38 +02:00
{
return $this -> config ;
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Get cached ( or eventually re - fetch ) server - side config .
2019-10-31 12:45:19 +01:00
*
* @ param array $config Current config
* @ param array $options Options for method call
2019-10-31 15:06:25 +01:00
*
2019-10-31 12:45:19 +01:00
* @ return \Generator
*/
public function getConfig ( array $config = [], array $options = []) : \Generator
2019-09-17 21:35:53 +02:00
{
if ( $this -> config [ 'expires' ] > \time ()) {
return $this -> config ;
}
2020-09-22 11:48:12 +02:00
$this -> config = empty ( $config ) ? yield from $this -> methodCallAsyncRead ( 'help.getConfig' , $config , $options ? : $this -> settings -> getDefaultDcParams ()) : $config ;
2020-01-31 19:29:43 +01:00
yield from $this -> parseConfig ();
2020-07-09 18:23:16 +02:00
$this -> logger -> logger ( Lang :: $current_lang [ 'config_updated' ], Logger :: NOTICE );
$this -> logger -> logger ( $this -> config , Logger :: NOTICE );
2019-09-17 21:35:53 +02:00
return $this -> config ;
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Parse cached config .
2019-10-31 12:45:19 +01:00
*
* @ return \Generator
*/
private function parseConfig () : \Generator
2016-11-25 00:15:53 +01:00
{
2017-05-11 00:43:50 +02:00
if ( isset ( $this -> config [ 'dc_options' ])) {
2019-09-17 22:42:38 +02:00
$options = $this -> config [ 'dc_options' ];
2017-05-11 00:43:50 +02:00
unset ( $this -> config [ 'dc_options' ]);
2020-01-31 19:29:43 +01:00
yield from $this -> parseDcOptions ( $options );
2017-05-11 00:43:50 +02:00
}
2017-02-11 15:16:57 +01:00
}
2019-10-31 12:45:19 +01:00
/**
2019-10-31 15:06:25 +01:00
* Parse DC options from config .
2019-10-31 12:45:19 +01:00
*
* @ param array $dc_options DC options
2019-10-31 15:06:25 +01:00
*
2019-10-31 12:45:19 +01:00
* @ return \Generator
*/
private function parseDcOptions ( array $dc_options ) : \Generator
2017-02-11 15:18:18 +01:00
{
2020-09-22 11:48:12 +02:00
$previous = $this -> dcList ;
2017-02-11 15:16:57 +01:00
foreach ( $dc_options as $dc ) {
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
$test = $this -> config [ 'test_mode' ] ? 'test' : 'main' ;
$id = $dc [ 'id' ];
2017-12-23 02:03:07 +01:00
if ( isset ( $dc [ 'static' ])) {
2018-03-01 20:49:22 +01:00
//$id .= $dc['static'] ? '_static' : '';
2017-12-23 02:03:07 +01:00
}
2017-07-20 16:20:19 +02:00
if ( isset ( $dc [ 'cdn' ])) {
$id .= $dc [ 'cdn' ] ? '_cdn' : '' ;
}
2017-04-21 13:13:24 +02:00
$id .= $dc [ 'media_only' ] ? '_media' : '' ;
2017-12-23 02:03:07 +01:00
$ipv6 = $dc [ 'ipv6' ] ? 'ipv6' : 'ipv4' ;
2019-09-01 01:52:28 +02:00
if ( \is_numeric ( $id )) {
2017-06-01 03:26:49 +02:00
$id = ( int ) $id ;
}
2019-09-01 01:52:28 +02:00
unset ( $dc [ 'cdn' ], $dc [ 'media_only' ], $dc [ 'id' ], $dc [ 'ipv6' ]);
2020-09-22 11:48:12 +02:00
$this -> dcList [ $test ][ $ipv6 ][ $id ] = $dc ;
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
}
2017-08-03 12:31:22 +02:00
$curdc = $this -> datacenter -> curdc ;
2020-09-22 11:48:12 +02:00
if ( $previous !== $this -> dcList && ( ! $this -> datacenter -> has ( $curdc ) || $this -> datacenter -> getDataCenterConnection ( $curdc ) -> byIPAddress ())) {
2019-09-17 21:35:53 +02:00
$this -> logger -> logger ( 'Got new DC options, reconnecting' );
2020-01-31 19:29:43 +01:00
yield from $this -> connectToAllDcs ( false );
2019-09-17 21:35:53 +02:00
}
2017-08-03 12:31:22 +02:00
$this -> datacenter -> curdc = $curdc ;
Added documentation, simplified code, organized exceptions, added some more examples in testing.php, decided to unset flags in deserialized responses, moved message id arrays to Connection classes, added wrappers for logging in to telegram as a bot or as a user and for logging out, fixed deserializing of gzip packed objects, added more logging, fixed bugs, added methods to get and parse configuration, saved some fairies, fixed exporting/importing of authorization, added some wakeup methods to prevent problems during serialization, added support for ipv6 and automagical detection too. I think we can safely say this is now a beta.
2016-11-25 00:15:22 +01:00
}
2019-10-31 11:17:22 +01:00
/**
2020-02-25 18:02:32 +01:00
* Get info about the logged - in user , cached .
*
* @ return array | bool
*/
public function getSelf ()
{
return $this -> authorization [ 'user' ] ? ? false ;
}
/**
* Get info about the logged - in user , not cached .
2019-10-31 11:17:22 +01:00
*
2020-02-25 18:02:32 +01:00
* @ return \Generator < array | bool >
2019-10-31 11:17:22 +01:00
*/
2020-02-25 18:02:32 +01:00
public function fullGetSelf () : \Generator
2017-03-11 19:55:56 +01:00
{
2017-09-25 22:33:37 +02:00
try {
2020-02-05 17:37:01 +01:00
$this -> authorization = [ 'user' => ( yield from $this -> methodCallAsyncRead ( 'users.getUsers' , [ 'id' => [[ '_' => 'inputUserSelf' ]]], [ 'datacenter' => $this -> datacenter -> curdc ]))[ 0 ]];
2017-09-25 22:34:13 +02:00
} catch ( RPCErrorException $e ) {
2018-04-08 19:53:30 +02:00
$this -> logger -> logger ( $e -> getMessage ());
2017-09-25 22:34:13 +02:00
return false ;
}
2017-03-24 21:01:08 +01:00
return $this -> authorization [ 'user' ];
2017-02-13 13:27:59 +01:00
}
2020-07-11 20:01:54 +02:00
/**
* Get authorization info .
*
* @ return int
*/
public function getAuthorization () : int
{
return $this -> authorized ;
}
2020-10-03 15:04:35 +02:00
/**
* Get current password hint .
*
* @ return string
*/
public function getHint () : string
{
if ( $this -> authorized !== self :: WAITING_PASSWORD ) {
throw new Exception ( " Not waiting for the password! " );
}
return $this -> authorization [ 'hint' ];
}
2020-02-23 19:28:42 +01:00
/**
* IDs of peers where to report errors .
*
* @ var int []
*/
private $reportDest = [];
/**
* Check if has report peers .
*
* @ return boolean
*/
public function hasReportPeers () : bool
{
return ( bool ) $this -> reportDest ;
}
/**
* Set peer ( s ) where to send errors occurred in the event loop .
*
* @ param int | string $userOrId Username ( s ) or peer ID ( s )
*
* @ return \Generator
*/
public function setReportPeers ( $userOrId ) : \Generator
{
if ( ! ( \is_array ( $userOrId ) && ! isset ( $userOrId [ '_' ]) && ! isset ( $userOrId [ 'id' ]))) {
$userOrId = [ $userOrId ];
}
2020-09-22 11:48:12 +02:00
foreach ( $userOrId as $k => & $peer ) {
try {
$peer = ( yield from $this -> getInfo ( $peer ))[ 'bot_api_id' ];
} catch ( \Throwable $e ) {
unset ( $userOrId [ $k ]);
$this -> logger ( " Could not obtain info about report peer $peer : $e " , Logger :: FATAL_ERROR );
}
2020-02-23 19:28:42 +01:00
}
2020-10-04 16:27:22 +02:00
/** @var int[] $userOrId */
2020-02-23 19:28:42 +01:00
$this -> reportDest = $userOrId ;
}
/**
* Report an error to the previously set peer .
*
2020-09-24 11:45:20 +02:00
* @ param string $message Error to report
* @ param string $parseMode Parse mode
2020-02-23 19:28:42 +01:00
*
* @ return \Generator
*/
2020-09-24 11:45:20 +02:00
public function report ( string $message , string $parseMode = '' ) : \Generator
2020-02-23 19:28:42 +01:00
{
if ( ! $this -> reportDest ) {
return ;
}
2020-02-26 12:45:30 +01:00
$file = null ;
2020-09-22 11:48:12 +02:00
if ( $this -> settings -> getLogger () -> getType () === Logger :: FILE_LOGGER
&& $path = $this -> settings -> getLogger () -> getExtra ()) {
2020-02-26 12:45:30 +01:00
StatCache :: clear ( $path );
if ( ! yield exists ( $path )) {
$message = " !!! WARNING !!! \n The logfile does not exist, please DO NOT delete the logfile to avoid errors in MadelineProto! \n \n $message " ;
} elseif ( ! yield size ( $path )) {
$message = " !!! WARNING !!! \n The logfile is empty, please DO NOT delete the logfile to avoid errors in MadelineProto! \n \n $message " ;
} else {
$file = yield from $this -> methodCallAsyncRead (
2020-02-26 14:14:26 +01:00
'messages.uploadMedia' ,
2020-02-26 12:45:30 +01:00
[
2020-02-26 14:14:26 +01:00
'peer' => $this -> reportDest [ 0 ],
2020-02-26 12:45:30 +01:00
'media' => [
'_' => 'inputMediaUploadedDocument' ,
'file' => $path ,
'attributes' => [
[ '_' => 'documentAttributeFilename' , 'file_name' => 'MadelineProto.log' ]
]
]
]
);
}
}
$sent = true ;
2020-02-23 19:28:42 +01:00
foreach ( $this -> reportDest as $id ) {
try {
2020-09-24 11:45:20 +02:00
yield from $this -> methodCallAsyncRead ( 'messages.sendMessage' , [ 'peer' => $id , 'message' => $message , 'parse_mode' => $parseMode ]);
2020-02-26 15:15:37 +01:00
if ( $file ) {
yield from $this -> methodCallAsyncRead ( 'messages.sendMedia' , [ 'peer' => $id , 'media' => $file ]);
}
2020-02-26 12:45:30 +01:00
$sent &= true ;
2020-02-23 19:28:42 +01:00
} catch ( \Throwable $e ) {
2020-02-26 12:45:30 +01:00
$sent &= false ;
2020-02-23 19:28:42 +01:00
$this -> logger ( " While reporting to $id : $e " , Logger :: FATAL_ERROR );
}
}
2020-02-26 12:45:30 +01:00
if ( $sent && $file ) {
2020-02-26 14:14:26 +01:00
\ftruncate ( $this -> logger -> stdout -> getResource (), 0 );
2020-02-26 12:45:30 +01:00
$this -> logger -> logger ( " Reported! " );
}
2020-02-23 19:28:42 +01:00
}
2020-02-25 18:02:32 +01:00
/**
* Get full list of MTProto and API methods .
*
* @ return array
*/
public function getAllMethods () : array
{
$methods = [];
foreach ( $this -> getTL () -> getMethods () -> by_id as $method ) {
$methods [] = $method [ 'method' ];
}
return \array_merge ( $methods , \get_class_methods ( InternalDoc :: class ));
}
2019-12-28 16:07:09 +01:00
/**
* Called right before serialization of method starts .
*
* Pass the method name
*
* @ return array
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public function getMethodCallbacks () : array
{
return [];
}
2019-12-28 16:07:09 +01:00
/**
* Called right before serialization of method starts .
*
* Pass the method name
*
* @ return array
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public function getMethodBeforeCallbacks () : array
{
return [];
}
2019-12-28 16:07:09 +01:00
/**
* Called right after deserialization of object , passing the final object .
*
* @ return array
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public function getConstructorCallbacks () : array
{
2020-06-23 20:30:40 +02:00
return \array_merge (
\array_fill_keys ([ 'chat' , 'chatEmpty' , 'chatForbidden' , 'channel' , 'channelEmpty' , 'channelForbidden' ], [[ $this , 'addChat' ]]),
\array_fill_keys ([ 'user' , 'userEmpty' ], [[ $this , 'addUser' ]]),
[ 'help.support' => [[ $this , 'addSupport' ]]]
);
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2019-12-28 16:07:09 +01:00
/**
* Called right before deserialization of object .
*
* Pass only the constructor name
*
* @ return array
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public function getConstructorBeforeCallbacks () : array
{
return [];
}
2019-12-28 16:07:09 +01:00
/**
* Called right before serialization of constructor .
*
* Passed the object , will return a modified version .
*
* @ return array
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public function getConstructorSerializeCallbacks () : array
{
return [];
}
2019-12-28 16:07:09 +01:00
/**
* Called if objects of the specified type cannot be serialized .
*
* Passed the unserializable object ,
* will try to convert it to an object of the proper type .
*
* @ return array
*/
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
public function getTypeMismatchCallbacks () : array
{
2020-01-31 19:29:43 +01:00
return \array_merge ( \array_fill_keys ([ 'User' , 'InputUser' , 'Chat' , 'InputChannel' , 'Peer' , 'InputPeer' , 'InputDialogPeer' , 'InputNotifyPeer' ], [ $this , 'getInfo' ]), \array_fill_keys ([ 'InputMedia' , 'InputDocument' , 'InputPhoto' ], [ $this , 'getFileInfo' ]), \array_fill_keys ([ 'InputFileLocation' ], [ $this , 'getDownloadInfo' ]));
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2019-10-31 11:17:22 +01:00
/**
2019-10-31 15:06:25 +01:00
* Get debug information for var_dump .
2019-10-31 11:17:22 +01:00
*
* @ return array
*/
public function __debugInfo () : array
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
{
2020-02-26 11:47:30 +01:00
$vars = \get_object_vars ( $this );
unset ( $vars [ 'full_chats' ], $vars [ 'chats' ], $vars [ 'referenceDatabase' ], $vars [ 'minDatabase' ], $vars [ 'TL' ]);
2020-02-25 19:10:49 +01:00
return $vars ;
Merge alpha into master (async, huge bugfixes and more) (#546)
* Implement async and lots of bugfixes
* Implement more async
* Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr
* Apply fixes from StyleCI
* Bugfixes
* Apply fixes from StyleCI
* Bugfixes, implement combined promises
* Apply fixes from StyleCI
* Support passing method arguments as callable
* Starting to write async upload logic
* Apply fixes from StyleCI
* Start implementing async file upload
* Apply fixes from StyleCI
* bugfix
* Apply fixes from StyleCI
* Start rewriting connection module
* Add PHP file docblocks for all classes
* Start working on new async stream API
* Finish writing stream API
* More stream API fixes
* Apply fixes from StyleCI
* Rewrite DataCenter and Connection modules
* Clean up stream API documentation
* Fixes
* Apply fixes from StyleCI
* Add referenced parameter to get length of buffer to read in getReadBuffer API
* Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar
* Start fixing reads
* Fix all protocol stream wrappers
* Apply fixes from StyleCI
* Implement disconnection, and remove end function
* Working async RPC
* Implement async file upload
* Bugfix
* Method recall bugfixes
* Bugfixes
* Trait bugfixes
* Fix FIFO buffer
* Bugfixes and speedtests
* Async logging
* Implement websocket streams
* Implement loop API, signal API, clean closing and start changing layer
* Small magna, websocket and HTTP fixes
* Clean up loop API
* Improved stack traces, 2FA and async
* Login fixes
* Added instructions for manual verification
* Small fixes
* More app info improvements
* More app info improvements
* TL and 2FA fixes
* Update to layer 89
* More bugfixes
* Implement broken media reporting
* Remove debug comments
* PHP 7.2 backwards compatibility
* Bugfixes
* Async key generation
* Some simplifications
* Transport fixes
* Cleanup
* async API
* Performance fixes
* Fixes to async API
* Bugfixes
* Implement one-time async loop
* Authorization and logging fixes
* Update to layer 91
* 7to5 fix
* Null coalesce conversion
* Implement socks5 proxy
* Implement HTTP proxy
* Fixes to HTTP proxy
* MTProxy and socks5 fixes
* Disable PHP 5 conversion
* Proxies have higher priority
* Avoid error handling in vendor
* Override composer dependencies
* Fix travis build
* Final composer fixes
* Proxy logic fixes
* Fix get_updates update handling
* Do not use parallel file driver if not supported
* Refactor loader and implement HTTP fixes
* Suppress errors in loader
* HTTP and authorization fixes
* HTTP fixes
* Improved peer management
* Use HTTP protocol on altervista
* Small bugfixes
* Minor fixes
* Docufix
* Docufix
* Legacy fixes
* Fix message queue
* Avoid updating if using MTProxy
* Improve logs and examples
* Trim final newlines while converting parse mode
* Reimplement noResponse flag
* Async combined event handler and APIFactory fixes
* Actually return config
* Case-insensitive methods
* Bugfix
* Apply fixes from StyleCI (#545)
* MTProxy fixes
* PHP 5 warning
* Improved PHP 5 warning
* Use <br> along with newlines in web logs
* Update docs
2018-12-26 20:51:14 +01:00
}
2016-09-10 19:53:28 +02:00
}