HACKING 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 0. The buildbot.
  2. http://tor-buildbot.freehaven.net:8010/
  3. 1. Coding conventions
  4. 1.1. Details
  5. Use tor_malloc, tor_free, tor_snprintf, tor_strdup, and tor_gettimeofday
  6. instead of their generic equivalents. (They always succeed or exit.)
  7. You can get a full list of the compatibility functions that Tor provides
  8. by looking through src/common/util.h and src/common/compat.h.
  9. Use 'INLINE' instead of 'inline', so that we work properly on Windows.
  10. 1.2. Calling and naming conventions
  11. Whenever possible, functions should return -1 on error and 0 on success.
  12. For multi-word identifiers, use lowercase words combined with
  13. underscores. (e.g., "multi_word_identifier"). Use ALL_CAPS for macros and
  14. constants.
  15. Typenames should end with "_t".
  16. Function names should be prefixed with a module name or object name. (In
  17. general, code to manipulate an object should be a module with the same
  18. name as the object, so it's hard to tell which convention is used.)
  19. Functions that do things should have imperative-verb names
  20. (e.g. buffer_clear, buffer_resize); functions that return booleans should
  21. have predicate names (e.g. buffer_is_empty, buffer_needs_resizing).
  22. 1.3. What To Optimize
  23. Don't optimize anything if it's not in the critical path. Right now,
  24. the critical path seems to be AES, logging, and the network itself.
  25. Feel free to do your own profiling to determine otherwise.
  26. 1.4. Log conventions
  27. http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#LogLevels
  28. No error or warning messages should be expected during normal OR or OP
  29. operation.
  30. If a library function is currently called such that failure always
  31. means ERR, then the library function should log WARN and let the caller
  32. log ERR.
  33. [XXX Proposed convention: every message of severity INFO or higher should
  34. either (A) be intelligible to end-users who don't know the Tor source; or
  35. (B) somehow inform the end-users that they aren't expected to understand
  36. the message (perhaps with a string like "internal error"). Option (A) is
  37. to be preferred to option (B). -NM]
  38. 1.5. Doxygen
  39. We use the 'doxygen' utility to generate documentation from our
  40. source code. Here's how to use it:
  41. 1. Begin every file that should be documented with
  42. /**
  43. * \file filename.c
  44. * \brief Short desccription of the file.
  45. **/
  46. (Doxygen will recognize any comment beginning with /** as special.)
  47. 2. Before any function, structure, #define, or variable you want to
  48. document, add a comment of the form:
  49. /** Describe the function's actions in imperative sentences.
  50. *
  51. * Use blank lines for paragraph breaks
  52. * - and
  53. * - hyphens
  54. * - for
  55. * - lists.
  56. *
  57. * Write <b>argument_names</b> in boldface.
  58. *
  59. * \code
  60. * place_example_code();
  61. * between_code_and_endcode_commands();
  62. * \endcode
  63. */
  64. 3. Make sure to escape the characters "<", ">", "\", "%" and "#" as "\<",
  65. "\>", "\\", "\%", and "\#".
  66. 4. To document structure members, you can use two forms:
  67. struct foo {
  68. /** You can put the comment before an element; */
  69. int a;
  70. int b; /**< Or use the less-than symbol to put the comment
  71. * after the element. */
  72. };
  73. 5. To generate documentation from the Tor source code, type:
  74. $ doxygen -g
  75. To generate a file called 'Doxyfile'. Edit that file and run
  76. 'doxygen' to generate the API documentation.
  77. 6. See the Doxygen manual for more information; this summary just
  78. scratches the surface.