minor touchups
[tor.git] / doc / HACKING
blob524f17da8b4002134783a183e3c17088c5e87c69
2 0. The buildbot.
4   http://tor-buildbot.freehaven.net:8010/
6 0.1. Useful command-lines that are non-trivial to reproduce but can
7 help with tracking bugs or leaks.
9 dmalloc -l ~/dmalloc.log
10 (run the commands it tells you)
11 ./configure --with-dmalloc
13 valgrind --leak-check=yes --error-limit=no --show-reachable=yes src/or/tor
15 1. Coding conventions
17 1.0. Whitespace and C conformance
19   Invoke "make check-spaces" from time to time, so it can tell you about
20   deviations from our C whitespace style.  Generally, we use:
21     - Unix-style line endings
22     - K&R-style indentation
23     - No space before newlines
24     - A blank line at the end of each file
25     - Never more than one blank line in a row
26     - Always spaces, never tabs
27     - No more than 79-columns per line.
28     - Two spaces per indent.
29     - A space between control keywords and their corresponding paren
30       "if (x)", "while (x)", and "switch (x)", never "if(x)", "while(x)", or
31       "switch(x)".
32     - A space between anything and an open brace.
33     - No space between a function name and an opening paren. "puts(x)", not
34       "puts (x)".
35     - Function declarations at the start of the line.
37   We try hard to build without warnings everywhere.  In particular, if you're
38   using gcc, you should invoke the configure script with the option
39   "--enable-gcc-warnings".  This will give a bunch of extra warning flags to
40   the compiler, and help us find divergences from our preferred C style.
42 1.1. Details
44   Use tor_malloc, tor_free, tor_strdup, and tor_gettimeofday instead of their
45   generic equivalents.  (They always succeed or exit.)
47   You can get a full list of the compatibility functions that Tor provides
48   by looking through src/common/util.h and src/common/compat.h.
50   Use 'INLINE' instead of 'inline', so that we work properly on Windows.
52 1.2. Calling and naming conventions
54   Whenever possible, functions should return -1 on error and 0 on success.
56   For multi-word identifiers, use lowercase words combined with
57   underscores. (e.g., "multi_word_identifier").  Use ALL_CAPS for macros and
58   constants.
60   Typenames should end with "_t".
62   Function names should be prefixed with a module name or object name.  (In
63   general, code to manipulate an object should be a module with the same
64   name as the object, so it's hard to tell which convention is used.)
66   Functions that do things should have imperative-verb names
67   (e.g. buffer_clear, buffer_resize); functions that return booleans should
68   have predicate names (e.g. buffer_is_empty, buffer_needs_resizing).
70 1.3. What To Optimize
72   Don't optimize anything if it's not in the critical path.  Right now,
73   the critical path seems to be AES, logging, and the network itself.
74   Feel free to do your own profiling to determine otherwise.
76 1.4. Log conventions
78   http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#LogLevels
80   No error or warning messages should be expected during normal OR or OP
81   operation.
83   If a library function is currently called such that failure always
84   means ERR, then the library function should log WARN and let the caller
85   log ERR.
87   [XXX Proposed convention: every message of severity INFO or higher should
88   either (A) be intelligible to end-users who don't know the Tor source; or
89   (B) somehow inform the end-users that they aren't expected to understand
90   the message (perhaps with a string like "internal error").  Option (A) is
91   to be preferred to option (B). -NM]
93 1.5. Doxygen
95   We use the 'doxygen' utility to generate documentation from our
96   source code. Here's how to use it:
98   1. Begin every file that should be documented with
99          /**
100           * \file filename.c
101           * \brief Short desccription of the file.
102           **/
104      (Doxygen will recognize any comment beginning with /** as special.)
106   2. Before any function, structure, #define, or variable you want to
107      document, add a comment of the form:
109         /** Describe the function's actions in imperative sentences.
110          *
111          * Use blank lines for paragraph breaks
112          *   - and
113          *   - hyphens
114          *   - for
115          *   - lists.
116          *
117          * Write <b>argument_names</b> in boldface.
118          *
119          * \code
120          *     place_example_code();
121          *     between_code_and_endcode_commands();
122          * \endcode
123          */
125   3. Make sure to escape the characters "<", ">", "\", "%" and "#" as "\<",
126      "\>", "\\", "\%", and "\#".
128   4. To document structure members, you can use two forms:
130        struct foo {
131          /** You can put the comment before an element; */
132          int a;
133          int b; /**< Or use the less-than symbol to put the comment
134                  * after the element. */
135        };
137   5. To generate documentation from the Tor source code, type:
139      $ doxygen -g
141      To generate a file called 'Doxyfile'.  Edit that file and run
142      'doxygen' to generate the API documentation.
144   6. See the Doxygen manual for more information; this summary just
145      scratches the surface.