e04eddb3 this conditional with 2 nested ternary conditionals on one line is pretty hard to read.
0- 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)) {
1+ bool fast_rekey = gArgs.GetBoolArg("-netencryptionfastrekey", false);
2+ if (m_bytes_encrypted >= (fast_rekey ? 32 * 1024 : REKEY_LIMIT_BYTES) || (now - m_time_last_rekey >= (fast_rekey ? 10 : REKEY_LIMIT_TIME))) {
or
0- 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)) {
1+ if (gArgs.GetBoolArg("-netencryptionfastrekey", false)) {
2+ if (m_bytes_encrypted >= 32 * 1024 || (now - m_time_last_rekey >= 10)) {
3+ rekey = true;
4+ }
5+ } else {
6+ if (m_bytes_encrypted >= REKEY_LIMIT_BYTES || (now - m_time_last_rekey >= REKEY_LIMIT_TIME)) {
7+ rekey = true;
8+ }
9+ }
10+ if (rekey) {
11 LogPrint(BCLog::NET, "Rekey limits reached, performing rekey.\n");
12 msg.data[2] |= (1u << 7);
13- rekey = true;
14 }
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
.