Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 2,101 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
} | } | ||||
if (::bind(hListenSocket, (struct sockaddr *)&sockaddr, len) == | if (::bind(hListenSocket, (struct sockaddr *)&sockaddr, len) == | ||||
SOCKET_ERROR) { | SOCKET_ERROR) { | ||||
int nErr = WSAGetLastError(); | int nErr = WSAGetLastError(); | ||||
if (nErr == WSAEADDRINUSE) { | if (nErr == WSAEADDRINUSE) { | ||||
strError = strprintf(_("Unable to bind to %s on this computer. %s " | strError = strprintf(_("Unable to bind to %s on this computer. %s " | ||||
"is probably already running."), | "is probably already running.") | ||||
.translated, | |||||
addrBind.ToString(), PACKAGE_NAME); | addrBind.ToString(), PACKAGE_NAME); | ||||
} else { | } else { | ||||
strError = strprintf(_("Unable to bind to %s on this computer " | strError = strprintf(_("Unable to bind to %s on this computer " | ||||
"(bind returned error %s)"), | "(bind returned error %s)") | ||||
.translated, | |||||
addrBind.ToString(), NetworkErrorString(nErr)); | addrBind.ToString(), NetworkErrorString(nErr)); | ||||
} | } | ||||
LogPrintf("%s\n", strError); | LogPrintf("%s\n", strError); | ||||
CloseSocket(hListenSocket); | CloseSocket(hListenSocket); | ||||
return false; | return false; | ||||
} | } | ||||
LogPrintf("Bound to %s\n", addrBind.ToString()); | LogPrintf("Bound to %s\n", addrBind.ToString()); | ||||
// Listen for incoming connections | // Listen for incoming connections | ||||
if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR) { | if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR) { | ||||
strError = strprintf(_("Error: Listening for incoming connections " | strError = strprintf(_("Error: Listening for incoming connections " | ||||
"failed (listen returned error %s)"), | "failed (listen returned error %s)") | ||||
.translated, | |||||
NetworkErrorString(WSAGetLastError())); | NetworkErrorString(WSAGetLastError())); | ||||
LogPrintf("%s\n", strError); | LogPrintf("%s\n", strError); | ||||
CloseSocket(hListenSocket); | CloseSocket(hListenSocket); | ||||
return false; | return false; | ||||
} | } | ||||
vhListenSocket.push_back(ListenSocket(hListenSocket, permissions)); | vhListenSocket.push_back(ListenSocket(hListenSocket, permissions)); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | Init(connOptions); | ||||
nMaxOutboundTotalBytesSentInCycle = 0; | nMaxOutboundTotalBytesSentInCycle = 0; | ||||
nMaxOutboundCycleStartTime = 0; | nMaxOutboundCycleStartTime = 0; | ||||
} | } | ||||
if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) { | if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) { | ||||
if (clientInterface) { | if (clientInterface) { | ||||
clientInterface->ThreadSafeMessageBox( | clientInterface->ThreadSafeMessageBox( | ||||
_("Failed to listen on any port. Use -listen=0 if you want " | _("Failed to listen on any port. Use -listen=0 if you want " | ||||
"this."), | "this.") | ||||
.translated, | |||||
"", CClientUIInterface::MSG_ERROR); | "", CClientUIInterface::MSG_ERROR); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
for (const auto &strDest : connOptions.vSeedNodes) { | for (const auto &strDest : connOptions.vSeedNodes) { | ||||
AddOneShot(strDest); | AddOneShot(strDest); | ||||
} | } | ||||
if (clientInterface) { | if (clientInterface) { | ||||
clientInterface->InitMessage(_("Loading P2P addresses...")); | clientInterface->InitMessage(_("Loading P2P addresses...").translated); | ||||
} | } | ||||
// Load addresses from peers.dat | // Load addresses from peers.dat | ||||
int64_t nStart = GetTimeMillis(); | int64_t nStart = GetTimeMillis(); | ||||
{ | { | ||||
CAddrDB adb(config->GetChainParams()); | CAddrDB adb(config->GetChainParams()); | ||||
if (adb.Read(addrman)) { | if (adb.Read(addrman)) { | ||||
LogPrintf("Loaded %i addresses from peers.dat %dms\n", | LogPrintf("Loaded %i addresses from peers.dat %dms\n", | ||||
addrman.size(), GetTimeMillis() - nStart); | addrman.size(), GetTimeMillis() - nStart); | ||||
} else { | } else { | ||||
// Addrman can be in an inconsistent state after failure, reset it | // Addrman can be in an inconsistent state after failure, reset it | ||||
addrman.Clear(); | addrman.Clear(); | ||||
LogPrintf("Invalid or missing peers.dat; recreating\n"); | LogPrintf("Invalid or missing peers.dat; recreating\n"); | ||||
DumpAddresses(); | DumpAddresses(); | ||||
} | } | ||||
} | } | ||||
uiInterface.InitMessage(_("Starting network threads...")); | uiInterface.InitMessage(_("Starting network threads...").translated); | ||||
fAddressesInitialized = true; | fAddressesInitialized = true; | ||||
if (semOutbound == nullptr) { | if (semOutbound == nullptr) { | ||||
// initialize semaphore | // initialize semaphore | ||||
semOutbound = std::make_unique<CSemaphore>( | semOutbound = std::make_unique<CSemaphore>( | ||||
std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)); | std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)); | ||||
} | } | ||||
Show All 35 Lines | threadOpenAddedConnections = | ||||
std::function<void()>(std::bind( | std::function<void()>(std::bind( | ||||
&CConnman::ThreadOpenAddedConnections, this))); | &CConnman::ThreadOpenAddedConnections, this))); | ||||
if (connOptions.m_use_addrman_outgoing && | if (connOptions.m_use_addrman_outgoing && | ||||
!connOptions.m_specified_outgoing.empty()) { | !connOptions.m_specified_outgoing.empty()) { | ||||
if (clientInterface) { | if (clientInterface) { | ||||
clientInterface->ThreadSafeMessageBox( | clientInterface->ThreadSafeMessageBox( | ||||
_("Cannot provide specific connections and have addrman find " | _("Cannot provide specific connections and have addrman find " | ||||
"outgoing connections at the same."), | "outgoing connections at the same.") | ||||
.translated, | |||||
"", CClientUIInterface::MSG_ERROR); | "", CClientUIInterface::MSG_ERROR); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
if (connOptions.m_use_addrman_outgoing || | if (connOptions.m_use_addrman_outgoing || | ||||
!connOptions.m_specified_outgoing.empty()) { | !connOptions.m_specified_outgoing.empty()) { | ||||
threadOpenConnections = | threadOpenConnections = | ||||
std::thread(&TraceThread<std::function<void()>>, "opencon", | std::thread(&TraceThread<std::function<void()>>, "opencon", | ||||
▲ Show 20 Lines • Show All 516 Lines • Show Last 20 Lines |