e04eddb3 this conditional with 2 nested ternary conditionals on one line is pretty hard to read.
<details>
<summary>Here are two ideas.</summary>
<p>
- if (m_bytes_encrypted >= (gArgs.GetBoolArg("-netencryptionfastrekey", false) ? 32 * 1024 : REKEY_LIMIT_BYTES) || now - m_time_last_rekey >= (gArgs.GetBoolArg("-netencryptionfastrekey", false) ? 10 : REKEY_LIMIT_TIME)) {
+ bool fast_rekey = gArgs.GetBoolArg("-netencryptionfastrekey", false);
+ if (m_bytes_encrypted >= (fast_rekey ? 32 * 1024 : REKEY_LIMIT_BYTES) || (now - m_time_last_rekey >= (fast_rekey ? 10 : REKEY_LIMIT_TIME))) {
or
- if (m_bytes_encrypted >= (gArgs.GetBoolArg("-netencryptionfastrekey", false) ? 32 * 1024 : REKEY_LIMIT_BYTES) || now - m_time_last_rekey >= (gArgs.GetBoolArg("-netencryptionfastrekey", false) ? 10 : REKEY_LIMIT_TIME)) {
+ if (gArgs.GetBoolArg("-netencryptionfastrekey", false)) {
+ if (m_bytes_encrypted >= 32 * 1024 || (now - m_time_last_rekey >= 10)) {
+ rekey = true;
+ }
+ } else {
+ if (m_bytes_encrypted >= REKEY_LIMIT_BYTES || (now - m_time_last_rekey >= REKEY_LIMIT_TIME)) {
+ rekey = true;
+ }
+ }
+ if (rekey) {
LogPrint(BCLog::NET, "Rekey limits reached, performing rekey.\n");
msg.data[2] |= (1u << 7);
- rekey = true;
}
</p>
</details>
Also, it would be nice to replace the various magic values with static constexprs that communicate meaning, like you are already doing in this commit for the rekey values in net.h.