Skip to content

Commit

Permalink
Avoid extra reconnect when connecting to server with TLS disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed Feb 23, 2021
1 parent f450566 commit 32a94f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/server/common/server_base.cpp
Expand Up @@ -160,7 +160,11 @@ void server_base::serve(boost::asio::yield_context yield, boost::asio::ip::tcp::
}

async_write(*socket, boost::asio::buffer(handshake_response.buf, 4), yield[error]);
if(check_error(error, socket) || !tls_enabled_) return;
if(check_error(error, socket)) return;
if(!tls_enabled_) { // continue with unencrypted connection if TLS disabled
final_socket = socket;
break;
}

final_socket = tls_socket_ptr { new tls_socket_ptr::element_type(std::move(*socket), tls_context_) };
utils::get<tls_socket_ptr>(final_socket)->async_handshake(boost::asio::ssl::stream_base::server, yield[error]);
Expand Down
3 changes: 2 additions & 1 deletion src/wesnothd_connection.cpp
Expand Up @@ -175,7 +175,8 @@ void wesnothd_connection::handle_handshake(const error_code& ec)

if(use_tls_) {
if(handshake_response_.num == 0xFFFFFFFFU) {
fallback_to_unencrypted();
use_tls_ = false;
handle_handshake(ec);
return;
}

Expand Down

0 comments on commit 32a94f4

Please sign in to comment.