diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-05-25 15:01:53 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2023-08-24 14:39:58 +0200 |
commit | 5ac1a51ee5a57da59f1ff1986b7d9054484d3c80 (patch) | |
tree | 47b75876e80bac44948dc92698d850a867fd50da /src/i2p.cpp | |
parent | 083316c4fe20819fbe627c5d21f1a627e10af329 (diff) | |
download | bitcoin-5ac1a51ee5a57da59f1ff1986b7d9054484d3c80.tar.xz |
i2p: avoid using Sock::Get() for checking for a valid socket
Peeking at the underlying socket file descriptor of `Sock` and checkig
if it is `INVALID_SOCKET` is bad encapsulation and stands in the way of
testing/mocking/fuzzing.
Instead use an empty unique_ptr to denote that there is no valid socket.
Diffstat (limited to 'src/i2p.cpp')
-rw-r--r-- | src/i2p.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/i2p.cpp b/src/i2p.cpp index f03e375adf..5a3dde54ce 100644 --- a/src/i2p.cpp +++ b/src/i2p.cpp @@ -119,7 +119,6 @@ Session::Session(const fs::path& private_key_file, : m_private_key_file{private_key_file}, m_control_host{control_host}, m_interrupt{interrupt}, - m_control_sock{std::make_unique<Sock>(INVALID_SOCKET)}, m_transient{false} { } @@ -127,7 +126,6 @@ Session::Session(const fs::path& private_key_file, Session::Session(const CService& control_host, CThreadInterrupt* interrupt) : m_control_host{control_host}, m_interrupt{interrupt}, - m_control_sock{std::make_unique<Sock>(INVALID_SOCKET)}, m_transient{true} { } @@ -315,7 +313,7 @@ void Session::CheckControlSock() LOCK(m_mutex); std::string errmsg; - if (!m_control_sock->IsConnected(errmsg)) { + if (m_control_sock && !m_control_sock->IsConnected(errmsg)) { Log("Control socket error: %s", errmsg); Disconnect(); } @@ -364,7 +362,7 @@ Binary Session::MyDestination() const void Session::CreateIfNotCreatedAlready() { std::string errmsg; - if (m_control_sock->IsConnected(errmsg)) { + if (m_control_sock && m_control_sock->IsConnected(errmsg)) { return; } @@ -437,14 +435,14 @@ std::unique_ptr<Sock> Session::StreamAccept() void Session::Disconnect() { - if (m_control_sock->Get() != INVALID_SOCKET) { + if (m_control_sock) { if (m_session_id.empty()) { Log("Destroying incomplete SAM session"); } else { Log("Destroying SAM session %s", m_session_id); } + m_control_sock.reset(); } - m_control_sock = std::make_unique<Sock>(INVALID_SOCKET); m_session_id.clear(); } } // namespace sam |