Commit 0039c79b authored by kelsey's avatar kelsey
Browse files

Implement transport reconnect support and follow changes in discovery API and...

Implement transport reconnect support and follow changes in discovery API and libtlmsp-cfg code structure
parent 6654553a
Loading
Loading
Loading
Loading
+27 −15
Original line number Diff line number Diff line
@@ -3472,6 +3472,7 @@ static CURLcode create_conn(struct Curl_easy *data,
  char *first_hop_host;
  char *first_hop_port_str;
  int first_hop_addr_type;
  size_t first_hop_addr_len;
  int remote_port;
  int i;
  const struct tlmsp_cfg_context *context;
@@ -3761,12 +3762,6 @@ static CURLcode create_conn(struct Curl_easy *data,
      result = CURLE_URL_MALFORMAT;
      goto out;
    }
    else if(data->state.lastconnect &&
        data->state.lastconnect->tlmsp_reconnect_state) {
      conn->tlmsp_reconnect_state =
          data->state.lastconnect->tlmsp_reconnect_state;
      data->state.lastconnect->tlmsp_reconnect_state = NULL;
    }
    else {
      /* TLMSP enabled for this connection */
      conn->tlmsp_cfg = tlmsp_cfg;
@@ -3777,6 +3772,21 @@ static CURLcode create_conn(struct Curl_easy *data,
          conn->tlmsp_context_id_for_dc[i] = context->id;
      }

      if(data->state.transport_reconnect_state) {
        conn->tlmsp_reconnect_state = data->state.transport_reconnect_state;
        data->state.transport_reconnect_state = NULL;

        if(!TLMSP_get_first_hop_address_reconnect_ex(
                conn->tlmsp_reconnect_state, &first_hop_addr_type,
                (uint8_t **)&first_hop_addr, &first_hop_addr_len, 1)) {
          free(cfg_host);
          free(cfg_port_str);
          failf(data,
              "SSL: couldn't determine TLMSP reconnect first hop address");
          result = CURLE_OUT_OF_MEMORY;
          goto out;
        }
      } else {
        first_hop_addr = tlmsp_cfg_get_client_first_hop_address(tlmsp_cfg, false,
            true, &first_hop_addr_type);
        if(!first_hop_addr) {
@@ -3786,9 +3796,11 @@ static CURLcode create_conn(struct Curl_easy *data,
          result = CURLE_OUT_OF_MEMORY;
          goto out;
        }
        first_hop_addr_len = strlen(first_hop_addr);
      }

      if(!tlmsp_util_address_to_host_and_port(first_hop_addr_type,
              (const uint8_t *)first_hop_addr, strlen(first_hop_addr), 0,
              (const uint8_t *)first_hop_addr, first_hop_addr_len, 0,
              &first_hop_host, &first_hop_port_str)) {
        free(first_hop_addr);
        free(cfg_host);
+3 −0
Original line number Diff line number Diff line
@@ -1296,6 +1296,9 @@ struct UrlState {

  struct connectdata *lastconnect; /* The last connection, NULL if undefined */

  const void *transport_reconnect_state; /* transport state to use in the event
                                            of CURLE_TRANSPORT_RECONNECT */

  char *headerbuff; /* allocated buffer to store headers in */
  size_t headersize;   /* size of the allocation */

+5 −7
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@

#ifdef USE_TLMSP
#include <openssl/tlmsp.h>
#include <tlmsp-tools/libtlmsp-cfg-openssl.h>
#include <tlmsp-tools/libtlmsp-util.h>
#endif

@@ -2340,18 +2341,15 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid)

#ifdef USE_TLMSP
static int tlmsp_validate_discovery_results(SSL *ssl,
                                            void *arg)
                                            void *arg,
                                            TLMSP_Middleboxes *middleboxes)
{
  struct connectdata *conn = arg;
  TLMSP_Middleboxes *middleboxes;
  const struct tlmsp_cfg *cfg = conn->tlmsp_cfg;
  int result;

  middleboxes = TLMSP_get_middleboxes_instance(ssl);
  if(middleboxes == NULL)
    return (0);
  (void)ssl;
  result = tlmsp_cfg_validate_middlebox_list_client_openssl(cfg, middleboxes);
  TLMSP_middleboxes_free(middleboxes);
  return (result);
}
#endif
@@ -2988,7 +2986,7 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
#ifdef USE_TLMSP
    if(SSL_ERROR_WANT_RECONNECT == detail) {
      connssl->connecting_state = ssl_connect_2;
      conn->tlmsp_reconnect_state = TLMSP_get_reconnect_state(BACKEND->handle);
      data->state.transport_reconnect_state = TLMSP_get_reconnect_state(BACKEND->handle);
      return CURLE_TRANSPORT_RECONNECT;
    }
#endif
+15 −6
Original line number Diff line number Diff line
@@ -1624,16 +1624,19 @@ static CURLcode operate_do(struct GlobalConfig *global,

          /* if retry-max-time is non-zero, make sure we haven't exceeded the
             time */
          if(retry_numretries &&
          if((CURLE_TRANSPORT_RECONNECT == result) ||
             (retry_numretries &&
              (!config->retry_maxtime ||
               (tvdiff(tvnow(), retrystart) <
               config->retry_maxtime*1000L)) ) {
                config->retry_maxtime*1000L))) ) {
            printf("retry\n");
            enum {
              RETRY_NO,
              RETRY_TIMEOUT,
              RETRY_CONNREFUSED,
              RETRY_HTTP,
              RETRY_FTP,
              RETRY_TRANSPORT_RECONNECT,
              RETRY_LAST /* not used */
            } retry = RETRY_NO;
            long response;
@@ -1679,6 +1682,11 @@ static CURLcode operate_do(struct GlobalConfig *global,
                  break;
                }
              }
            }
            else if (CURLE_TRANSPORT_RECONNECT == result) {
              retry = RETRY_TRANSPORT_RECONNECT;
              retry_numretries++; /* don't count this against the retry limit */
              retry_sleep = 0;
            } /* if CURLE_OK */
            else if(result) {
              long protocol;
@@ -1702,10 +1710,11 @@ static CURLcode operate_do(struct GlobalConfig *global,
                "timeout",
                "connection refused",
                "HTTP error",
                "FTP error"
                "FTP error",
                "transport reconnect required"
              };

              warnf(config->global, "Transient problem: %s "
              warnf(config->global, "Transient problem: %s. "
                    "Will retry in %ld seconds. "
                    "%ld retries left.\n",
                    m[retry], retry_sleep/1000L, retry_numretries);