[Net] Remove StreamPeerTLS.blocking_handshake option.
Which was unused internally, and can be replaced by: ``` while tls.get_status() == tls.STATUS_HANDSHAKING: tls.poll() ```
This commit is contained in:
parent
adba870534
commit
7cd80e6a6d
|
@ -364,7 +364,6 @@ Error HTTPClientTCP::poll() {
|
|||
if (!handshaking) {
|
||||
// Connect the StreamPeerTLS and start handshaking.
|
||||
tls_conn = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
||||
tls_conn->set_blocking_handshake_enabled(false);
|
||||
Error err = tls_conn->connect_to_stream(tcp_connection, conn_host, tls_options);
|
||||
if (err != OK) {
|
||||
close();
|
||||
|
|
|
@ -41,18 +41,8 @@ StreamPeerTLS *StreamPeerTLS::create() {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool StreamPeerTLS::available = false;
|
||||
|
||||
bool StreamPeerTLS::is_available() {
|
||||
return available;
|
||||
}
|
||||
|
||||
void StreamPeerTLS::set_blocking_handshake_enabled(bool p_enabled) {
|
||||
blocking_handshake = p_enabled;
|
||||
}
|
||||
|
||||
bool StreamPeerTLS::is_blocking_handshake_enabled() const {
|
||||
return blocking_handshake;
|
||||
return _create != nullptr;
|
||||
}
|
||||
|
||||
void StreamPeerTLS::_bind_methods() {
|
||||
|
@ -62,10 +52,6 @@ void StreamPeerTLS::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTLS::get_status);
|
||||
ClassDB::bind_method(D_METHOD("get_stream"), &StreamPeerTLS::get_stream);
|
||||
ClassDB::bind_method(D_METHOD("disconnect_from_stream"), &StreamPeerTLS::disconnect_from_stream);
|
||||
ClassDB::bind_method(D_METHOD("set_blocking_handshake_enabled", "enabled"), &StreamPeerTLS::set_blocking_handshake_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_blocking_handshake_enabled"), &StreamPeerTLS::is_blocking_handshake_enabled);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_handshake"), "set_blocking_handshake_enabled", "is_blocking_handshake_enabled");
|
||||
|
||||
BIND_ENUM_CONSTANT(STATUS_DISCONNECTED);
|
||||
BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
|
||||
|
|
|
@ -41,10 +41,6 @@ protected:
|
|||
static StreamPeerTLS *(*_create)();
|
||||
static void _bind_methods();
|
||||
|
||||
static bool available;
|
||||
|
||||
bool blocking_handshake = true;
|
||||
|
||||
public:
|
||||
enum Status {
|
||||
STATUS_DISCONNECTED,
|
||||
|
@ -54,9 +50,6 @@ public:
|
|||
STATUS_ERROR_HOSTNAME_MISMATCH
|
||||
};
|
||||
|
||||
void set_blocking_handshake_enabled(bool p_enabled);
|
||||
bool is_blocking_handshake_enabled() const;
|
||||
|
||||
virtual void poll() = 0;
|
||||
virtual Error accept_stream(Ref<StreamPeer> p_base, Ref<TLSOptions> p_options) = 0;
|
||||
virtual Error connect_to_stream(Ref<StreamPeer> p_base, const String &p_common_name, Ref<TLSOptions> p_options) = 0;
|
||||
|
|
|
@ -53,10 +53,6 @@
|
|||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="blocking_handshake" type="bool" setter="set_blocking_handshake_enabled" getter="is_blocking_handshake_enabled" default="true">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
<constant name="STATUS_DISCONNECTED" value="0" enum="Status">
|
||||
A status representing a [StreamPeerTLS] that is disconnected.
|
||||
|
|
|
@ -80,22 +80,17 @@ void StreamPeerMbedTLS::_cleanup() {
|
|||
}
|
||||
|
||||
Error StreamPeerMbedTLS::_do_handshake() {
|
||||
int ret = 0;
|
||||
while ((ret = mbedtls_ssl_handshake(tls_ctx->get_context())) != 0) {
|
||||
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||
// An error occurred.
|
||||
ERR_PRINT("TLS handshake error: " + itos(ret));
|
||||
TLSContextMbedTLS::print_mbedtls_error(ret);
|
||||
disconnect_from_stream();
|
||||
status = STATUS_ERROR;
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
// Handshake is still in progress.
|
||||
if (!blocking_handshake) {
|
||||
// Will retry via poll later
|
||||
return OK;
|
||||
}
|
||||
int ret = mbedtls_ssl_handshake(tls_ctx->get_context());
|
||||
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||
// Handshake is still in progress, will retry via poll later.
|
||||
return OK;
|
||||
} else if (ret != 0) {
|
||||
// An error occurred.
|
||||
ERR_PRINT("TLS handshake error: " + itos(ret));
|
||||
TLSContextMbedTLS::print_mbedtls_error(ret);
|
||||
disconnect_from_stream();
|
||||
status = STATUS_ERROR;
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
status = STATUS_CONNECTED;
|
||||
|
@ -306,10 +301,8 @@ StreamPeerTLS *StreamPeerMbedTLS::_create_func() {
|
|||
|
||||
void StreamPeerMbedTLS::initialize_tls() {
|
||||
_create = _create_func;
|
||||
available = true;
|
||||
}
|
||||
|
||||
void StreamPeerMbedTLS::finalize_tls() {
|
||||
available = false;
|
||||
_create = nullptr;
|
||||
}
|
||||
|
|
|
@ -333,7 +333,6 @@ void WSLPeer::_do_client_handshake() {
|
|||
// Start SSL handshake
|
||||
tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
||||
ERR_FAIL_COND_MSG(tls.is_null(), "SSL is not available in this build.");
|
||||
tls->set_blocking_handshake_enabled(false);
|
||||
if (tls->connect_to_stream(tcp, requested_host, tls_options) != OK) {
|
||||
close(-1);
|
||||
return; // Error.
|
||||
|
|
|
@ -205,7 +205,6 @@ public:
|
|||
if (tls.is_null()) {
|
||||
tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
||||
peer = tls;
|
||||
tls->set_blocking_handshake_enabled(false);
|
||||
if (tls->accept_stream(tcp, TLSOptions::server(key, cert)) != OK) {
|
||||
_clear_client();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue