Skip to content

Commit 6e55ab5

Browse files
committed
partial bitcoin#26312: Remove Sock::Get() and Sock::Sock()
excludes: - 7829272 - 5086a99 - 7df4508
1 parent 859da12 commit 6e55ab5

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

src/i2p.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,13 @@ Session::Session(const fs::path& private_key_file,
119119
: m_private_key_file{private_key_file},
120120
m_control_host{control_host},
121121
m_interrupt{interrupt},
122-
m_control_sock{std::make_unique<Sock>(INVALID_SOCKET)},
123122
m_transient{false}
124123
{
125124
}
126125

127126
Session::Session(const CService& control_host, CThreadInterrupt* interrupt)
128127
: m_control_host{control_host},
129128
m_interrupt{interrupt},
130-
m_control_sock{std::make_unique<Sock>(INVALID_SOCKET)},
131129
m_transient{true}
132130
{
133131
}
@@ -346,7 +344,7 @@ void Session::CheckControlSock()
346344
LOCK(m_mutex);
347345

348346
std::string errmsg;
349-
if (!m_control_sock->IsConnected(errmsg)) {
347+
if (m_control_sock && !m_control_sock->IsConnected(errmsg)) {
350348
LogPrintLevel(BCLog::I2P, BCLog::Level::Debug, "Control socket error: %s\n", errmsg);
351349
Disconnect();
352350
}
@@ -395,7 +393,7 @@ Binary Session::MyDestination() const
395393
void Session::CreateIfNotCreatedAlready()
396394
{
397395
std::string errmsg;
398-
if (m_control_sock->IsConnected(errmsg)) {
396+
if (m_control_sock && m_control_sock->IsConnected(errmsg)) {
399397
return;
400398
}
401399

@@ -468,14 +466,14 @@ std::unique_ptr<Sock> Session::StreamAccept()
468466

469467
void Session::Disconnect()
470468
{
471-
if (m_control_sock->Get() != INVALID_SOCKET) {
469+
if (m_control_sock) {
472470
if (m_session_id.empty()) {
473471
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "Destroying incomplete SAM session\n");
474472
} else {
475473
LogPrintLevel(BCLog::I2P, BCLog::Level::Info, "Destroying SAM session %s\n", m_session_id);
476474
}
475+
m_control_sock.reset();
477476
}
478-
m_control_sock = std::make_unique<Sock>(INVALID_SOCKET);
479477
m_session_id.clear();
480478
}
481479
} // namespace sam

src/i2p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class Session
253253
* ("SESSION CREATE"). With the established session id we later open
254254
* other connections to the SAM service to accept incoming I2P
255255
* connections and make outgoing ones.
256+
* If not connected then this unique_ptr will be empty.
256257
* See https://geti2p.net/en/docs/api/samv3
257258
*/
258259
std::unique_ptr<Sock> m_control_sock GUARDED_BY(m_mutex);

src/net.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,10 @@ static CAddress GetBindAddress(const Sock& sock)
415415
CAddress addr_bind;
416416
struct sockaddr_storage sockaddr_bind;
417417
socklen_t sockaddr_bind_len = sizeof(sockaddr_bind);
418-
if (sock.Get() != INVALID_SOCKET) {
419-
if (!sock.GetSockName((struct sockaddr*)&sockaddr_bind, &sockaddr_bind_len)) {
420-
addr_bind.SetSockAddr((const struct sockaddr*)&sockaddr_bind);
421-
} else {
422-
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "getsockname failed\n");
423-
}
418+
if (!sock.GetSockName((struct sockaddr*)&sockaddr_bind, &sockaddr_bind_len)) {
419+
addr_bind.SetSockAddr((const struct sockaddr*)&sockaddr_bind);
420+
} else {
421+
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "getsockname failed\n");
424422
}
425423
return addr_bind;
426424
}

src/netbase.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,6 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
534534
// Create a sockaddr from the specified service.
535535
struct sockaddr_storage sockaddr;
536536
socklen_t len = sizeof(sockaddr);
537-
if (sock.Get() == INVALID_SOCKET) {
538-
LogPrintf("Cannot connect to %s: invalid socket\n", addrConnect.ToStringAddrPort());
539-
return false;
540-
}
541537
if (!addrConnect.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
542538
LogPrintf("Cannot connect to %s: unsupported network\n", addrConnect.ToStringAddrPort());
543539
return false;

0 commit comments

Comments
 (0)