Ticket #5915: tor-optimistic-data.patch

File tor-optimistic-data.patch, 3.0 KB (added by cypherpunks, 15 months ago)

Optimistic Data patch for Tor.0.3.5.x

  • src/core/or/connection_edge.c

    a b connection_ap_handshake_process_socks(en 
    26782678  } /* else socks handshake is done, continue processing */
    26792679
    26802680  if (SOCKS_COMMAND_IS_CONNECT(socks->command))
     2681  {
     2682    connection_ap_handshake_socks_reply(conn, NULL, 0, 0);
    26812683    control_event_stream_status(conn, STREAM_EVENT_NEW, 0);
     2684  }
    26822685  else
    26832686    control_event_stream_status(conn, STREAM_EVENT_NEW_RESOLVE, 0);
    26842687
  • src/core/or/relay.c

    a b edge_reason_is_retriable(int reason) 
    722722         reason == END_STREAM_REASON_MISC ||
    723723         reason == END_STREAM_REASON_NOROUTE;
    724724}
     725/** Displays an error message to an HTTP client
     726 */
    725727
     728void display_error_message(edge_connection_t *conn, int reason) {
     729        char myreply[1024];
     730        size_t myreplylen;
     731        // conn->socks_request->has_finished = 0;
     732        strlcpy(myreply,
     733                "HTTP/1.0 501 Connection ended\r\n"
     734                "Content-Type: text/html; charset=iso-8859-1\r\n\r\n"
     735                "<html>\n"
     736                "<head>\n"
     737                "<title>Connection ended</title>\n"
     738                "</head>\n"
     739                "<body>\n"
     740                "<h1>Tor has terminated the connection</h1>\n"
     741                "<p>\n"
     742                "The connection has been terminated by Tor."
     743                "\n"
     744                "Reason given: ", 1024);
     745       
     746        const char *reasonstr = stream_end_reason_to_string(reason);
     747        strlcat(myreply, reasonstr, 1024);
     748       
     749        strlcat(myreply,
     750                "</p>\n"
     751                "<p>\n"
     752                "See <a href=\"https://www.torproject.org/documentation.html\">"
     753                           "https://www.torproject.org/documentation.html</a> for more "
     754                           "information.\n"
     755                "<!-- Plus this comment, to make the body response more than 512 bytes, so "
     756                "     IE will be willing to display it. Comment comment comment comment "
     757                "     comment comment comment comment comment comment comment comment.-->\n"
     758                "</p>\n"
     759                "</body>\n"
     760                "</html>\n"
     761                , 1024);
     762        myreplylen = strlen(myreply)+1;
     763       
     764        connection_ap_handshake_socks_reply(conn, myreply, myreplylen, 1);
     765}
    726766/** Called when we receive an END cell on a stream that isn't open yet,
    727767 * from the client side.
    728768 * Arguments are as for connection_edge_process_relay_cell().
    connection_ap_process_end_not_open( 
    887927            return 0;
    888928          /* else, conn will get closed below */
    889929        } else {
     930          if (conn->socks_request->port == 80){
     931                display_error_message(conn, reason);
     932                conn->socks_request->has_finished = 0;
     933          }
    890934          log_notice(LD_APP,
    891935                     "Have tried resolving or connecting to address '%s' "
    892936                     "at %d different places. Giving up.",