diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2020-09-17 07:54:00 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-09-17 15:37:21 +0200 |
commit | 4c954973273624f80d92cf6190ea064bac41bdb9 (patch) | |
tree | e928cf5042a57cb05706730d2dba29d938cca99e | |
parent | d29ad2b57f2ae139f246ae8afa81a26fed996a91 (diff) |
wsd: allow pings from clients
Per the rfc (https://tools.ietf.org/html/rfc6455#section-5.5.2):
"An endpoint MAY send a Ping frame any time after the connection
is established and before the connection is closed."
And "Upon receipt of a Ping frame, an endpoint MUST send a Pong
frame in response, unless it already received a Close frame."
Here we allow for pings to come from clients and we respond
to them by pongs, as required by rfc 6455.
Change-Id: I8e285f095526e4b67373ecb3ae1efc9c8717d756
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/102948
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | net/WebSocketHandler.hpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index 7fb38c86d..7a9ec902c 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -287,33 +287,25 @@ public: switch (code) { case WSOpCode::Pong: - if (_isClient) - { - LOG_ERR('#' << socket->getFD() << ": Servers should not send pongs, only clients"); - shutdown(StatusCodes::POLICY_VIOLATION); - return true; - } - else { + if (_isClient) + LOG_WRN('#' << socket->getFD() << ": Servers should not send pongs, only clients"); + _pingTimeUs = std::chrono::duration_cast<std::chrono::microseconds> (std::chrono::steady_clock::now() - _lastPingSentTime).count(); LOG_TRC('#' << socket->getFD() << ": Pong received: " << _pingTimeUs << " microseconds"); } break; case WSOpCode::Ping: - if (_isClient) { - auto now = std::chrono::steady_clock::now(); + if (!_isClient) + LOG_ERR('#' << socket->getFD() << ": Clients should not send pings, only servers"); + + const auto now = std::chrono::steady_clock::now(); _pingTimeUs = std::chrono::duration_cast<std::chrono::microseconds> (now - _lastPingSentTime).count(); sendPong(now, &ctrlPayload[0], payloadLen, socket); } - else - { - LOG_ERR('#' << socket->getFD() << ": Clients should not send pings, only servers"); - shutdown(StatusCodes::POLICY_VIOLATION); - return true; - } break; case WSOpCode::Close: { |