upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/selftest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/selftest.cpp')
-rw-r--r--src/selftest.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/selftest.cpp b/src/selftest.cpp
index cca5335..eed6779 100644
--- a/src/selftest.cpp
+++ b/src/selftest.cpp
@@ -1109,6 +1109,13 @@ static int RunNetMessageSelfTest()
1109 int nFail = 0; 1109 int nFail = 0;
1110 try 1110 try
1111 { 1111 {
1112 // A peer that has not yet been kept waiting must not look like one that
1113 // has been waiting since the epoch. This is the whole bug: the stall
1114 // clock lives in CNode, so only the constructor can start it at zero.
1115 CNode opened(INVALID_SOCKET, CAddress("127.0.0.1"));
1116 nFail += Check(opened.nMsgWaitSince == 0 && opened.nMsgWaitSize == 0,
1117 "a new peer starts with its stall clock stopped") ? 0 : 1;
1118
1112 CNode complete(INVALID_SOCKET, CAddress("127.0.0.1")); 1119 CNode complete(INVALID_SOCKET, CAddress("127.0.0.1"));
1113 complete.nVersion = VERSION; 1120 complete.nVersion = VERSION;
1114 complete.vRecv << CMessageHeader("ping", 0); 1121 complete.vRecv << CMessageHeader("ping", 0);
@@ -1123,20 +1130,38 @@ static int RunNetMessageSelfTest()
1123 nFail += Check(ProcessMessages(&partial), "an incomplete message returns cleanly") ? 0 : 1; 1130 nFail += Check(ProcessMessages(&partial), "an incomplete message returns cleanly") ? 0 : 1;
1124 nFail += Check(partial.vRecv.size() == nPartialBefore, 1131 nFail += Check(partial.vRecv.size() == nPartialBefore,
1125 "an incomplete message keeps one header in the buffer") ? 0 : 1; 1132 "an incomplete message keeps one header in the buffer") ? 0 : 1;
1126 nFail += Check(partial.nIncompleteMessageStart != 0, 1133 nFail += Check(partial.nMsgWaitSince != 0,
1127 "an incomplete message starts a timeout clock") ? 0 : 1; 1134 "an incomplete message starts the stall clock") ? 0 : 1;
1135 nFail += Check(partial.nMsgWaitSize == 0,
1136 "the stall clock records how much payload had arrived") ? 0 : 1;
1128 nFail += Check(!partial.fDisconnect, 1137 nFail += Check(!partial.fDisconnect,
1129 "a fresh incomplete message does not disconnect immediately") ? 0 : 1; 1138 "a fresh incomplete message does not disconnect immediately") ? 0 : 1;
1130 1139
1140 // Still arriving, just slowly: more payload is here than when the clock
1141 // was started, so the clock restarts however old it was. Timing the
1142 // wait instead of the stall would drop this peer.
1143 CNode slow(INVALID_SOCKET, CAddress("127.0.0.1"));
1144 slow.nVersion = VERSION;
1145 slow.vRecv << CMessageHeader("block", 100);
1146 slow.vRecv.insert(slow.vRecv.end(), 50, '\0');
1147 slow.nMsgWaitSince = GetTime() - BTF_MSG_WAIT_MAX_SECS - 1;
1148 slow.nMsgWaitSize = 10;
1149 ProcessMessages(&slow);
1150 nFail += Check(!slow.fDisconnect,
1151 "a peer still sending payload is not dropped") ? 0 : 1;
1152 nFail += Check(slow.nMsgWaitSize == 50,
1153 "progress restarts the stall clock") ? 0 : 1;
1154
1155 // Nothing more has arrived since the clock started, and the clock is
1156 // older than the limit.
1131 CNode stale(INVALID_SOCKET, CAddress("127.0.0.1")); 1157 CNode stale(INVALID_SOCKET, CAddress("127.0.0.1"));
1132 stale.nVersion = VERSION; 1158 stale.nVersion = VERSION;
1133 stale.vRecv << CMessageHeader("block", 100); 1159 stale.vRecv << CMessageHeader("block", 100);
1134 stale.nIncompleteMessageStart = GetTime() - BTF_INCOMPLETE_MESSAGE_TIMEOUT_SECS - 1; 1160 stale.nMsgWaitSince = GetTime() - BTF_MSG_WAIT_MAX_SECS - 1;
1135 stale.nIncompleteMessageSize = 100; 1161 stale.nMsgWaitSize = 0;
1136 stale.strIncompleteMessageCommand = "block";
1137 ProcessMessages(&stale); 1162 ProcessMessages(&stale);
1138 nFail += Check(stale.fDisconnect, 1163 nFail += Check(stale.fDisconnect,
1139 "a stale incomplete message disconnects the peer") ? 0 : 1; 1164 "a stalled incomplete message disconnects the peer") ? 0 : 1;
1140 1165
1141 CNode oversized(INVALID_SOCKET, CAddress("127.0.0.1")); 1166 CNode oversized(INVALID_SOCKET, CAddress("127.0.0.1"));
1142 oversized.nVersion = VERSION; 1167 oversized.nVersion = VERSION;