From 84d9c8f1b882eec983fe160b18d5df7917a7dff6 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 16 Dec 2022 15:12:30 -0500 Subject: [PATCH] access to RouterInfo's addresses by index --- daemon/HTTPServer.cpp | 1 + libi2pd/RouterContext.cpp | 55 +++++++-------- libi2pd/RouterInfo.cpp | 142 +++++++++++++++++++------------------- libi2pd/RouterInfo.h | 24 +++++-- 4 files changed, 116 insertions(+), 106 deletions(-) diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 917acdb8..4743efc2 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -315,6 +315,7 @@ namespace http { { for (const auto& address : *addresses) { + if (!address) continue; s << "\r\n"; switch (address->transportStyle) { diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index 8928fc7f..5259a4f7 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -272,7 +272,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { - if (address->port != port && address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) + if (address && address->port != port && address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) { address->port = port; updated = true; @@ -290,7 +290,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { - if (address->IsNTCP2 () && (address->port != port || address->published != publish)) + if (address && address->IsNTCP2 () && (address->port != port || address->published != publish)) { bool isAddr = v4 && address->IsV4 (); if (!isAddr && (v6 || ygg)) @@ -319,23 +319,20 @@ namespace i2p auto addresses = m_RouterInfo.GetAddresses (); if (!addresses) return; bool found = false, updated = false; - for (auto it = addresses->begin (); it != addresses->end ();) + for (auto& it: *addresses) { - if ((*it)->IsNTCP2 ()) + if (it && it->IsNTCP2 ()) { found = true; if (enable) { - (*it)->s = m_NTCP2Keys->staticPublicKey; - memcpy ((*it)->i, m_NTCP2Keys->iv, 16); - it++; + it->s = m_NTCP2Keys->staticPublicKey; + memcpy (it->i, m_NTCP2Keys->iv, 16); } else - it = addresses->erase (it); + it.reset (); updated = true; - } - else - it++; + } } if (enable && !found) { @@ -365,7 +362,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { - if (address->IsSSU2 () && (!address->port || address->port != port || address->published != publish) && + if (address && address->IsSSU2 () && (!address->port || address->port != port || address->published != publish) && ((v4 && address->IsV4 ()) || (v6 && address->IsV6 ()))) { if (port) address->port = port; @@ -387,23 +384,20 @@ namespace i2p auto addresses = m_RouterInfo.GetAddresses (); if (!addresses) return; bool found = false, updated = false; - for (auto it = addresses->begin (); it != addresses->end ();) + for (auto& it : *addresses) { - if ((*it)->IsSSU2 ()) + if (it && it->IsSSU2 ()) { found = true; if (enable) { - (*it)->s = m_SSU2Keys->staticPublicKey; - (*it)->i = m_SSU2Keys->intro; - it++; + it->s = m_SSU2Keys->staticPublicKey; + it->i = m_SSU2Keys->intro; } else - it = addresses->erase (it); + it.reset (); updated = true; } - else - it++; } if (enable && !found) { @@ -435,6 +429,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { + if (!addrHTTP/1.1 200 OK Date: Wed, 23 Jul 2025 10:13:25 GMT Content-Type: text/plain; charset=utf-8 Connection: close Transfer-Encoding: chunked Cache-Control: max-age=0, private, must-revalidate, no-transform Set-Cookie: i_like_gitea=3b50a89a8fb9c2ca; Path=/; HttpOnly; Secure; SameSite=Lax Set-Cookie: _csrf=T533cQ0dtU7qG-W0I3-HEEchBMU6MTc1MzI2NTYwNTA5MjMzODI5OQ; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax X-Frame-Options: SAMEORIGIN X-Cache-Status: HIT X-Cache-Age: 0 4118 From 84d9c8f1b882eec983fe160b18d5df7917a7dff6 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 16 Dec 2022 15:12:30 -0500 Subject: [PATCH] access to RouterInfo's addresses by index --- daemon/HTTPServer.cpp | 1 + libi2pd/RouterContext.cpp | 55 +++++++-------- libi2pd/RouterInfo.cpp | 142 +++++++++++++++++++------------------- libi2pd/RouterInfo.h | 24 +++++-- 4 files changed, 116 insertions(+), 106 deletions(-) diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 917acdb8..4743efc2 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -315,6 +315,7 @@ namespace http { { for (const auto& address : *addresses) { + if (!address) continue; s << "\r\n"; switch (address->transportStyle) { diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index 8928fc7f..5259a4f7 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -272,7 +272,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { - if (address->port != port && address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) + if (address && address->port != port && address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) { address->port = port; updated = true; @@ -290,7 +290,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { - if (address->IsNTCP2 () && (address->port != port || address->published != publish)) + if (address && address->IsNTCP2 () && (address->port != port || address->published != publish)) { bool isAddr = v4 && address->IsV4 (); if (!isAddr && (v6 || ygg)) @@ -319,23 +319,20 @@ namespace i2p auto addresses = m_RouterInfo.GetAddresses (); if (!addresses) return; bool found = false, updated = false; - for (auto it = addresses->begin (); it != addresses->end ();) + for (auto& it: *addresses) { - if ((*it)->IsNTCP2 ()) + if (it && it->IsNTCP2 ()) { found = true; if (enable) { - (*it)->s = m_NTCP2Keys->staticPublicKey; - memcpy ((*it)->i, m_NTCP2Keys->iv, 16); - it++; + it->s = m_NTCP2Keys->staticPublicKey; + memcpy (it->i, m_NTCP2Keys->iv, 16); } else - it = addresses->erase (it); + it.reset (); updated = true; - } - else - it++; + } } if (enable && !found) { @@ -365,7 +362,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { - if (address->IsSSU2 () && (!address->port || address->port != port || address->published != publish) && + if (address && address->IsSSU2 () && (!address->port || address->port != port || address->published != publish) && ((v4 && address->IsV4 ()) || (v6 && address->IsV6 ()))) { if (port) address->port = port; @@ -387,23 +384,20 @@ namespace i2p auto addresses = m_RouterInfo.GetAddresses (); if (!addresses) return; bool found = false, updated = false; - for (auto it = addresses->begin (); it != addresses->end ();) + for (auto& it : *addresses) { - if ((*it)->IsSSU2 ()) + if (it && it->IsSSU2 ()) { found = true; if (enable) { - (*it)->s = m_SSU2Keys->staticPublicKey; - (*it)->i = m_SSU2Keys->intro; - it++; + it->s = m_SSU2Keys->staticPublicKey; + it->i = m_SSU2Keys->intro; } else - it = addresses->erase (it); + it.reset (); updated = true; } - else - it++; } if (enable && !found) { @@ -435,6 +429,7 @@ namespace i2p bool updated = false; for (auto& address : *addresses) { + if (!addr 0