Make the stream API generic again

This commit is contained in:
Daniil Gentili 2019-06-20 20:30:29 +02:00
parent 0a33f69e8b
commit d82914187c
2 changed files with 38 additions and 4 deletions

View File

@ -507,7 +507,24 @@ class DataCenter
foreach ($combo as $stream) {
if ($stream[0] === DefaultStream::getName() && $stream[1] === []) {
$stream[1] = [[$this, 'socketConnect'], [$this, 'cryptoConnect']];
$isIpv6 = $ipv6 === 'ipv6';
$stream[1] = [
function (
string $uri,
ClientConnectContext $socketContext = null,
CancellationToken $token = null
) use ($isIpv6): Promise {
return $this->socketConnect($isIpv6, $uri, $socketContext, $token);
},
function (
string $uri,
ClientConnectContext $socketContext = null,
ClientTlsContext $tlsContext = null,
CancellationToken $token = null
) use ($isIpv6): Promise {
return $this->cryptoConnect($isIpv6, $uri, $socketContext, $tlsContext, $token);
}
];
}
$ctx->addStream(...$stream);
}
@ -567,7 +584,24 @@ class DataCenter
foreach ($combo as $stream) {
if ($stream[0] === DefaultStream::getName() && $stream[1] === []) {
$stream[1] = [[$this, 'socketConnect'], [$this, 'cryptoConnect']];
$isIpv6 = $ipv6 === 'ipv6';
$stream[1] = [
function (
string $uri,
ClientConnectContext $socketContext = null,
CancellationToken $token = null
) use ($isIpv6): Promise {
return $this->socketConnect($isIpv6, $uri, $socketContext, $token);
},
function (
string $uri,
ClientConnectContext $socketContext = null,
ClientTlsContext $tlsContext = null,
CancellationToken $token = null
) use ($isIpv6): Promise {
return $this->cryptoConnect($isIpv6, $uri, $socketContext, $tlsContext, $token);
}
];
}
$ctx->addStream(...$stream);
}

View File

@ -57,9 +57,9 @@ class DefaultStream extends Socket implements RawStreamInterface, ProxyStreamInt
public function connectAsync(\danog\MadelineProto\Stream\ConnectionContext $ctx, string $header = ''): \Generator
{
if ($ctx->isSecure()) {
$this->stream = yield ($this->cryptoConnector)($ctx->getIpv6(), $ctx->getStringUri(), $ctx->getSocketContext(), null, $ctx->getCancellationToken());
$this->stream = yield ($this->cryptoConnector)($ctx->getStringUri(), $ctx->getSocketContext(), null, $ctx->getCancellationToken());
} else {
$this->stream = yield ($this->connector)($ctx->getIpv6(), $ctx->getStringUri(), $ctx->getSocketContext(), $ctx->getCancellationToken());
$this->stream = yield ($this->connector)($ctx->getStringUri(), $ctx->getSocketContext(), $ctx->getCancellationToken());
}
yield $this->stream->write($header);
}