HACKING 3.9 KB

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