Introduce two high level, convenience methods in the Sock class:
- SendComplete(): keep trying to send the specified data until either successfully sent all of it, timeout or interrupted.
- RecvUntilTerminator(): read until a terminator is encountered (never after it), timeout or interrupted.
These will be convenient in the I2P SAM implementation.
SendComplete() can also be used in the SOCKS5 implementation instead of calling send() directly.
i2p: limit the size of incoming messages
Put a limit on the amount of data Sock::RecvUntilTerminator() can read
if no terminator is received.In the case of I2P this avoids a runaway (or malicious) I2P proxy
sending us tons of data without a terminator before a timeout is
triggered.
test: add a test to ensure RecvUntilTerminator() limit works
This is a backport of core#20685 [12/20] and core#21407 (partial)
https://github.com/bitcoin/bitcoin/pull/20685/commits/42c779f503eb8437b6232773a4a2472306cc9f3d
https://github.com/bitcoin/bitcoin/pull/21407/commits/80a5a8ea2b7ad512c74c29df5b504e9be6cf23a0
https://github.com/bitcoin/bitcoin/pull/21407/commits/7059e6d82275b44efc41675ee10760145b6c1073
Note: the backport of core#21047 is missing the changes to i2p.{cpp|h} that will be included in a following commit.
Depends on D11022