@@ -268,9 +268,22 @@ class Transport {
268
268
virtual bool ReceivedMessageComplete () const = 0;
269
269
/* * Set the deserialization context version for objects returned by GetReceivedMessage. */
270
270
virtual void SetReceiveVersion (int version) = 0;
271
- /* * Feed wire bytes to the transport; chops off consumed bytes off front of msg_bytes. */
272
- virtual int ReceivedBytes (Span<const uint8_t >& msg_bytes) = 0;
273
- /* * Retrieve a completed message from transport (only when ReceivedMessageComplete). */
271
+
272
+ /* * Feed wire bytes to the transport.
273
+ *
274
+ * @return false if some bytes were invalid, in which case the transport can't be used anymore.
275
+ *
276
+ * Consumed bytes are chopped off the front of msg_bytes.
277
+ */
278
+ virtual bool ReceivedBytes (Span<const uint8_t >& msg_bytes) = 0;
279
+
280
+ /* * Retrieve a completed message from transport.
281
+ *
282
+ * This can only be called when ReceivedMessageComplete() is true.
283
+ *
284
+ * If reject_message=true is returned the message itself is invalid, but (other than false
285
+ * returned by ReceivedBytes) the transport is not in an inconsistent state.
286
+ */
274
287
virtual CNetMessage GetReceivedMessage (std::chrono::microseconds time, bool & reject_message) = 0;
275
288
276
289
// 2. Sending side functions, for converting messages into bytes to be sent over the wire.
@@ -387,7 +400,7 @@ class V1Transport final : public Transport
387
400
vRecv.SetVersion (nVersionIn);
388
401
}
389
402
390
- int ReceivedBytes (Span<const uint8_t >& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
403
+ bool ReceivedBytes (Span<const uint8_t >& msg_bytes) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex)
391
404
{
392
405
AssertLockNotHeld (m_recv_mutex);
393
406
LOCK (m_recv_mutex);
@@ -397,7 +410,7 @@ class V1Transport final : public Transport
397
410
} else {
398
411
msg_bytes = msg_bytes.subspan (ret);
399
412
}
400
- return ret;
413
+ return ret >= 0 ;
401
414
}
402
415
403
416
CNetMessage GetReceivedMessage (std::chrono::microseconds time, bool & reject_message) override EXCLUSIVE_LOCKS_REQUIRED(!m_recv_mutex);
0 commit comments