1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-23 06:31:11 +01:00
This commit is contained in:
Daniil Gentili 2024-05-20 16:14:34 +02:00
parent cda2583744
commit 9ad145fade
4 changed files with 24 additions and 30 deletions

View File

@ -3370,6 +3370,7 @@
</PossiblyInvalidPropertyAssignmentValue>
<PossiblyNullOperand>
<code><![CDATA[$this->sent]]></code>
<code><![CDATA[$this->sent]]></code>
</PossiblyNullOperand>
</file>
<file src="src/MTProto/PermAuthKey.php">
@ -3639,16 +3640,6 @@
<code><![CDATA[$msgId]]></code>
<code><![CDATA[$request->getMsgId()]]></code>
</PossiblyNullArgument>
<PossiblyNullOperand>
<code><![CDATA[$request->getSent()]]></code>
<code><![CDATA[$request->getSent()]]></code>
</PossiblyNullOperand>
<PossiblyNullReference>
<code><![CDATA[dec]]></code>
<code><![CDATA[dec]]></code>
<code><![CDATA[observe]]></code>
<code><![CDATA[observe]]></code>
</PossiblyNullReference>
<RedundantConditionGivenDocblockType>
<code><![CDATA[$this->API->authorized_dc == $this->datacenter && $this->API->authorized === \danog\MadelineProto\API::LOGGED_IN]]></code>
</RedundantConditionGivenDocblockType>

View File

