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