Skip to content

Commit 8c1e54c

Browse files
authored
Fix #4
Retry requests that fail TLS handshake by emitting RESOLVING event immediately after TLS_HANDSHAKING, such as those to gmnisrv server.
1 parent 283a78d commit 8c1e54c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Core/Client.vala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,32 @@ public class Starfish.Core.Client : Object {
8888
int redirect_count = 0,
8989
bool follow_redirects = true,
9090
bool accept_mismatched_cert = false,
91-
bool should_use_cleint_cert = false
91+
bool should_use_cleint_cert = false,
92+
int tls_retry_count = 0
9293
) {
9394
SocketConnection conn;
9495
CertError? cert_error = null;
9596
CertInfo? cert_info = null;
9697
CertInfo? client_cert_info = null;
98+
bool is_retryable_tls_issue = false;
9799
try {
98100
var socket_client = new SocketClient () {
99101
tls = true,
100102
tls_validation_flags = TlsCertificateFlags.VALIDATE_ALL,
101103
timeout = 100000000
102104
};
105+
SocketClientEvent? previous_event = null;
103106
socket_client.event.connect ((event, connectable, conn) => {
107+
if (previous_event == SocketClientEvent.TLS_HANDSHAKING
108+
&& event == SocketClientEvent.RESOLVING
109+
&& tls_retry_count < 3
110+
) {
111+
warning ("Detected issue in TLS handshake, will attempt to retry it.");
112+
is_retryable_tls_issue = true;
113+
} else {
114+
previous_event = event;
115+
}
116+
104117
if (event == SocketClientEvent.TLS_HANDSHAKING) {
105118
var tls_conn = (TlsClientConnection) conn;
106119
if (should_use_cleint_cert) {
@@ -139,6 +152,9 @@ public class Starfish.Core.Client : Object {
139152
var request = (uri.to_string () + "\r\n").data;
140153
yield conn.output_stream.write_async (request, Priority.DEFAULT, cancel);
141154
} catch (Error err) {
155+
if (is_retryable_tls_issue) {
156+
return yield load_gemini (uri, cancel, redirect_count, follow_redirects, accept_mismatched_cert, should_use_cleint_cert, tls_retry_count + 1);
157+
}
142158
if (cert_error != null) {
143159
if (cert_error is CertError.PARSING_ERROR || cert_error is CertError.FINGERPRINTING_ERROR) {
144160
return new InternalErrorResponse.server_certificate_invalid (cert_info, uri, cert_error.message);

0 commit comments

Comments
 (0)