Commit 1934e244 authored by David Goulet's avatar David Goulet 🐼
Browse files

Merge branch 'tor-gitlab/mr/546'

parents df662530 9f0b0afa
Loading
Loading
Loading
Loading

changes/ticket40568

0 → 100644
+3 −0
Original line number Diff line number Diff line
  o Minor features (control port):
    - Provide congestion control fields on CIRC_BW and STREAM control
      port events, for use by sbws. Closes ticket 40568.
+42 −0
Original line number Diff line number Diff line
@@ -1442,3 +1442,45 @@ congestion_control_parse_ext_response(const uint8_t *msg,

  return (int)ret;
}

/**
 * Returns a formatted string of fields containing congestion
 * control information, for the CIRC_BW control port event.
 *
 * An origin circuit can have a ccontrol object directly on it,
 * if it is an onion service, or onion client. Exit-bound clients
 * will have the ccontrol on the cpath associated with their exit
 * (the last one in the cpath list).
 *
 * WARNING: This function does not support leaky-pipe topology. It
 * is to be used for control port information only.
 */
char *
congestion_control_get_control_port_fields(const origin_circuit_t *circ)
{
  const congestion_control_t *ccontrol = NULL;
  char *ret = NULL;
  int len;

  if (TO_CIRCUIT(circ)->ccontrol) {
    ccontrol = TO_CIRCUIT(circ)->ccontrol;
  } else if (circ->cpath && circ->cpath->prev->ccontrol) {
    /* Get ccontrol for last hop (exit) if it exists */
    ccontrol = circ->cpath->prev->ccontrol;
  }

  if (!ccontrol)
    return NULL;

  len = tor_asprintf(&ret,
                     " SS=%d CWND=%"PRIu64" RTT=%"PRIu64" MIN_RTT=%"PRIu64,
                     ccontrol->in_slow_start, ccontrol->cwnd,
                     ccontrol->ewma_rtt_usec/1000,
                     ccontrol->min_rtt_usec/1000);
  if (len < 0) {
    log_warn(LD_BUG, "Unable to format event for controller.");
    return NULL;
  }

  return ret;
}
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ int congestion_control_parse_ext_response(const uint8_t *msg,
                                          const size_t msg_len,
                                          circuit_params_t *params_out);
bool congestion_control_validate_sendme_increment(uint8_t sendme_inc);
char *congestion_control_get_control_port_fields(const origin_circuit_t *);

/* Ugh, C.. these are private. Use the getter instead, when
 * external to the congestion control code. */
+29 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "core/or/trace_probes_cc.h"
#include "feature/nodelist/networkstatus.h"
#include "trunnel/flow_control_cells.h"
#include "feature/control/control_events.h"

#include "core/or/connection_st.h"
#include "core/or/cell_st.h"
@@ -147,6 +148,13 @@ circuit_send_stream_xoff(edge_connection_t *stream)
  if (connection_edge_send_command(stream, RELAY_COMMAND_XOFF,
                               (char*)payload, (size_t)xoff_size) == 0) {
    stream->xoff_sent = true;

    /* If this is an entry conn, notify control port */
    if (TO_CONN(stream)->type == CONN_TYPE_AP) {
      control_event_stream_status(TO_ENTRY_CONN(TO_CONN(stream)),
                                  STREAM_EVENT_XOFF_SENT,
                                  0);
    }
  }
}

@@ -213,6 +221,13 @@ circuit_send_stream_xon(edge_connection_t *stream)
                                   (size_t)xon_size) == 0) {
    /* Revert the xoff sent status, so we can send another one if need be */
    stream->xoff_sent = false;

    /* If it's an entry conn, notify control port */
    if (TO_CONN(stream)->type == CONN_TYPE_AP) {
      control_event_stream_status(TO_ENTRY_CONN(TO_CONN(stream)),
                                  STREAM_EVENT_XON_SENT,
                                  0);
    }
  }
}

@@ -299,6 +314,13 @@ circuit_process_stream_xoff(edge_connection_t *conn,
  connection_stop_reading(TO_CONN(conn));
  conn->xoff_received = true;

  /* If this is an entry conn, notify control port */
  if (TO_CONN(conn)->type == CONN_TYPE_AP) {
    control_event_stream_status(TO_ENTRY_CONN(TO_CONN(conn)),
                                STREAM_EVENT_XOFF_RECV,
                                0);
  }

  return retval;
}

@@ -403,6 +425,13 @@ circuit_process_stream_xon(edge_connection_t *conn,
    connection_start_reading(TO_CONN(conn));
  }

  /* If this is an entry conn, notify control port */
  if (TO_CONN(conn)->type == CONN_TYPE_AP) {
    control_event_stream_status(TO_ENTRY_CONN(TO_CONN(conn)),
                                STREAM_EVENT_XON_RECV,
                                0);
  }

  xon_cell_free(xon);

  return retval;
+14 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "core/or/origin_circuit_st.h"
#include "core/or/channel.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/control/control_events.h"

#define NOLA_BDP_OVERSHOOT    100

@@ -70,9 +71,20 @@ congestion_control_nola_process_sendme(congestion_control_t *cc,
  /* If we get a congestion event, the only thing NOLA
   * does is note this as if we exited slow-start
   * (which for NOLA just means we finished our ICW). */
  if (cc->next_cc_event == 0)
  if (cc->next_cc_event == 0) {
    if (cc->in_slow_start) {
      cc->in_slow_start = 0;

      /* We need to report that slow start has exited ASAP,
       * for sbws bandwidth measurement. */
      if (CIRCUIT_IS_ORIGIN(circ)) {
        /* We must discard const here because the event modifies fields :/ */
        control_event_circ_bandwidth_used_for_circ(
                TO_ORIGIN_CIRCUIT((circuit_t*)circ));
      }
    }
  }

  /* If we did not successfully update BDP, we must return. Otherwise,
   * NOLA can drift downwards */
  if (!congestion_control_update_circuit_estimates(cc, circ, layer_hint)) {
Loading