Skip to content

Commit

Permalink
Added methods to check if connection is using TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed Mar 20, 2021
1 parent 4489c09 commit 4221b19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/network_asio.hpp
Expand Up @@ -102,6 +102,14 @@ class connection
return done_;
}

/** True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens */
bool using_tls() const
{
// Calling this function before connection is ready may return wrong result
assert(done_);
return utils::holds_alternative<tls_socket>(socket_);
}

std::size_t bytes_to_write() const
{
return bytes_to_write_;
Expand Down
6 changes: 6 additions & 0 deletions src/wesnothd_connection.hpp
Expand Up @@ -98,6 +98,12 @@ class wesnothd_connection
/** Waits until the server handshake is complete. */
void wait_for_handshake();

/** True if connection is currently using TLS and thus is allowed to send cleartext passwords or auth tokens */
bool using_tls() const
{
return utils::holds_alternative<tls_socket>(socket_);
}

void cancel();

void stop();
Expand Down

0 comments on commit 4221b19

Please sign in to comment.