Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show All 32 Lines | |||||
#include <miniupnpc/miniupnpc.h> | #include <miniupnpc/miniupnpc.h> | ||||
#include <miniupnpc/miniwget.h> | #include <miniupnpc/miniwget.h> | ||||
#include <miniupnpc/upnpcommands.h> | #include <miniupnpc/upnpcommands.h> | ||||
#include <miniupnpc/upnperrors.h> | #include <miniupnpc/upnperrors.h> | ||||
#endif | #endif | ||||
#include <cmath> | #include <cmath> | ||||
// Dump addresses to peers.dat and banlist.dat every 15 minutes (900s) | // Dump addresses to peers.dat every 15 minutes (900s) | ||||
#define DUMP_ADDRESSES_INTERVAL 900 | static constexpr int DUMP_PEERS_INTERVAL = 15 * 60; | ||||
// Dump addresses to banlist.dat every 15 minutes (900s) | |||||
static constexpr int DUMP_BANS_INTERVAL = 60 * 15; | |||||
// We add a random period time (0 to 1 seconds) to feeler connections to prevent | // We add a random period time (0 to 1 seconds) to feeler connections to prevent | ||||
// synchronization. | // synchronization. | ||||
#define FEELER_SLEEP_WINDOW 1 | #define FEELER_SLEEP_WINDOW 1 | ||||
// MSG_NOSIGNAL is not available on some platforms, if it doesn't exist define | // MSG_NOSIGNAL is not available on some platforms, if it doesn't exist define | ||||
// it as 0 | // it as 0 | ||||
#if !defined(MSG_NOSIGNAL) | #if !defined(MSG_NOSIGNAL) | ||||
▲ Show 20 Lines • Show All 1,711 Lines • ▼ Show 20 Lines | void CConnman::DumpAddresses() { | ||||
CAddrDB adb(config->GetChainParams()); | CAddrDB adb(config->GetChainParams()); | ||||
adb.Write(addrman); | adb.Write(addrman); | ||||
LogPrint(BCLog::NET, "Flushed %d addresses to peers.dat %dms\n", | LogPrint(BCLog::NET, "Flushed %d addresses to peers.dat %dms\n", | ||||
addrman.size(), GetTimeMillis() - nStart); | addrman.size(), GetTimeMillis() - nStart); | ||||
} | } | ||||
void CConnman::DumpData() { | |||||
DumpAddresses(); | |||||
DumpBanlist(); | |||||
} | |||||
void CConnman::ProcessOneShot() { | void CConnman::ProcessOneShot() { | ||||
std::string strDest; | std::string strDest; | ||||
{ | { | ||||
LOCK(cs_vOneShots); | LOCK(cs_vOneShots); | ||||
if (vOneShots.empty()) { | if (vOneShots.empty()) { | ||||
return; | return; | ||||
} | } | ||||
strDest = vOneShots.front(); | strDest = vOneShots.front(); | ||||
▲ Show 20 Lines • Show All 759 Lines • ▼ Show 20 Lines | bool CConnman::Start(CScheduler &scheduler, const Options &connOptions) { | ||||
threadMessageHandler = | threadMessageHandler = | ||||
std::thread(&TraceThread<std::function<void()>>, "msghand", | std::thread(&TraceThread<std::function<void()>>, "msghand", | ||||
std::function<void()>( | std::function<void()>( | ||||
std::bind(&CConnman::ThreadMessageHandler, this))); | std::bind(&CConnman::ThreadMessageHandler, this))); | ||||
// Dump network addresses | // Dump network addresses | ||||
scheduler.scheduleEvery( | scheduler.scheduleEvery( | ||||
[this]() { | [this]() { | ||||
this->DumpData(); | this->DumpAddresses(); | ||||
return true; | |||||
}, | |||||
DUMP_PEERS_INTERVAL * 1000); | |||||
scheduler.scheduleEvery( | |||||
[this]() { | |||||
this->DumpBanlist(); | |||||
return true; | return true; | ||||
}, | }, | ||||
DUMP_ADDRESSES_INTERVAL * 1000); | DUMP_BANS_INTERVAL * 1000); | ||||
return true; | return true; | ||||
} | } | ||||
class CNetCleanup { | class CNetCleanup { | ||||
public: | public: | ||||
CNetCleanup() {} | CNetCleanup() {} | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void CConnman::Stop() { | ||||
if (threadDNSAddressSeed.joinable()) { | if (threadDNSAddressSeed.joinable()) { | ||||
threadDNSAddressSeed.join(); | threadDNSAddressSeed.join(); | ||||
} | } | ||||
if (threadSocketHandler.joinable()) { | if (threadSocketHandler.joinable()) { | ||||
threadSocketHandler.join(); | threadSocketHandler.join(); | ||||
} | } | ||||
if (fAddressesInitialized) { | if (fAddressesInitialized) { | ||||
DumpData(); | DumpAddresses(); | ||||
DumpBanlist(); | |||||
fAddressesInitialized = false; | fAddressesInitialized = false; | ||||
} | } | ||||
// Close sockets | // Close sockets | ||||
for (CNode *pnode : vNodes) { | for (CNode *pnode : vNodes) { | ||||
pnode->CloseSocketDisconnect(); | pnode->CloseSocketDisconnect(); | ||||
} | } | ||||
for (ListenSocket &hListenSocket : vhListenSocket) { | for (ListenSocket &hListenSocket : vhListenSocket) { | ||||
▲ Show 20 Lines • Show All 461 Lines • Show Last 20 Lines |