@@ -485,18 +485,27 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
485
485
Proxy proxy;
486
486
CAddress addr_bind;
487
487
assert (!addr_bind.IsValid ());
488
+ std::unique_ptr<i2p::sam::Session> i2p_transient_session;
488
489
489
490
if (addrConnect.IsValid ()) {
491
+ const bool use_proxy{GetProxy (addrConnect.GetNetwork (), proxy)};
490
492
bool proxyConnectionFailed = false ;
491
493
492
- if (addrConnect.GetNetwork () == NET_I2P && m_i2p_sam_session. get () != nullptr ) {
494
+ if (addrConnect.GetNetwork () == NET_I2P && use_proxy ) {
493
495
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) {
496
505
sock = std::move (conn.sock );
497
506
addr_bind = CAddress{conn.me , NODE_NONE};
498
507
}
499
- } else if (GetProxy (addrConnect. GetNetwork (), proxy) ) {
508
+ } else if (use_proxy ) {
500
509
sock = CreateSock (proxy.proxy );
501
510
if (!sock) {
502
511
return nullptr ;
@@ -547,7 +556,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
547
556
addr_bind,
548
557
pszDest ? pszDest : " " ,
549
558
conn_type,
550
- /* inbound_onion=*/ false );
559
+ /* inbound_onion=*/ false ,
560
+ std::move (i2p_transient_session));
551
561
pnode->AddRef ();
552
562
553
563
// 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)
2260
2270
}
2261
2271
2262
2272
Proxy i2p_sam;
2263
- if (GetProxy (NET_I2P, i2p_sam)) {
2273
+ if (GetProxy (NET_I2P, i2p_sam) && connOptions. m_i2p_accept_incoming ) {
2264
2274
m_i2p_sam_session = std::make_unique<i2p::sam::Session>(gArgs .GetDataDirNet () / " i2p_private_key" ,
2265
2275
i2p_sam.proxy , &interruptNet);
2266
2276
}
@@ -2334,7 +2344,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
2334
2344
// Process messages
2335
2345
threadMessageHandler = std::thread (&util::TraceThread, " msghand" , [this ] { ThreadMessageHandler (); });
2336
2346
2337
- if (connOptions. m_i2p_accept_incoming && m_i2p_sam_session. get () != nullptr ) {
2347
+ if (m_i2p_sam_session) {
2338
2348
threadI2PAcceptIncoming =
2339
2349
std::thread (&util::TraceThread, " i2paccept" , [this ] { ThreadI2PAcceptIncoming (); });
2340
2350
}
0 commit comments