Page MenuHomePhabricator

net: extend Sock with methods for robust send & read until terminator
ClosedPublic

Authored by PiRK on Feb 9 2022, 09:02.

Details

Summary

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

Test Plan

With clang-tidy
ninja && ninja-check

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Feb 9 2022, 09:02

Where is the test for this ?

PiRK edited the summary of this revision. (Show Details)
PiRK edited the test plan for this revision. (Show Details)

squash with core#21407 to incluede a unit test and a a limit on the amount of data Sock::RecvUntilTerminator() can read
Summary updated.

This revision is now accepted and ready to land.Feb 10 2022, 09:06