You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

coding.txt 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Please be consistent with the existing coding style.
  2. Block style:
  3. bool Function(char* psz, int n)
  4. {
  5. // Comment summarising what this section of code does
  6. for (int i = 0; i < n; i++)
  7. {
  8. // When something fails, return early
  9. if (!Something())
  10. return false;
  11. ...
  12. }
  13. // Success return is usually at the end
  14. return true;
  15. }
  16. - ANSI/Allman block style
  17. - 4 space indenting, no tabs
  18. - No extra spaces inside parenthesis; please don't do ( this )
  19. - No space after function names, one space after if, for and while
  20. Variable names begin with the type in lowercase, like nSomeVariable.
  21. Please don't put the first word of the variable name in lowercase like
  22. someVariable.
  23. Common types:
  24. n integer number: short, unsigned short, int, unsigned int,
  25. int64, uint64, sometimes char if used as a number
  26. d double, float
  27. f flag
  28. hash uint256
  29. p pointer or array, one p for each level of indirection
  30. psz pointer to null terminated string
  31. str string object
  32. v vector or similar list objects
  33. map map or multimap
  34. set set or multiset
  35. bn CBigNum
  36. -------------------------
  37. Locking/mutex usage notes
  38. The code is multi-threaded, and uses mutexes and the
  39. CRITICAL_BLOCK/TRY_CRITICAL_BLOCK macros to protect data structures.
  40. Deadlocks due to inconsistent lock ordering (thread 1 locks cs_main
  41. and then cs_wallet, while thread 2 locks them in the opposite order:
  42. result, deadlock as each waits for the other to release its lock) are
  43. a problem. Compile with -DDEBUG_LOCKORDER to get lock order
  44. inconsistencies reported in the debug.log file.
  45. Re-architecting the core code so there are better-defined interfaces
  46. between the various components is a goal, with any necessary locking
  47. done by the components (e.g. see the self-contained CKeyStore class
  48. and its cs_KeyStore lock for example).
  49. -------
  50. Threads
  51. StartNode : Starts other threads.
  52. ThreadGetMyExternalIP : Determines outside-the-firewall IP address,
  53. sends addr message to connected peers when it determines it.
  54. ThreadIRCSeed : Joins IRC bootstrapping channel, watching for new
  55. peers and advertising this node's IP address.
  56. ThreadSocketHandler : Sends/Receives data from peers on port 8333.
  57. ThreadMessageHandler : Higher-level message handling (sending and
  58. receiving).
  59. ThreadOpenConnections : Initiates new connections to peers.
  60. ThreadTopUpKeyPool : replenishes the keystore's keypool.
  61. ThreadCleanWalletPassphrase : re-locks an encrypted wallet after user
  62. has unlocked it for a period of time.
  63. SendingDialogStartTransfer : used by pay-via-ip-address code (obsolete)
  64. ThreadDelayedRepaint : repaint the gui
  65. ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used
  66. in 500ms.
  67. ThreadRPCServer : Remote procedure call handler, listens on port 8332
  68. for connections and services them.
  69. ThreadBitcoinMiner : Generates bitcoins
  70. ThreadMapPort : Universal plug-and-play startup/shutdown
  71. Shutdown : Does an orderly shutdown of everything
  72. ExitTimeout : Windows-only, sleeps 5 seconds then exits application