mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
i2p: construct Session with Proxy instead of CService
This commit is contained in:
parent
d9318a37ec
commit
a88bf9dedd
4 changed files with 22 additions and 14 deletions
10
src/i2p.cpp
10
src/i2p.cpp
|
@ -115,7 +115,7 @@ static CNetAddr DestB64ToAddr(const std::string& dest)
|
||||||
namespace sam {
|
namespace sam {
|
||||||
|
|
||||||
Session::Session(const fs::path& private_key_file,
|
Session::Session(const fs::path& private_key_file,
|
||||||
const CService& control_host,
|
const Proxy& control_host,
|
||||||
CThreadInterrupt* interrupt)
|
CThreadInterrupt* interrupt)
|
||||||
: m_private_key_file{private_key_file},
|
: m_private_key_file{private_key_file},
|
||||||
m_control_host{control_host},
|
m_control_host{control_host},
|
||||||
|
@ -124,7 +124,7 @@ Session::Session(const fs::path& private_key_file,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::Session(const CService& control_host, CThreadInterrupt* interrupt)
|
Session::Session(const Proxy& control_host, CThreadInterrupt* interrupt)
|
||||||
: m_control_host{control_host},
|
: m_control_host{control_host},
|
||||||
m_interrupt{interrupt},
|
m_interrupt{interrupt},
|
||||||
m_transient{true}
|
m_transient{true}
|
||||||
|
@ -326,10 +326,10 @@ Session::Reply Session::SendRequestAndGetReply(const Sock& sock,
|
||||||
|
|
||||||
std::unique_ptr<Sock> Session::Hello() const
|
std::unique_ptr<Sock> Session::Hello() const
|
||||||
{
|
{
|
||||||
auto sock = ConnectDirectly(m_control_host, true);
|
auto sock = m_control_host.Connect();
|
||||||
|
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
throw std::runtime_error(strprintf("Cannot connect to %s", m_control_host.ToStringAddrPort()));
|
throw std::runtime_error(strprintf("Cannot connect to %s", m_control_host.ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
SendRequestAndGetReply(*sock, "HELLO VERSION MIN=3.1 MAX=3.1");
|
SendRequestAndGetReply(*sock, "HELLO VERSION MIN=3.1 MAX=3.1");
|
||||||
|
@ -413,7 +413,7 @@ void Session::CreateIfNotCreatedAlready()
|
||||||
const auto session_type = m_transient ? "transient" : "persistent";
|
const auto session_type = m_transient ? "transient" : "persistent";
|
||||||
const auto session_id = GetRandHash().GetHex().substr(0, 10); // full is overkill, too verbose in the logs
|
const auto session_id = GetRandHash().GetHex().substr(0, 10); // full is overkill, too verbose in the logs
|
||||||
|
|
||||||
Log("Creating %s SAM session %s with %s", session_type, session_id, m_control_host.ToStringAddrPort());
|
Log("Creating %s SAM session %s with %s", session_type, session_id, m_control_host.ToString());
|
||||||
|
|
||||||
auto sock = Hello();
|
auto sock = Hello();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <compat/compat.h>
|
#include <compat/compat.h>
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
|
#include <netbase.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/sock.h>
|
#include <util/sock.h>
|
||||||
|
@ -67,7 +68,7 @@ public:
|
||||||
* `Session` object.
|
* `Session` object.
|
||||||
*/
|
*/
|
||||||
Session(const fs::path& private_key_file,
|
Session(const fs::path& private_key_file,
|
||||||
const CService& control_host,
|
const Proxy& control_host,
|
||||||
CThreadInterrupt* interrupt);
|
CThreadInterrupt* interrupt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +82,7 @@ public:
|
||||||
* `CThreadInterrupt` object is saved, so it must not be destroyed earlier than this
|
* `CThreadInterrupt` object is saved, so it must not be destroyed earlier than this
|
||||||
* `Session` object.
|
* `Session` object.
|
||||||
*/
|
*/
|
||||||
Session(const CService& control_host, CThreadInterrupt* interrupt);
|
Session(const Proxy& control_host, CThreadInterrupt* interrupt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the session, closing the internally used sockets. The sockets that have been
|
* Destroy the session, closing the internally used sockets. The sockets that have been
|
||||||
|
@ -235,9 +236,9 @@ private:
|
||||||
const fs::path m_private_key_file;
|
const fs::path m_private_key_file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The host and port of the SAM control service.
|
* The SAM control service proxy.
|
||||||
*/
|
*/
|
||||||
const CService m_control_host;
|
const Proxy m_control_host;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cease network activity when this is signaled.
|
* Cease network activity when this is signaled.
|
||||||
|
|
|
@ -463,7 +463,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
LOCK(m_unused_i2p_sessions_mutex);
|
LOCK(m_unused_i2p_sessions_mutex);
|
||||||
if (m_unused_i2p_sessions.empty()) {
|
if (m_unused_i2p_sessions.empty()) {
|
||||||
i2p_transient_session =
|
i2p_transient_session =
|
||||||
std::make_unique<i2p::sam::Session>(proxy.proxy, &interruptNet);
|
std::make_unique<i2p::sam::Session>(proxy, &interruptNet);
|
||||||
} else {
|
} else {
|
||||||
i2p_transient_session.swap(m_unused_i2p_sessions.front());
|
i2p_transient_session.swap(m_unused_i2p_sessions.front());
|
||||||
m_unused_i2p_sessions.pop();
|
m_unused_i2p_sessions.pop();
|
||||||
|
@ -3186,7 +3186,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
||||||
Proxy i2p_sam;
|
Proxy i2p_sam;
|
||||||
if (GetProxy(NET_I2P, i2p_sam) && connOptions.m_i2p_accept_incoming) {
|
if (GetProxy(NET_I2P, i2p_sam) && connOptions.m_i2p_accept_incoming) {
|
||||||
m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs.GetDataDirNet() / "i2p_private_key",
|
m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs.GetDataDirNet() / "i2p_private_key",
|
||||||
i2p_sam.proxy, &interruptNet);
|
i2p_sam, &interruptNet);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& strDest : connOptions.vSeedNodes) {
|
for (const auto& strDest : connOptions.vSeedNodes) {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <i2p.h>
|
#include <i2p.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <netaddress.h>
|
#include <netaddress.h>
|
||||||
|
#include <netbase.h>
|
||||||
#include <test/util/logging.h>
|
#include <test/util/logging.h>
|
||||||
#include <test/util/net.h>
|
#include <test/util/net.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
@ -51,7 +52,9 @@ BOOST_AUTO_TEST_CASE(unlimited_recv)
|
||||||
};
|
};
|
||||||
|
|
||||||
CThreadInterrupt interrupt;
|
CThreadInterrupt interrupt;
|
||||||
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key", CService{}, &interrupt);
|
const std::optional<CService> addr{Lookup("127.0.0.1", 9000, false)};
|
||||||
|
const Proxy sam_proxy(addr.value(), false);
|
||||||
|
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key", sam_proxy, &interrupt);
|
||||||
|
|
||||||
{
|
{
|
||||||
ASSERT_DEBUG_LOG("Creating persistent SAM session");
|
ASSERT_DEBUG_LOG("Creating persistent SAM session");
|
||||||
|
@ -111,8 +114,10 @@ BOOST_AUTO_TEST_CASE(listen_ok_accept_fail)
|
||||||
};
|
};
|
||||||
|
|
||||||
CThreadInterrupt interrupt;
|
CThreadInterrupt interrupt;
|
||||||
|
const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
|
||||||
|
const Proxy sam_proxy(addr, false);
|
||||||
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key",
|
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key",
|
||||||
CService{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656},
|
sam_proxy,
|
||||||
&interrupt);
|
&interrupt);
|
||||||
|
|
||||||
i2p::Connection conn;
|
i2p::Connection conn;
|
||||||
|
@ -154,7 +159,9 @@ BOOST_AUTO_TEST_CASE(damaged_private_key)
|
||||||
BOOST_REQUIRE(WriteBinaryFile(i2p_private_key_file, file_contents));
|
BOOST_REQUIRE(WriteBinaryFile(i2p_private_key_file, file_contents));
|
||||||
|
|
||||||
CThreadInterrupt interrupt;
|
CThreadInterrupt interrupt;
|
||||||
i2p::sam::Session session(i2p_private_key_file, CService{}, &interrupt);
|
const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
|
||||||
|
const Proxy sam_proxy{addr, false};
|
||||||
|
i2p::sam::Session session(i2p_private_key_file, sam_proxy, &interrupt);
|
||||||
|
|
||||||
{
|
{
|
||||||
ASSERT_DEBUG_LOG("Creating persistent SAM session");
|
ASSERT_DEBUG_LOG("Creating persistent SAM session");
|
||||||
|
|
Loading…
Add table
Reference in a new issue