mirror of
https://github.com/godotengine/godot
synced 2024-09-05 06:28:34 +00:00
[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) {
|
if (!handshaking) {
|
||||||
// Connect the StreamPeerTLS and start handshaking.
|
// Connect the StreamPeerTLS and start handshaking.
|
||||||
tls_conn = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
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);
|
Error err = tls_conn->connect_to_stream(tcp_connection, conn_host, tls_options);
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -41,18 +41,8 @@ StreamPeerTLS *StreamPeerTLS::create() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamPeerTLS::available = false;
|
|
||||||
|
|
||||||
bool StreamPeerTLS::is_available() {
|
bool StreamPeerTLS::is_available() {
|
||||||
return available;
|
return _create != nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
void StreamPeerTLS::set_blocking_handshake_enabled(bool p_enabled) {
|
|
||||||
blocking_handshake = p_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StreamPeerTLS::is_blocking_handshake_enabled() const {
|
|
||||||
return blocking_handshake;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamPeerTLS::_bind_methods() {
|
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_status"), &StreamPeerTLS::get_status);
|
||||||
ClassDB::bind_method(D_METHOD("get_stream"), &StreamPeerTLS::get_stream);
|
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("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_DISCONNECTED);
|
||||||
BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
|
BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
|
||||||
|
|
|
@ -41,10 +41,6 @@ protected:
|
||||||
static StreamPeerTLS *(*_create)();
|
static StreamPeerTLS *(*_create)();
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
static bool available;
|
|
||||||
|
|
||||||
bool blocking_handshake = true;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Status {
|
enum Status {
|
||||||
STATUS_DISCONNECTED,
|
STATUS_DISCONNECTED,
|
||||||
|
@ -54,9 +50,6 @@ public:
|
||||||
STATUS_ERROR_HOSTNAME_MISMATCH
|
STATUS_ERROR_HOSTNAME_MISMATCH
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_blocking_handshake_enabled(bool p_enabled);
|
|
||||||
bool is_blocking_handshake_enabled() const;
|
|
||||||
|
|
||||||
virtual void poll() = 0;
|
virtual void poll() = 0;
|
||||||
virtual Error accept_stream(Ref<StreamPeer> p_base, Ref<TLSOptions> p_options) = 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;
|
virtual Error connect_to_stream(Ref<StreamPeer> p_base, const String &p_common_name, Ref<TLSOptions> p_options) = 0;
|
||||||
|
|
|
@ -53,10 +53,6 @@
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<members>
|
|
||||||
<member name="blocking_handshake" type="bool" setter="set_blocking_handshake_enabled" getter="is_blocking_handshake_enabled" default="true">
|
|
||||||
</member>
|
|
||||||
</members>
|
|
||||||
<constants>
|
<constants>
|
||||||
<constant name="STATUS_DISCONNECTED" value="0" enum="Status">
|
<constant name="STATUS_DISCONNECTED" value="0" enum="Status">
|
||||||
A status representing a [StreamPeerTLS] that is disconnected.
|
A status representing a [StreamPeerTLS] that is disconnected.
|
||||||
|
|
|
@ -80,22 +80,17 @@ void StreamPeerMbedTLS::_cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error StreamPeerMbedTLS::_do_handshake() {
|
Error StreamPeerMbedTLS::_do_handshake() {
|
||||||
int ret = 0;
|
int ret = mbedtls_ssl_handshake(tls_ctx->get_context());
|
||||||
while ((ret = mbedtls_ssl_handshake(tls_ctx->get_context())) != 0) {
|
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||||
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
|
// Handshake is still in progress, will retry via poll later.
|
||||||
// An error occurred.
|
return OK;
|
||||||
ERR_PRINT("TLS handshake error: " + itos(ret));
|
} else if (ret != 0) {
|
||||||
TLSContextMbedTLS::print_mbedtls_error(ret);
|
// An error occurred.
|
||||||
disconnect_from_stream();
|
ERR_PRINT("TLS handshake error: " + itos(ret));
|
||||||
status = STATUS_ERROR;
|
TLSContextMbedTLS::print_mbedtls_error(ret);
|
||||||
return FAILED;
|
disconnect_from_stream();
|
||||||
}
|
status = STATUS_ERROR;
|
||||||
|
return FAILED;
|
||||||
// Handshake is still in progress.
|
|
||||||
if (!blocking_handshake) {
|
|
||||||
// Will retry via poll later
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status = STATUS_CONNECTED;
|
status = STATUS_CONNECTED;
|
||||||
|
@ -306,10 +301,8 @@ StreamPeerTLS *StreamPeerMbedTLS::_create_func() {
|
||||||
|
|
||||||
void StreamPeerMbedTLS::initialize_tls() {
|
void StreamPeerMbedTLS::initialize_tls() {
|
||||||
_create = _create_func;
|
_create = _create_func;
|
||||||
available = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamPeerMbedTLS::finalize_tls() {
|
void StreamPeerMbedTLS::finalize_tls() {
|
||||||
available = false;
|
|
||||||
_create = nullptr;
|
_create = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,7 +333,6 @@ void WSLPeer::_do_client_handshake() {
|
||||||
// Start SSL handshake
|
// Start SSL handshake
|
||||||
tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
||||||
ERR_FAIL_COND_MSG(tls.is_null(), "SSL is not available in this build.");
|
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) {
|
if (tls->connect_to_stream(tcp, requested_host, tls_options) != OK) {
|
||||||
close(-1);
|
close(-1);
|
||||||
return; // Error.
|
return; // Error.
|
||||||
|
|
|
@ -205,7 +205,6 @@ public:
|
||||||
if (tls.is_null()) {
|
if (tls.is_null()) {
|
||||||
tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
tls = Ref<StreamPeerTLS>(StreamPeerTLS::create());
|
||||||
peer = tls;
|
peer = tls;
|
||||||
tls->set_blocking_handshake_enabled(false);
|
|
||||||
if (tls->accept_stream(tcp, TLSOptions::server(key, cert)) != OK) {
|
if (tls->accept_stream(tcp, TLSOptions::server(key, cert)) != OK) {
|
||||||
_clear_client();
|
_clear_client();
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue