@@ -485,18 +485,27 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
485485 Proxy proxy;
486486 CAddress addr_bind;
487487 assert (!addr_bind.IsValid ());
488+ std::unique_ptr<i2p::sam::Session> i2p_transient_session;
488489
489490 if (addrConnect.IsValid ()) {
491+ const bool use_proxy{GetProxy (addrConnect.GetNetwork (), proxy)};
490492 bool proxyConnectionFailed = false ;
491493
492- if (addrConnect.GetNetwork () == NET_I2P && m_i2p_sam_session. get () != nullptr ) {
494+ if (addrConnect.GetNetwork () == NET_I2P && use_proxy ) {
493495 i2p::Connection conn;
494- if (m_i2p_sam_session->Connect (addrConnect, conn, proxyConnectionFailed)) {
495- connected = true ;
496+
497+ if (m_i2p_sam_session) {
498+ connected = m_i2p_sam_session->Connect (addrConnect, conn, proxyConnectionFailed);
499+ } else {
500+ i2p_transient_session = std::make_unique<i2p::sam::Session>(proxy.proxy , &interruptNet);
501+ connected = i2p_transient_session->Connect (addrConnect, conn, proxyConnectionFailed);
502+ }
503+
504+ if (connected) {
496505 sock = std::move (conn.sock );
497506 addr_bind = CAddress{conn.me , NODE_NONE};
498507 }
499- } else if (GetProxy (addrConnect. GetNetwork (), proxy) ) {
508+ } else if (use_proxy ) {
500509 sock = CreateSock (proxy.proxy );
501510 if (!sock) {
502511 return nullptr ;
@@ -547,7 +556,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
547556 addr_bind,
548557 pszDest ? pszDest : " " ,
549558 conn_type,
550- /* inbound_onion=*/ false );
559+ /* inbound_onion=*/ false ,
560+ std::move (i2p_transient_session));
551561 pnode->AddRef ();
552562
553563 // 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)
22602270 }
22612271
22622272 Proxy i2p_sam;
2263- if (GetProxy (NET_I2P, i2p_sam)) {
2273+ if (GetProxy (NET_I2P, i2p_sam) && connOptions. m_i2p_accept_incoming ) {
22642274 m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs .GetDataDirNet () / " i2p_private_key" ,
22652275 i2p_sam.proxy , &interruptNet);
22662276 }
@@ -2334,7 +2344,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
23342344 // Process messages
23352345 threadMessageHandler = std::thread (&util::TraceThread, " msghand" , [this ] { ThreadMessageHandler (); });
23362346
2337- if (connOptions. m_i2p_accept_incoming && m_i2p_sam_session. get () != nullptr ) {
2347+ if (m_i2p_sam_session) {
23382348 threadI2PAcceptIncoming =
23392349 std::thread (&util::TraceThread, " i2paccept" , [this ] { ThreadI2PAcceptIncoming (); });
23402350 }
0 commit comments