|
14 | 14 | #include <compat.h>
|
15 | 15 | #include <consensus/consensus.h>
|
16 | 16 | #include <crypto/sha256.h>
|
| 17 | +#include <i2p.h> |
17 | 18 | #include <net_permissions.h>
|
18 | 19 | #include <netbase.h>
|
19 | 20 | #include <node/ui_interface.h>
|
@@ -2187,6 +2188,45 @@ void CConnman::ThreadMessageHandler()
|
2187 | 2188 | }
|
2188 | 2189 | }
|
2189 | 2190 |
|
| 2191 | +void CConnman::ThreadI2PAcceptIncoming() |
| 2192 | +{ |
| 2193 | + static constexpr auto err_wait_begin = 1s; |
| 2194 | + static constexpr auto err_wait_cap = 5min; |
| 2195 | + auto err_wait = err_wait_begin; |
| 2196 | + |
| 2197 | + bool advertising_listen_addr = false; |
| 2198 | + i2p::Connection conn; |
| 2199 | + |
| 2200 | + while (!interruptNet) { |
| 2201 | + |
| 2202 | + if (!m_i2p_sam_session->Listen(conn)) { |
| 2203 | + if (advertising_listen_addr && conn.me.IsValid()) { |
| 2204 | + RemoveLocal(conn.me); |
| 2205 | + advertising_listen_addr = false; |
| 2206 | + } |
| 2207 | + |
| 2208 | + interruptNet.sleep_for(err_wait); |
| 2209 | + if (err_wait < err_wait_cap) { |
| 2210 | + err_wait *= 2; |
| 2211 | + } |
| 2212 | + |
| 2213 | + continue; |
| 2214 | + } |
| 2215 | + |
| 2216 | + if (!advertising_listen_addr) { |
| 2217 | + AddLocal(conn.me, LOCAL_BIND); |
| 2218 | + advertising_listen_addr = true; |
| 2219 | + } |
| 2220 | + |
| 2221 | + if (!m_i2p_sam_session->Accept(conn)) { |
| 2222 | + continue; |
| 2223 | + } |
| 2224 | + |
| 2225 | + CreateNodeFromAcceptedSocket(conn.sock.Release(), NetPermissionFlags::PF_NONE, |
| 2226 | + CAddress{conn.me, NODE_NONE}, CAddress{conn.peer, NODE_NONE}); |
| 2227 | + } |
| 2228 | +} |
| 2229 | + |
2190 | 2230 | bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError, NetPermissionFlags permissions)
|
2191 | 2231 | {
|
2192 | 2232 | int nOne = 1;
|
@@ -2472,6 +2512,12 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
2472 | 2512 | // Process messages
|
2473 | 2513 | threadMessageHandler = std::thread(&TraceThread<std::function<void()> >, "msghand", std::function<void()>(std::bind(&CConnman::ThreadMessageHandler, this)));
|
2474 | 2514 |
|
| 2515 | + if (connOptions.m_i2p_accept_incoming && m_i2p_sam_session.get() != nullptr) { |
| 2516 | + threadI2PAcceptIncoming = |
| 2517 | + std::thread(&TraceThread<std::function<void()>>, "i2paccept", |
| 2518 | + std::function<void()>(std::bind(&CConnman::ThreadI2PAcceptIncoming, this))); |
| 2519 | + } |
| 2520 | + |
2475 | 2521 | // Dump network addresses
|
2476 | 2522 | scheduler.scheduleEvery([this] { DumpAddresses(); }, DUMP_PEERS_INTERVAL);
|
2477 | 2523 |
|
@@ -2519,6 +2565,9 @@ void CConnman::Interrupt()
|
2519 | 2565 |
|
2520 | 2566 | void CConnman::StopThreads()
|
2521 | 2567 | {
|
| 2568 | + if (threadI2PAcceptIncoming.joinable()) { |
| 2569 | + threadI2PAcceptIncoming.join(); |
| 2570 | + } |
2522 | 2571 | if (threadMessageHandler.joinable())
|
2523 | 2572 | threadMessageHandler.join();
|
2524 | 2573 | if (threadOpenConnections.joinable())
|
|
0 commit comments