private function negotiateCrypto(string $watcherId, $socket, $peer)
{
list($ip, $port) = $peer;
if ($handshake = @\stream_socket_enable_crypto($socket, true)) {
$socketId = (int) $socket;
\Amp\cancel($watcherId);
unset($this->pendingTlsStreams[$socketId]);
assert((function () use($socket, $ip, $port) {
$meta = stream_get_meta_data($socket)["crypto"];
$isH2 = isset($meta["alpn_protocol"]) && $meta["alpn_protocol"] === "h2";
return $this->logDebug(sprintf("crypto negotiated %s%s:%d", $isH2 ? "(h2) " : "", $ip, $port));
})());
// Dispatch via HTTP 1 driver; it knows how to handle PRI * requests - for now it is easier to dispatch only via content (ignore alpn)...
$this->importClient($socket, $ip, $port);
} elseif ($handshake === false) {
assert($this->logDebug("crypto handshake error {$ip}:{$port}"));
$this->failCryptoNegotiation($socket, $ip);
}
}