Improve peer management and phar creation, implement secondary auto-update mechanism

This commit is contained in:
Daniil Gentili 2018-02-25 16:17:28 +00:00
parent eddbb40f34
commit 79618223b7
3 changed files with 20 additions and 8 deletions

View File

@ -20,6 +20,20 @@ if (!isset($argv[3])) {
$p = new Phar(__DIR__.'/'.$argv[2], 0, $argv[2]);
$p->buildFromDirectory(realpath($argv[1]), '/^((?!tests).)*(\.php|\.py|\.tl|\.json)$/i');
$p->addFromString('vendor/danog/madelineproto/.git/refs/heads/master', $argv[3]);
$p->addFromString('.git/refs/heads/master', $argv[3]);
$p->setStub('<?php Phar::interceptFileFuncs(); Phar::mapPhar("'.$argv[2].'"); require_once "phar://'.$argv[2].'/vendor/autoload.php"; __HALT_COMPILER(); ?>');
$p->setStub('<?php
$backtrace = debug_backtrace();
if (basename($backtrace[0]["file"]) === "phar.php") {
chdir(dirname($backtrace[1]["file"]));
if (!isset($phar_debug)) file_put_contents($backtrace[0]["file"], file_get_contents("https://phar.madelineproto.xyz/phar.php?v=new"));
}
if ((new Phar(__FILE__))[".git/refs/heads/master"]->getContent() !== file_get_contents("https://phar.madelineproto.xyz/release?v=new") && !isset($phar_debug)) {
file_put_contents(__FILE__, file_get_contents("https://phar.madelineproto.xyz/madeline.phar?v=new"));
}
Phar::interceptFileFuncs();
Phar::mapPhar("'.$argv[2].'");
require_once "phar://'.$argv[2].'/vendor/autoload.php";
__HALT_COMPILER(); ?>');

View File

@ -71,12 +71,8 @@ trait MessageHandler
public function recv_message($datacenter)
{
if ($this->datacenter->sockets[$datacenter]->must_open) {
\danog\MadelineProto\Logger::log(['Trying to write in closed socket, sending initial ping/http_wait']);
if ($this->is_http($datacenter)) {
$this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]);
} else {
$this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]);
}
\danog\MadelineProto\Logger::log(['Trying to read from closed socket, sending initial ping']);
$this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]);
}
$payload = $this->datacenter->sockets[$datacenter]->read_message();
if (strlen($payload) === 4) {

View File

@ -208,7 +208,9 @@ trait PeerHandler
if (!isset($this->settings['pwr']['requests']) || $this->settings['pwr']['requests'] === true) {
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true);
if (isset($dbres['ok']) && $dbres['ok']) {
return $this->get_info('@'.$dbres['result']);
$this->resolve_username('@'.$dbres['result']);
return $this->get_info($id, false);
}
}