@@ -43,7 +43,9 @@ static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"
4343#include < chrono>
4444#include < cstdint>
4545#include < exception>
46+ #include < ios>
4647#include < memory>
48+ #include < system_error>
4749#include < unordered_map>
4850
4951#include < math.h>
@@ -433,6 +435,9 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
433435 bool connected = false ;
434436 SOCKET hSocket = INVALID_SOCKET;
435437 proxyType proxy;
438+ CAddress addr_bind;
439+ assert (!addr_bind.IsValid ());
440+
436441 if (addrConnect.IsValid ()) {
437442 bool proxyConnectionFailed = false ;
438443
@@ -442,6 +447,18 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
442447 return nullptr ;
443448 }
444449 connected = ConnectThroughProxy (proxy, addrConnect.ToStringIP (), addrConnect.GetPort (), hSocket, nConnectTimeout, proxyConnectionFailed);
450+ } else if (addrConnect.GetNetwork () == NET_I2P) {
451+ try {
452+ const i2p::Connection& conn = m_i2p_sam_session->Connect (addrConnect);
453+ connected = true ;
454+ hSocket = conn.socket ;
455+ addr_bind = CAddress{conn.me , NODE_NONE};
456+ } catch (const std::ios_base::failure& e) {
457+ LogPrint (BCLog::I2P, " I2P: %s\n " , e.what ());
458+ if (e.code () == std::errc::network_unreachable) {
459+ proxyConnectionFailed = true ;
460+ }
461+ }
445462 } else {
446463 // no proxy needed (none set for target network)
447464 hSocket = CreateSocket (addrConnect);
@@ -474,7 +491,9 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
474491 // Add node
475492 NodeId id = GetNewNodeId ();
476493 uint64_t nonce = GetDeterministicRandomizer (RANDOMIZER_ID_LOCALHOSTNONCE).Write (id).Finalize ();
477- CAddress addr_bind = GetBindAddress (hSocket);
494+ if (!addr_bind.IsValid ()) {
495+ addr_bind = GetBindAddress (hSocket);
496+ }
478497 CNode* pnode = new CNode (id, nLocalServices, GetBestHeight (), hSocket, addrConnect, CalculateKeyedNetGroup (addrConnect), nonce, addr_bind, pszDest ? pszDest : " " , conn_type);
479498 pnode->AddRef ();
480499
0 commit comments