4 http://tor-buildbot.freehaven.net:8010/
8 1.0. Whitespace and C conformance
10 Invoke "make check-spaces" from time to time, so it can tell you about
11 deviations from our C whitespace style. Generally, we use:
12 - Unix-style line endings
13 - K&R-style indentation
14 - No space before newlines
15 - A blank line at the end of each file
16 - Never more than one blank line in a row
17 - Always spaces, never tabs
18 - A space between control keywords and their corresponding paren
19 "if (x)", "while (x)", and "switch (x)", never "if(x)", "while(x)", or
21 - A space between anything and an open brace.
22 - No space between a function name and an opening paren. "puts(x)", not
24 - Function declarations at the start of the line.
26 We try hard to build without warnings everywhere. In particular, if you're
27 using gcc, you should invoke the configure script with the option
28 "--enable-gcc-warnings". This will give a bunch of extra warning flags to
29 the compiler, and help us find divergences from our preferred C style.
33 Use tor_malloc, tor_free, tor_strdup, and tor_gettimeofday instead of their
34 generic equivalents. (They always succeed or exit.)
36 You can get a full list of the compatibility functions that Tor provides
37 by looking through src/common/util.h and src/common/compat.h.
39 Use 'INLINE' instead of 'inline', so that we work properly on Windows.
41 1.2. Calling and naming conventions
43 Whenever possible, functions should return -1 on error and 0 on success.
45 For multi-word identifiers, use lowercase words combined with
46 underscores. (e.g., "multi_word_identifier"). Use ALL_CAPS for macros and
49 Typenames should end with "_t".
51 Function names should be prefixed with a module name or object name. (In
52 general, code to manipulate an object should be a module with the same
53 name as the object, so it's hard to tell which convention is used.)
55 Functions that do things should have imperative-verb names
56 (e.g. buffer_clear, buffer_resize); functions that return booleans should
57 have predicate names (e.g. buffer_is_empty, buffer_needs_resizing).
61 Don't optimize anything if it's not in the critical path. Right now,
62 the critical path seems to be AES, logging, and the network itself.
63 Feel free to do your own profiling to determine otherwise.
67 http://wiki.noreply.org/noreply/TheOnionRouter/TorFAQ#LogLevels
69 No error or warning messages should be expected during normal OR or OP
72 If a library function is currently called such that failure always
73 means ERR, then the library function should log WARN and let the caller
76 [XXX Proposed convention: every message of severity INFO or higher should
77 either (A) be intelligible to end-users who don't know the Tor source; or
78 (B) somehow inform the end-users that they aren't expected to understand
79 the message (perhaps with a string like "internal error"). Option (A) is
80 to be preferred to option (B). -NM]
84 We use the 'doxygen' utility to generate documentation from our
85 source code. Here's how to use it:
87 1. Begin every file that should be documented with
90 * \brief Short desccription of the file.
93 (Doxygen will recognize any comment beginning with /** as special.)
95 2. Before any function, structure, #define, or variable you want to
96 document, add a comment of the form:
98 /** Describe the function's actions in imperative sentences.
100 * Use blank lines for paragraph breaks
106 * Write <b>argument_names</b> in boldface.
109 * place_example_code();
110 * between_code_and_endcode_commands();
114 3. Make sure to escape the characters "<", ">", "\", "%" and "#" as "\<",
115 "\>", "\\", "\%", and "\#".
117 4. To document structure members, you can use two forms:
120 /** You can put the comment before an element; */
122 int b; /**< Or use the less-than symbol to put the comment
123 * after the element. */
126 5. To generate documentation from the Tor source code, type:
130 To generate a file called 'Doxyfile'. Edit that file and run
131 'doxygen' to generate the API documentation.
133 6. See the Doxygen manual for more information; this summary just
134 scratches the surface.