i2p: use pointers to Sock to accommodate mocking

Change the types of `i2p::Connection::sock` and
`i2p::sam::Session::m_control_sock` from `Sock` to
`std::unique_ptr<Sock>`.

Using pointers would allow us to sneak `FuzzedSock` instead of `Sock`
and have the methods of the former called.

After this change a test only needs to replace `CreateSock()` with
a function that returns `FuzzedSock`.
This commit is contained in:
Vasil Dimov
2021-03-04 14:31:49 +01:00
parent 82d360b5a8
commit 9947e44de0
3 changed files with 30 additions and 26 deletions

View File

@@ -432,7 +432,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
i2p::Connection conn;
if (m_i2p_sam_session->Connect(addrConnect, conn, proxyConnectionFailed)) {
connected = true;
sock = std::make_unique<Sock>(std::move(conn.sock));
sock = std::move(conn.sock);
addr_bind = CAddress{conn.me, NODE_NONE};
}
} else if (GetProxy(addrConnect.GetNetwork(), proxy)) {
@@ -2221,7 +2221,7 @@ void CConnman::ThreadI2PAcceptIncoming()
continue;
}
CreateNodeFromAcceptedSocket(conn.sock.Release(), NetPermissionFlags::PF_NONE,
CreateNodeFromAcceptedSocket(conn.sock->Release(), NetPermissionFlags::PF_NONE,
CAddress{conn.me, NODE_NONE}, CAddress{conn.peer, NODE_NONE});
}
}