@ -186,15 +186,16 @@ final class DataCenter
*/
private function generateContexts(int $dc_number): ContextIterator
{
$test = $this->getSettings()->getTestMode() ? 'test' : 'main';
$ipv6 = $this->getSettings()->getIpv6() ? 'ipv6' : 'ipv4';
$settings = $this->getSettings();
$test = $settings->getTestMode() ? 'test' : 'main';
$ipv6 = $settings->getIpv6() ? 'ipv6' : 'ipv4';
if (!isset($this->API->dcList[$test][$ipv6][$dc_number])) {
throw new AssertionError("No info for DC $dc_number!");
}
$ctxs = [];
$combos = [];
$default = match ($this->getSettings()->getProtocol()) {
$default = match ($settings->getProtocol()) {
AbridgedStream::class =>
[[DefaultStream::class, []], [BufferedRawStream::class, []], [AbridgedStream::class, []]],
IntermediateStream::class =>
@ -210,13 +211,13 @@ final class DataCenter
UdpBufferedStream::class =>
[[DefaultStream::class, []], [UdpBufferedStream::class, []]],
};
if ($this->getSettings()->getObfuscated() && !\in_array($default[2][0], [HttpsStream::class, HttpStream::class], true)) {
if ($settings->getObfuscated() && !\in_array($default[2][0], [HttpsStream::class, HttpStream::class], true)) {
$default = [[DefaultStream::class, []], [BufferedRawStream::class, []], [ObfuscatedStream::class, []], end($default)];
}
if (!\in_array($default[2][0], [HttpsStream::class, HttpStream::class], true)) {
switch ($this->getSettings()->getTransport()) {
switch ($settings->getTransport()) {
case DefaultStream::class:
if ($this->getSettings()->getObfuscated()) {
if ($settings->getObfuscated()) {
$default = [[DefaultStream::class, []], [BufferedRawStream::class, []], [ObfuscatedStream::class, []], end($default)];
}
break;
@ -241,7 +242,7 @@ final class DataCenter
}
}
$proxyCombos = [];
foreach ($this->getSettings()->getProxies() as $proxy => $extras) {
foreach ($settings->getProxies() as $proxy => $extras) {
foreach ($extras as $extra) {
if ($proxy === ObfuscatedStream::class && \in_array(\strlen($extra['secret']), [17, 34], true)) {
$combos[] = [[DefaultStream::class, []], [BufferedRawStream::class, []], [$proxy, $extra], [IntermediatePaddedStream::class, []]];
@ -273,7 +274,7 @@ final class DataCenter
}
}
}
if ($this->getSettings()->getRetry()) {
if ($settings->getRetry()) {
$combos = array_merge($proxyCombos, $combos);
$combos[] = [[DefaultStream::class, []], [BufferedRawStream::class, []], [HttpsStream::class, []]];
} elseif ($proxyCombos) {
@ -281,19 +282,19 @@ final class DataCenter
}
$combos = array_unique($combos, SORT_REGULAR);
$bind = self::normalizeBindToOption($this->getSettings()->getBindTo());
$bind = self::normalizeBindToOption($settings->getBindTo());
$onlyIPv6 = null;
if ($bind !== null) {
$onlyIPv6 = InternetAddress::fromString($bind)->getVersion() === InternetAddressVersion::IPv6
? 'ipv6'
: 'ipv4';
}
$context = (new ConnectContext())->withConnectTimeout($this->getSettings()->getTimeout())->withBindTo($bind);
$context = (new ConnectContext())->withConnectTimeout($settings->getTimeout())->withBindTo($bind);
foreach ($combos as $combo) {
foreach ([true, false] as $useDoH) {
$ipv6Combos = [
$this->getSettings()->getIpv6() ? 'ipv6' : 'ipv4',
$this->getSettings()->getIpv6() ? 'ipv4' : 'ipv6',
$settings->getIpv6() ? 'ipv6' : 'ipv4',
$settings->getIpv6() ? 'ipv4' : 'ipv6',
];
foreach ($ipv6Combos as $ipv6) {
if ($onlyIPv6 !== null && $onlyIPv6 !== $ipv6) {
@ -310,14 +311,14 @@ final class DataCenter
foreach (array_unique([$port, 443, 80, 88, 5222]) as $port) {
$stream = end($combo)[0];
if ($stream === HttpsStream::class) {
$subdomain = $this->getSettings()->getSslSubdomains()[abs($dc_number)] ?? null;
$subdomain = $settings->getSslSubdomains()[abs($dc_number)] ?? null;
if (!$subdomain) {
continue;
}
if (DataCenter::isMedia($dc_number)) {
$subdomain .= '-1';
}
$path = $this->getSettings()->getTestMode() ? 'apiw_test1' : 'apiw1';
$path = $settings->getTestMode() ? 'apiw_test1' : 'apiw1';
$uri = 'tcp://'.$subdomain.'.web.telegram.org:'.$port.'/'.$path;
} elseif ($stream === HttpStream::class) {
$uri = 'tcp://'.$address.':'.$port.'/api';
@ -337,17 +338,17 @@ final class DataCenter
if (\in_array($stream[0], [WsStream::class, WssStream::class], true) && $stream[1] === []) {
$stream[1] = $this->dohWrapper->webSocketConnector;
if ($stream[0] === WssStream::class) {
$subdomain = $this->getSettings()->getSslSubdomains()[abs($dc_number)] ?? null;
$subdomain = $settings->getSslSubdomains()[abs($dc_number)] ?? null;
if (!$subdomain) {
continue;
}
if (DataCenter::isMedia($dc_number)) {
$subdomain .= '-1';
}
$path = $this->getSettings()->getTestMode() ? 'apiws_test' : 'apiws';
$path = $settings->getTestMode() ? 'apiws_test' : 'apiws';
$uri = 'tcp://'.$subdomain.'.web.telegram.org:'.$port.'/'.$path;
} else {
$path = $this->getSettings()->getTestMode() ? 'apiws_test' : 'apiws';
$path = $settings->getTestMode() ? 'apiws_test' : 'apiws';
$uri = 'tcp://'.$address.':'.$port.'/'.$path;
}
$ctx->setUri($uri);

View File

@ -325,7 +325,7 @@ final class WriteLoop extends Loop
if ($count > 1 || $has_seq) {
$this->API->logger("Wrapping in msg_container ({$count} messages of total size {$total_length}) as encrypted message for DC {$this->datacenter}", Logger::ULTRA_VERBOSE);
$message_id = $this->connection->msgIdHandler->generateMessageId();
$this->connection->pendingOutgoing[$this->connection->pendingOutgoingKey] = new Container(array_values($keys));
$this->connection->pendingOutgoing[$this->connection->pendingOutgoingKey] = new Container($this->connection, array_values($keys));
$this->connection->outgoingCtr?->inc();
$this->connection->pendingOutgoingGauge?->set(\count($this->connection->pendingOutgoing));
$keys[$this->connection->pendingOutgoingKey++] = $message_id;

View File

@ -20,6 +20,8 @@ declare(strict_types=1);
namespace danog\MadelineProto\MTProto;
use danog\MadelineProto\Connection;
/**
* Outgoing container message.
*
@ -39,10 +41,10 @@ final class Container extends MTProtoOutgoingMessage
*
* @param list<int> $ids
*/
public function __construct(array $ids)
public function __construct(Connection $connection, array $ids)
{
$this->ids = $ids;
parent::__construct([], 'msg_container', '', false, false);
parent::__construct($connection, [], 'msg_container', '', false, false);
}
/**
* Get message IDs.