circuitmux.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* * Copyright (c) 2012, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file circuitmux.c
  5. * \brief Circuit mux/cell selection abstraction
  6. **/
  7. #include "or.h"
  8. #include "circuitmux.h"
  9. /*
  10. * A circuitmux is a collection of circuits; it tracks which subset
  11. * of the attached circuits are 'active' (i.e., have cells available
  12. * to transmit) and how many cells on each. It expoes three distinct
  13. * interfaces to other components:
  14. *
  15. * To channels, which each have a circuitmux_t, the supported operations
  16. * are:
  17. *
  18. * circuitmux_flush_cells():
  19. *
  20. * Retrieve a cell from one of the active circuits, chosen according to
  21. * the circuitmux_t's cell selection policy.
  22. *
  23. * circuitmux_unlink_all():
  24. *
  25. * The channel is closing down, all circuits must be detached.
  26. *
  27. * To circuits, the exposed operations are:
  28. *
  29. * TODO
  30. *
  31. * To circuit selection policies, the exposed operations are:
  32. *
  33. * TODO
  34. *
  35. * General status inquiries?
  36. *
  37. */
  38. struct circuitmux_s {
  39. /*
  40. * Double-linked ring of circuits with queued cells waiting for room to
  41. * free up on this connection's outbuf. Every time we pull cells from
  42. * a circuit, we advance this pointer to the next circuit in the ring.
  43. */
  44. struct circuit_t *active_circuits;
  45. /*
  46. * Priority queue of cell_ewma_t for circuits with queued cells waiting
  47. * for room to free up on this connection's outbuf. Kept in heap order
  48. * according to EWMA.
  49. *
  50. * This is redundant with active_circuits; if we ever decide only to use
  51. * the cell_ewma algorithm for choosing circuits, we can remove
  52. * active_circuits.
  53. */
  54. smartlist_t *active_circuit_pqueue;
  55. /*
  56. * The tick on which the cell_ewma_ts in active_circuit_pqueue last had
  57. * their ewma values rescaled.
  58. */
  59. unsigned active_circuit_pqueue_last_recalibrated;
  60. };