From 025cc04d9e8ec12cea749b6831fb8bc5c78894e2 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 4 Oct 2019 12:58:06 +0200 Subject: Re-implement WebSocket get host/port. Was lost during library switch --- modules/websocket/wsl_server.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/websocket/wsl_server.cpp') diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index efb526eed1..dbf153bd4a 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -185,6 +185,7 @@ void WSLServer::poll() { WSLPeer::PeerData *data = memnew(struct WSLPeer::PeerData); data->obj = this; data->conn = ppeer->connection; + data->tcp = ppeer->tcp; data->is_server = true; data->id = id; @@ -204,12 +205,13 @@ void WSLServer::poll() { return; while (_server->is_connection_available()) { - Ref conn = _server->take_connection(); + Ref conn = _server->take_connection(); if (is_refusing_new_connections()) continue; // Conn will go out-of-scope and be closed. Ref peer = memnew(PendingPeer); peer->connection = conn; + peer->tcp = conn; peer->time = OS::get_singleton()->get_ticks_msec(); _pending.push_back(peer); } -- cgit v1.2.3 From c723a8b6aa2e32f0c8b213303610a35d08b01e34 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 7 Oct 2019 16:35:56 +0200 Subject: Implement WebSocketServer SSL support. --- modules/websocket/wsl_server.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'modules/websocket/wsl_server.cpp') diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index dbf153bd4a..e3101d99d7 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -35,6 +35,7 @@ #include "core/project_settings.h" WSLServer::PendingPeer::PendingPeer() { + use_ssl = false; time = 0; has_request = false; response_sent = 0; @@ -100,6 +101,16 @@ bool WSLServer::PendingPeer::_parse_request(const PoolStringArray p_protocols) { Error WSLServer::PendingPeer::do_handshake(PoolStringArray p_protocols) { if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) return ERR_TIMEOUT; + if (use_ssl) { + Ref ssl = static_cast >(connection); + if (ssl.is_null()) + return FAILED; + ssl->poll(); + if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) + return ERR_BUSY; + else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) + return FAILED; + } if (!has_request) { int read = 0; while (true) { @@ -210,7 +221,15 @@ void WSLServer::poll() { continue; // Conn will go out-of-scope and be closed. Ref peer = memnew(PendingPeer); - peer->connection = conn; + if (private_key.is_valid() && ssl_cert.is_valid()) { + Ref ssl = Ref(StreamPeerSSL::create()); + ssl->set_blocking_handshake_enabled(false); + ssl->accept_stream(conn, private_key, ssl_cert, ca_chain); + peer->connection = ssl; + peer->use_ssl = true; + } else { + peer->connection = conn; + } peer->tcp = conn; peer->time = OS::get_singleton()->get_ticks_msec(); _pending.push_back(peer); -- cgit v1.2.3 From 67a4c3033bd4c5e6f61b5ff77709f60512392ab0 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 8 Oct 2019 20:13:24 +0200 Subject: Custom headers support in WebSocketClient. This commit also converts all PoolVector parameters to `const Vector` in both WebSocketServer and WebSocketClient. --- modules/websocket/wsl_server.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules/websocket/wsl_server.cpp') diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index e3101d99d7..993dceafb9 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -43,7 +43,7 @@ WSLServer::PendingPeer::PendingPeer() { memset(req_buf, 0, sizeof(req_buf)); } -bool WSLServer::PendingPeer::_parse_request(const PoolStringArray p_protocols) { +bool WSLServer::PendingPeer::_parse_request(const Vector p_protocols) { Vector psa = String((char *)req_buf).split("\r\n"); int len = psa.size(); ERR_FAIL_COND_V_MSG(len < 4, false, "Not enough response headers, got: " + itos(len) + ", expected >= 4."); @@ -98,7 +98,7 @@ bool WSLServer::PendingPeer::_parse_request(const PoolStringArray p_protocols) { return true; } -Error WSLServer::PendingPeer::do_handshake(PoolStringArray p_protocols) { +Error WSLServer::PendingPeer::do_handshake(const Vector p_protocols) { if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) return ERR_TIMEOUT; if (use_ssl) { @@ -154,11 +154,11 @@ Error WSLServer::PendingPeer::do_handshake(PoolStringArray p_protocols) { return OK; } -Error WSLServer::listen(int p_port, PoolVector p_protocols, bool gd_mp_api) { +Error WSLServer::listen(int p_port, const Vector p_protocols, bool gd_mp_api) { ERR_FAIL_COND_V(is_listening(), ERR_ALREADY_IN_USE); _is_multiplayer = gd_mp_api; - _protocols = p_protocols; + _protocols.append_array(p_protocols); _server->listen(p_port); return OK; @@ -252,6 +252,7 @@ void WSLServer::stop() { } _pending.clear(); _peer_map.clear(); + _protocols.clear(); } bool WSLServer::has_peer(int p_id) const { -- cgit v1.2.3