Ticket #3875: tor-optimistic-data.patch

File tor-optimistic-data.patch, 2.6 KB (added by t55wang, 7 years ago)

Optimistic Data patch for Tor.

  • src/or/connection_edge.c

    Implements optimistic data on the Tor client. 
    
    diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
    index 63a3213..d8515f4 100644
    a b connection_ap_handshake_process_socks(entry_connection_t *conn) 
    23422342  } /* else socks handshake is done, continue processing */
    23432343
    23442344  if (SOCKS_COMMAND_IS_CONNECT(socks->command))
     2345{
     2346    connection_ap_handshake_socks_reply(conn, NULL, 0, 0);
    23452347    control_event_stream_status(conn, STREAM_EVENT_NEW, 0);
     2348}
    23462349  else
    23472350    control_event_stream_status(conn, STREAM_EVENT_NEW_RESOLVE, 0);
    23482351
  • src/or/relay.c

    diff --git a/src/or/relay.c b/src/or/relay.c
    index e22ce47..05b765a 100644
    a b edge_reason_is_retriable(int reason) 
    699699         reason == END_STREAM_REASON_NOROUTE;
    700700}
    701701
     702/** Displays an error message to an HTTP client
     703 */
     704
     705void display_error_message(edge_connection_t *conn, int reason) {
     706        char myreply[1024];
     707        size_t myreplylen;
     708        conn->socks_request->has_finished = 0;
     709        strlcpy(myreply,
     710                "HTTP/1.0 501 Connection ended\r\n"
     711                "Content-Type: text/html; charset=iso-8859-1\r\n\r\n"
     712                "<html>\n"
     713                "<head>\n"
     714                "<title>Connection ended</title>\n"
     715                "</head>\n"
     716                "<body>\n"
     717                "<h1>Tor has terminated the connection</h1>\n"
     718                "<p>\n"
     719                "The connection has been terminated by Tor."
     720                "\n"
     721                "Reason given: ", 1024);
     722       
     723        const char *reasonstr = stream_end_reason_to_string(reason);
     724        strlcat(myreply, reasonstr, 1024);
     725       
     726        strlcat(myreply,
     727                "</p>\n"
     728                "<p>\n"
     729                "See <a href=\"https://www.torproject.org/documentation.html\">"
     730                           "https://www.torproject.org/documentation.html</a> for more "
     731                           "information.\n"
     732                "<!-- Plus this comment, to make the body response more than 512 bytes, so "
     733                "     IE will be willing to display it. Comment comment comment comment "
     734                "     comment comment comment comment comment comment comment comment.-->\n"
     735                "</p>\n"
     736                "</body>\n"
     737                "</html>\n"
     738                , 1024);
     739        myreplylen = strlen(myreply)+1;
     740       
     741        connection_ap_handshake_socks_reply(conn, myreply, myreplylen, 1);
     742}
     743
    702744/** Called when we receive an END cell on a stream that isn't open yet,
    703745 * from the client side.
    704746 * Arguments are as for connection_edge_process_relay_cell().
    connection_ap_process_end_not_open( 
    812854            return 0;
    813855          /* else, conn will get closed below */
    814856        } else {
     857          if (conn->socks_request->port == 80)
     858                display_error_message(conn, reason);
    815859          log_notice(LD_APP,
    816860                     "Have tried resolving or connecting to address '%s' "
    817861                     "at %d different places. Giving up.",