mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
net: use transient I2P session for outbound if -i2pacceptincoming=0
If not accepting I2P connections, then do not create `CConnman::m_i2p_sam_session`. When opening a new outbound I2P connection either use `CConnman::m_i2p_sam_session` like before or create a temporary one and store it in `CNode` for destruction later.
This commit is contained in:
24
src/net.cpp
24
src/net.cpp
@@ -485,18 +485,27 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
|||||||
Proxy proxy;
|
Proxy proxy;
|
||||||
CAddress addr_bind;
|
CAddress addr_bind;
|
||||||
assert(!addr_bind.IsValid());
|
assert(!addr_bind.IsValid());
|
||||||
|
std::unique_ptr<i2p::sam::Session> i2p_transient_session;
|
||||||
|
|
||||||
if (addrConnect.IsValid()) {
|
if (addrConnect.IsValid()) {
|
||||||
|
const bool use_proxy{GetProxy(addrConnect.GetNetwork(), proxy)};
|
||||||
bool proxyConnectionFailed = false;
|
bool proxyConnectionFailed = false;
|
||||||
|
|
||||||
if (addrConnect.GetNetwork() == NET_I2P && m_i2p_sam_session.get() != nullptr) {
|
if (addrConnect.GetNetwork() == NET_I2P && use_proxy) {
|
||||||
i2p::Connection conn;
|
i2p::Connection conn;
|
||||||
if (m_i2p_sam_session->Connect(addrConnect, conn, proxyConnectionFailed)) {
|
|
||||||
connected = true;
|
if (m_i2p_sam_session) {
|
||||||
|
connected = m_i2p_sam_session->Connect(addrConnect, conn, proxyConnectionFailed);
|
||||||
|
} else {
|
||||||
|
i2p_transient_session = std::make_unique<i2p::sam::Session>(proxy.proxy, &interruptNet);
|
||||||
|
connected = i2p_transient_session->Connect(addrConnect, conn, proxyConnectionFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connected) {
|
||||||
sock = std::move(conn.sock);
|
sock = std::move(conn.sock);
|
||||||
addr_bind = CAddress{conn.me, NODE_NONE};
|
addr_bind = CAddress{conn.me, NODE_NONE};
|
||||||
}
|
}
|
||||||
} else if (GetProxy(addrConnect.GetNetwork(), proxy)) {
|
} else if (use_proxy) {
|
||||||
sock = CreateSock(proxy.proxy);
|
sock = CreateSock(proxy.proxy);
|
||||||
if (!sock) {
|
if (!sock) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -547,7 +556,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
|||||||
addr_bind,
|
addr_bind,
|
||||||
pszDest ? pszDest : "",
|
pszDest ? pszDest : "",
|
||||||
conn_type,
|
conn_type,
|
||||||
/*inbound_onion=*/false);
|
/*inbound_onion=*/false,
|
||||||
|
std::move(i2p_transient_session));
|
||||||
pnode->AddRef();
|
pnode->AddRef();
|
||||||
|
|
||||||
// We're making a new connection, harvest entropy from the time (and our peer count)
|
// We're making a new connection, harvest entropy from the time (and our peer count)
|
||||||
@@ -2260,7 +2270,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Proxy i2p_sam;
|
Proxy i2p_sam;
|
||||||
if (GetProxy(NET_I2P, i2p_sam)) {
|
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.proxy, &interruptNet);
|
||||||
}
|
}
|
||||||
@@ -2334,7 +2344,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
|||||||
// Process messages
|
// Process messages
|
||||||
threadMessageHandler = std::thread(&util::TraceThread, "msghand", [this] { ThreadMessageHandler(); });
|
threadMessageHandler = std::thread(&util::TraceThread, "msghand", [this] { ThreadMessageHandler(); });
|
||||||
|
|
||||||
if (connOptions.m_i2p_accept_incoming && m_i2p_sam_session.get() != nullptr) {
|
if (m_i2p_sam_session) {
|
||||||
threadI2PAcceptIncoming =
|
threadI2PAcceptIncoming =
|
||||||
std::thread(&util::TraceThread, "i2paccept", [this] { ThreadI2PAcceptIncoming(); });
|
std::thread(&util::TraceThread, "i2paccept", [this] { ThreadI2PAcceptIncoming(); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1090,7 +1090,8 @@ private:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* I2P SAM session.
|
* I2P SAM session.
|
||||||
* Used to accept incoming and make outgoing I2P connections.
|
* Used to accept incoming and make outgoing I2P connections from a persistent
|
||||||
|
* address.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
|
std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user