Merge pull request #54 from ratchetphp/v0.3.1

v0.3.1
This commit is contained in:
Chris Boden 2021-12-09 18:20:49 -05:00 committed by GitHub
commit 7c964514e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 41 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2011-2016 Chris Boden Copyright (c) 2011 Chris Boden
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -27,10 +27,10 @@
}, },
"require": { "require": {
"php": ">=5.4.2", "php": ">=5.4.2",
"guzzlehttp/psr7": "^1.0" "guzzlehttp/psr7": "^2 || ^1.7"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "5.7.*", "phpunit/phpunit": "^5.7",
"react/socket": "^1.3" "react/socket": "^1.3"
}, },
"scripts": { "scripts": {

View File

@ -327,15 +327,6 @@ class Frame implements FrameInterface {
} }
return $payload ^ str_pad('', $len, $maskingKey, STR_PAD_RIGHT); return $payload ^ str_pad('', $len, $maskingKey, STR_PAD_RIGHT);
// TODO: Remove this before publish - keeping methods here to compare performance (above is faster but need control against v0.3.3)
$applied = '';
for ($i = 0, $len = strlen($payload); $i < $len; $i++) {
$applied .= $payload[$i] ^ $maskingKey[$i % static::MASK_LENGTH];
}
return $applied;
} }
/** /**

View File

@ -117,10 +117,10 @@ class MessageBuffer {
$memory_limit_bytes = static::getMemoryLimit(); $memory_limit_bytes = static::getMemoryLimit();
if ($maxMessagePayloadSize === null) { if ($maxMessagePayloadSize === null) {
$maxMessagePayloadSize = $memory_limit_bytes / 4; $maxMessagePayloadSize = (int)($memory_limit_bytes / 4);
} }
if ($maxFramePayloadSize === null) { if ($maxFramePayloadSize === null) {
$maxFramePayloadSize = $memory_limit_bytes / 4; $maxFramePayloadSize = (int)($memory_limit_bytes / 4);
} }
if (!is_int($maxFramePayloadSize) || $maxFramePayloadSize > 0x7FFFFFFFFFFFFFFF || $maxFramePayloadSize < 0) { // this should be interesting on non-64 bit systems if (!is_int($maxFramePayloadSize) || $maxFramePayloadSize > 0x7FFFFFFFFFFFFFFF || $maxFramePayloadSize < 0) { // this should be interesting on non-64 bit systems

View File

@ -1,4 +1,6 @@
<?php <?php
use GuzzleHttp\Psr7\Message;
use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\Uri;
use Ratchet\RFC6455\Handshake\InvalidPermessageDeflateOptionsException; use Ratchet\RFC6455\Handshake\InvalidPermessageDeflateOptionsException;
use Ratchet\RFC6455\Handshake\PermessageDeflateOptions; use Ratchet\RFC6455\Handshake\PermessageDeflateOptions;
@ -15,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
define('AGENT', 'RatchetRFC/0.3'); define('AGENT', 'RatchetRFC/0.3');
$testServer = "127.0.0.1"; $testServer = $argc > 1 ? $argv[1] : "127.0.0.1";
$loop = React\EventLoop\Factory::create(); $loop = React\EventLoop\Factory::create();
@ -55,9 +57,9 @@ function getTestCases() {
$deferred = new Deferred(); $deferred = new Deferred();
$connector->connect($testServer . ':9001')->then(function (ConnectionInterface $connection) use ($deferred) { $connector->connect($testServer . ':9002')->then(function (ConnectionInterface $connection) use ($deferred, $testServer) {
$cn = new ClientNegotiator(); $cn = new ClientNegotiator();
$cnRequest = $cn->generateRequest(new Uri('ws://127.0.0.1:9001/getCaseCount')); $cnRequest = $cn->generateRequest(new Uri('ws://' . $testServer . ':9002/getCaseCount'));
$rawResponse = ""; $rawResponse = "";
$response = null; $response = null;
@ -72,7 +74,7 @@ function getTestCases() {
if ($pos) { if ($pos) {
$data = substr($rawResponse, $pos + 4); $data = substr($rawResponse, $pos + 4);
$rawResponse = substr($rawResponse, 0, $pos + 4); $rawResponse = substr($rawResponse, 0, $pos + 4);
$response = \GuzzleHttp\Psr7\parse_response($rawResponse); $response = Message::parseResponse($rawResponse);
if (!$cn->validateResponse($cnRequest, $response)) { if (!$cn->validateResponse($cnRequest, $response)) {
$connection->end(); $connection->end();
@ -101,7 +103,7 @@ function getTestCases() {
} }
}); });
$connection->write(\GuzzleHttp\Psr7\str($cnRequest)); $connection->write(Message::toString($cnRequest));
}); });
return $deferred->promise(); return $deferred->promise();
@ -120,10 +122,10 @@ function runTest($case)
$deferred = new Deferred(); $deferred = new Deferred();
$connector->connect($testServer . ':9001')->then(function (ConnectionInterface $connection) use ($deferred, $casePath, $case) { $connector->connect($testServer . ':9002')->then(function (ConnectionInterface $connection) use ($deferred, $casePath, $case, $testServer) {
$cn = new ClientNegotiator( $cn = new ClientNegotiator(
PermessageDeflateOptions::permessageDeflateSupported() ? PermessageDeflateOptions::createEnabled() : null); PermessageDeflateOptions::permessageDeflateSupported() ? PermessageDeflateOptions::createEnabled() : null);
$cnRequest = $cn->generateRequest(new Uri('ws://127.0.0.1:9001' . $casePath)); $cnRequest = $cn->generateRequest(new Uri('ws://' . $testServer . ':9002' . $casePath));
$rawResponse = ""; $rawResponse = "";
$response = null; $response = null;
@ -137,7 +139,7 @@ function runTest($case)
if ($pos) { if ($pos) {
$data = substr($rawResponse, $pos + 4); $data = substr($rawResponse, $pos + 4);
$rawResponse = substr($rawResponse, 0, $pos + 4); $rawResponse = substr($rawResponse, 0, $pos + 4);
$response = \GuzzleHttp\Psr7\parse_response($rawResponse); $response = Message::parseResponse($rawResponse);
if (!$cn->validateResponse($cnRequest, $response)) { if (!$cn->validateResponse($cnRequest, $response)) {
echo "Invalid response.\n"; echo "Invalid response.\n";
@ -167,7 +169,7 @@ function runTest($case)
$deferred->resolve(); $deferred->resolve();
}); });
$connection->write(\GuzzleHttp\Psr7\str($cnRequest)); $connection->write(Message::toString($cnRequest));
}); });
return $deferred->promise(); return $deferred->promise();
@ -179,12 +181,12 @@ function createReport() {
$deferred = new Deferred(); $deferred = new Deferred();
$connector->connect($testServer . ':9001')->then(function (ConnectionInterface $connection) use ($deferred) { $connector->connect($testServer . ':9002')->then(function (ConnectionInterface $connection) use ($deferred, $testServer) {
// $reportPath = "/updateReports?agent=" . AGENT . "&shutdownOnComplete=true"; // $reportPath = "/updateReports?agent=" . AGENT . "&shutdownOnComplete=true";
// we will stop it using docker now instead of just shutting down // we will stop it using docker now instead of just shutting down
$reportPath = "/updateReports?agent=" . AGENT; $reportPath = "/updateReports?agent=" . AGENT;
$cn = new ClientNegotiator(); $cn = new ClientNegotiator();
$cnRequest = $cn->generateRequest(new Uri('ws://127.0.0.1:9001' . $reportPath)); $cnRequest = $cn->generateRequest(new Uri('ws://' . $testServer . ':9002' . $reportPath));
$rawResponse = ""; $rawResponse = "";
$response = null; $response = null;
@ -199,7 +201,7 @@ function createReport() {
if ($pos) { if ($pos) {
$data = substr($rawResponse, $pos + 4); $data = substr($rawResponse, $pos + 4);
$rawResponse = substr($rawResponse, 0, $pos + 4); $rawResponse = substr($rawResponse, 0, $pos + 4);
$response = \GuzzleHttp\Psr7\parse_response($rawResponse); $response = Message::parseResponse($rawResponse);
if (!$cn->validateResponse($cnRequest, $response)) { if (!$cn->validateResponse($cnRequest, $response)) {
$connection->end(); $connection->end();
@ -228,7 +230,7 @@ function createReport() {
} }
}); });
$connection->write(\GuzzleHttp\Psr7\str($cnRequest)); $connection->write(Message::toString($cnRequest));
}); });
return $deferred->promise(); return $deferred->promise();

View File

@ -1,5 +1,5 @@
{ {
"url": "ws://127.0.0.1:9001" "url": "ws://127.0.0.1:9002"
, "options": { , "options": {
"failByDrop": false "failByDrop": false
} }

View File

@ -1,5 +1,5 @@
{ {
"url": "ws://127.0.0.1:9001" "url": "ws://127.0.0.1:9002"
, "options": { , "options": {
"failByDrop": false "failByDrop": false
} }

View File

@ -6,13 +6,13 @@ if [ "$ABTEST" = "client" ]; then
-d \ -d \
-v ${PWD}:/config \ -v ${PWD}:/config \
-v ${PWD}/reports:/reports \ -v ${PWD}/reports:/reports \
-p 9001:9001 \ -p 9002:9002 \
--name fuzzingserver \ --name fuzzingserver \
crossbario/autobahn-testsuite wstest -m fuzzingserver -s /config/fuzzingserver$SKIP_DEFLATE.json crossbario/autobahn-testsuite wstest -m fuzzingserver -s /config/fuzzingserver$SKIP_DEFLATE.json
sleep 5 sleep 5
if [ "$TRAVIS" != "true" ]; then if [ "$TRAVIS" != "true" ]; then
echo "Running tests vs Autobahn test client" echo "Running tests vs Autobahn test client"
###docker run -it --rm --name abpytest crossbario/autobahn-testsuite wstest --mode testeeclient -w ws://host.docker.internal:9001 ###docker run -it --rm --name abpytest crossbario/autobahn-testsuite wstest --mode testeeclient -w ws://host.docker.internal:9002
fi fi
php -d memory_limit=256M clientRunner.php php -d memory_limit=256M clientRunner.php

View File

@ -1,5 +1,6 @@
<?php <?php
use GuzzleHttp\Psr7\Message;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Ratchet\RFC6455\Handshake\PermessageDeflateOptions; use Ratchet\RFC6455\Handshake\PermessageDeflateOptions;
use Ratchet\RFC6455\Messaging\MessageBuffer; use Ratchet\RFC6455\Messaging\MessageBuffer;
@ -35,18 +36,18 @@ $socket->on('connection', function (React\Socket\ConnectionInterface $connection
return; return;
} }
$headerComplete = true; $headerComplete = true;
$psrRequest = \GuzzleHttp\Psr7\parse_request($parts[0] . "\r\n\r\n"); $psrRequest = Message::parseRequest($parts[0] . "\r\n\r\n");
$negotiatorResponse = $negotiator->handshake($psrRequest); $negotiatorResponse = $negotiator->handshake($psrRequest);
$negotiatorResponse = $negotiatorResponse->withAddedHeader("Content-Length", "0"); $negotiatorResponse = $negotiatorResponse->withAddedHeader("Content-Length", "0");
if ($negotiatorResponse->getStatusCode() !== 101 && $psrRequest->getUri()->getPath() === '/shutdown') { if ($negotiatorResponse->getStatusCode() !== 101 && $psrRequest->getUri()->getPath() === '/shutdown') {
$connection->end(\GuzzleHttp\Psr7\str(new Response(200, [], 'Shutting down echo server.' . PHP_EOL))); $connection->end(Message::toString(new Response(200, [], 'Shutting down echo server.' . PHP_EOL)));
$socket->close(); $socket->close();
return; return;
}; };
$connection->write(\GuzzleHttp\Psr7\str($negotiatorResponse)); $connection->write(Message::toString($negotiatorResponse));
if ($negotiatorResponse->getStatusCode() !== 101) { if ($negotiatorResponse->getStatusCode() !== 101) {
$connection->end(); $connection->end();

View File

@ -2,6 +2,7 @@
namespace Ratchet\RFC6455\Test\Unit\Handshake; namespace Ratchet\RFC6455\Test\Unit\Handshake;
use GuzzleHttp\Psr7\Message;
use Ratchet\RFC6455\Handshake\RequestVerifier; use Ratchet\RFC6455\Handshake\RequestVerifier;
use Ratchet\RFC6455\Handshake\ServerNegotiator; use Ratchet\RFC6455\Handshake\ServerNegotiator;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -24,7 +25,7 @@ Accept-Language: en-US,en;q=0.8
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);
@ -53,7 +54,7 @@ Accept-Language: en-US,en;q=0.8
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);
@ -80,7 +81,7 @@ Accept-Language: en-US,en;q=0.8
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);
@ -107,7 +108,7 @@ Accept-Language: en-US,en;q=0.8
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);
@ -141,7 +142,7 @@ Accept-Language: en-US,en;q=0.8
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);
@ -175,7 +176,7 @@ Accept-Language: en-US,en;q=0.8
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);
@ -205,7 +206,7 @@ Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
'; ';
$request = \GuzzleHttp\Psr7\parse_request($requestText); $request = Message::parseRequest($requestText);
$response = $negotiator->handshake($request); $response = $negotiator->handshake($request);