/** * @memcheck */ public function testEncrypt() { $listener = new Listener(ION_TEST_SERVER_HOST); $server_ssl = Crypto::server(Crypto::METHOD_TLSv12)->passPhrase('unittest')->localCert(ION_RESOURCES . '/cacert.pem', ION_RESOURCES . '/cakey.pem')->allowSelfSigned(); $client_ssl = Crypto::client(Crypto::METHOD_TLSv12)->allowSelfSigned(); $listener->encrypt($server_ssl); $listener->whenAccepted()->then(function (Stream $connect) { $this->data["connect"] = $this->describe($connect); $this->data["incoming"] = (yield $connect->readLine("\r\n")); $connect->write("welcome\r\n"); (yield $connect->flush()); $this->stop(); })->onFail(function (\Throwable $error) { $this->data["server.error"] = $this->describe($error); $this->stop(); }); $this->promise(function () use($client_ssl) { $socket = Stream::socket(ION_TEST_SERVER_HOST, $client_ssl); $socket->write("hello\r\n"); $this->data["outgoing"] = (yield $socket->readLine("\r\n")); }, false); $this->loop(); $this->assertEquals(["connect" => ["object" => "ION\\Stream"], "incoming" => "hello", "outgoing" => "welcome"], $this->data); }
public function listener($ip, callable $callback) { $listener = new Listener($ip); $listener->whenAccepted()->then($callback)->onFail(function ($error) { $this->data["listener.error"] = $this->describe($error); }); return $listener; }