aboutsummaryrefslogtreecommitdiff
path: root/src/util/sock.h
AgeCommit message (Collapse)Author
2021-04-13net: flag relevant Sock methods with [[nodiscard]]Vasil Dimov
2021-04-06doc: fixup -Wdocumentation issuesfanquake
2021-03-16net: add connect() and getsockopt() wrappers to SockVasil Dimov
Extend the `Sock` class with wrappers to `connect()` and `getsockopt()`. This will make it possible to mock code which uses those.
2021-03-16fuzz: implement unimplemented FuzzedSock methodsVasil Dimov
We want `Get()` to always return the same value, otherwise it will look like the `FuzzedSock` implementation itself is broken. So assign `m_socket` a random number in the `FuzzedSock` constructor. There is nothing to fuzz about the `Get()` and `Release()` methods, so use the ones from the base class `Sock`. `Reset()` is just setting our socket to `INVALID_SOCKET`. We don't want to use the base `Reset()` because it will close `m_socket` and given that our `m_socket` is just a random number it may end up closing a real opened file descriptor if it coincides with our random `m_socket`.
2021-03-16i2p: limit the size of incoming messagesVasil Dimov
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.
2021-03-01net: extend Sock with a method to check whether connectedVasil Dimov
This will be convenient in the I2P SAM implementation.
2021-03-01net: extend Sock with methods for robust send & read until terminatorVasil Dimov
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.
2021-03-01net: extend Sock::Wait() to report a timeoutVasil Dimov
Previously `Sock::Wait()` would not have signaled to the caller whether a timeout or one of the requested events occurred since that was not needed by any of the callers. Such functionality will be needed in the I2P implementation, thus extend the `Sock::Wait()` method.
2021-03-01net: move the constant maxWait out of InterruptibleRecv()Vasil Dimov
Move `maxWait` out of `InterruptibleRecv()` and rename it to `MAX_WAIT_FOR_IO` so that it can be reused by other code.
2021-02-10net: add RAII socket and use it instead of bare SOCKETVasil Dimov
Introduce a class to manage the lifetime of a socket - when the object that contains the socket goes out of scope, the underlying socket will be closed. In addition, the new `Sock` class has a `Send()`, `Recv()` and `Wait()` methods that can be overridden by unit tests to mock the socket operations. The `Wait()` method also hides the `#ifdef USE_POLL poll() #else select() #endif` technique from higher level code.
2021-02-10net: move CloseSocket() from netbase to util/sockVasil Dimov
Move `CloseSocket()` (and `NetworkErrorString()` which it uses) from `netbase.{h,cpp}` to newly added `src/util/sock.{h,cpp}`. This is necessary in order to use `CloseSocket()` from a newly introduced Sock class (which will live in `src/util/sock.{h,cpp}`). `sock.{h,cpp}` cannot depend on netbase because netbase will depend on it.