aboutsummaryrefslogtreecommitdiff
path: root/src/i2p.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-03-04 14:31:49 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-03-16 13:59:18 +0100
commit9947e44de0cbd79e99d883443a9ac441d8c69713 (patch)
tree8d60e4c979aa3fe1cf383e108a4b35b42df63614 /src/i2p.h
parent82d360b5a88d9057b6c09b61cd69e426c7a2412d (diff)
downloadbitcoin-9947e44de0cbd79e99d883443a9ac441d8c69713.tar.xz
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`.
Diffstat (limited to 'src/i2p.h')
-rw-r--r--src/i2p.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/i2p.h b/src/i2p.h
index 1ebe7d0329..cb2efedba8 100644
--- a/src/i2p.h
+++ b/src/i2p.h
@@ -12,6 +12,7 @@
#include <threadinterrupt.h>
#include <util/sock.h>
+#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
@@ -29,7 +30,7 @@ using Binary = std::vector<uint8_t>;
*/
struct Connection {
/** Connected socket. */
- Sock sock;
+ std::unique_ptr<Sock> sock;
/** Our I2P address. */
CService me;
@@ -166,7 +167,7 @@ private:
* @return a connected socket
* @throws std::runtime_error if an error occurs
*/
- Sock Hello() const EXCLUSIVE_LOCKS_REQUIRED(m_mutex);
+ std::unique_ptr<Sock> Hello() const EXCLUSIVE_LOCKS_REQUIRED(m_mutex);
/**
* Check the control socket for errors and possibly disconnect.
@@ -204,10 +205,11 @@ private:
/**
* Open a new connection to the SAM proxy and issue "STREAM ACCEPT" request using the existing
- * session id. Return the idle socket that is waiting for a peer to connect to us.
+ * session id.
+ * @return the idle socket that is waiting for a peer to connect to us
* @throws std::runtime_error if an error occurs
*/
- Sock StreamAccept() EXCLUSIVE_LOCKS_REQUIRED(m_mutex);
+ std::unique_ptr<Sock> StreamAccept() EXCLUSIVE_LOCKS_REQUIRED(m_mutex);
/**
* Destroy the session, closing the internally used sockets.
@@ -248,7 +250,7 @@ private:
* connections and make outgoing ones.
* See https://geti2p.net/en/docs/api/samv3
*/
- Sock m_control_sock GUARDED_BY(m_mutex);
+ std::unique_ptr<Sock> m_control_sock GUARDED_BY(m_mutex);
/**
* Our .b32.i2p address.