Changeset View
Changeset View
Standalone View
Standalone View
doc/developer-notes.md
Show First 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | |||||
- ThreadOpenAddedConnections : Opens network connections to added nodes. | - ThreadOpenAddedConnections : Opens network connections to added nodes. | ||||
- ThreadOpenConnections : Initiates new connections to peers. | - ThreadOpenConnections : Initiates new connections to peers. | ||||
- ThreadMessageHandler : Higher-level message handling (sending and receiving). | - ThreadMessageHandler : Higher-level message handling (sending and receiving). | ||||
- DumpAddresses : Dumps IP addresses of nodes to peers.dat. | - DumpAddresses : Dumps IP addresses of nodes to peers.dat. | ||||
- ThreadFlushWalletDB : Close the wallet.dat file if it hasn't been used in 500ms. | |||||
- ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them. | - ThreadRPCServer : Remote procedure call handler, listens on port 8332 for connections and services them. | ||||
- BitcoinMiner : Generates bitcoins (if wallet is enabled). | |||||
- Shutdown : Does an orderly shutdown of everything. | - Shutdown : Does an orderly shutdown of everything. | ||||
Ignoring IDE/editor files | Ignoring IDE/editor files | ||||
-------------------------- | -------------------------- | ||||
In closed-source environments in which everyone uses the same IDE it is common | In closed-source environments in which everyone uses the same IDE it is common | ||||
to add temporary files it produces to the project-wide `.gitignore` file. | to add temporary files it produces to the project-wide `.gitignore` file. | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | - Use explicitly signed or unsigned `char`s, or even better `uint8_t` and | ||||
lead to interoperability problems or dangerous conditions such as | lead to interoperability problems or dangerous conditions such as | ||||
out-of-bounds array accesses | out-of-bounds array accesses | ||||
- Prefer explicit constructions over implicit ones that rely on 'magical' C++ behavior | - Prefer explicit constructions over implicit ones that rely on 'magical' C++ behavior | ||||
- *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those | - *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those | ||||
that are not language lawyers | that are not language lawyers | ||||
- Initialize all non-static class members where they are defined | |||||
- *Rationale*: Initializing the members in the declaration makes it easy to spot uninitialized ones, | |||||
and avoids accidentally reading uninitialized memory | |||||
```cpp | |||||
class A | |||||
{ | |||||
uint32_t m_count{0}; | |||||
} | |||||
``` | |||||
Strings and formatting | Strings and formatting | ||||
------------------------ | ------------------------ | ||||
- Use `std::string`, avoid C string manipulation functions | - Use `std::string`, avoid C string manipulation functions | ||||
- *Rationale*: C++ string handling is marginally safer, less scope for | - *Rationale*: C++ string handling is marginally safer, less scope for | ||||
buffer overflows and surprises with `\0` characters. Also some C string manipulations | buffer overflows and surprises with `\0` characters. Also some C string manipulations | ||||
tend to act differently depending on platform, or even the user locale | tend to act differently depending on platform, or even the user locale | ||||
- Use `ParseInt32`, `ParseInt64`, `ParseUInt32`, `ParseUInt64`, `ParseDouble` from `utilstrencodings.h` for number parsing | - Use `ParseInt32`, `ParseInt64`, `ParseUInt32`, `ParseUInt64`, `ParseDouble` from `utilstrencodings.h` for number parsing | ||||
- *Rationale*: These functions do overflow checking, and avoid pesky locale issues | - *Rationale*: These functions do overflow checking, and avoid pesky locale issues | ||||
Variable names | Variable names | ||||
-------------- | -------------- | ||||
The shadowing warning (`-Wshadow`) is enabled by default. It prevents issues rising | The shadowing warning (`-Wshadow`) is enabled by default. It prevents issues rising | ||||
from using a different variable with the same name. | from using a different variable with the same name. | ||||
E.g. in member initializers, prepend `_` to the argument name shadowing the | |||||
member name: | |||||
```c++ | |||||
class AddressBookPage | |||||
{ | |||||
Mode m_mode; | |||||
} | |||||
AddressBookPage::AddressBookPage(Mode _mode) : | |||||
m_mode(_mode) | |||||
... | |||||
``` | |||||
When using nested cycles, do not name the inner cycle variable the same as in | |||||
upper cycle etc. | |||||
Please name variables so that their names do not shadow variables defined in the source code. | Please name variables so that their names do not shadow variables defined in the source code. | ||||
Threads and synchronization | Threads and synchronization | ||||
---------------------------- | ---------------------------- | ||||
- Build and run tests with `-DDEBUG_LOCKORDER` to verify that no potential | - Build and run tests with `-DDEBUG_LOCKORDER` to verify that no potential | ||||
deadlocks are introduced. As of 0.12, this is defined by default when | deadlocks are introduced. As of 0.12, this is defined by default when | ||||
configuring with `--enable-debug` | configuring with `--enable-debug` | ||||
▲ Show 20 Lines • Show All 257 Lines • Show Last 20 Lines |