bool static ApplyProxySettings() { QSettings settings; CService addrProxy(settings.value("addrProxy", "127.0.0.1:9050").toString().toStdString()); int nSocksVersion(settings.value("nSocksVersion", 5).toInt()); if (!settings.value("fUseProxy", false).toBool()) { addrProxy = CService(); nSocksVersion = 0; return false; } if (nSocksVersion && !addrProxy.IsValid()) return false; if (!IsLimited(NET_IPV4)) SetProxy(NET_IPV4, addrProxy, nSocksVersion); if (nSocksVersion > 4) { #ifdef USE_IPV6 if (!IsLimited(NET_IPV6)) SetProxy(NET_IPV6, addrProxy, nSocksVersion); #endif SetNameProxy(addrProxy, nSocksVersion); } return true; }
bool static Bind(const CService &addr, bool fError = true) { if (IsLimited(addr)) return false; std::string strError; if (!BindListenPort(addr, strError)) { if (fError) return InitError(strError); return false; }; return true; }
BOOL CDownloadsSettingsPage::OnKillActive() { UpdateData(); if ( IsLimited( m_sBandwidthLimit ) && !Settings.ParseVolume( m_sBandwidthLimit ) ) { CString strMessage; LoadString( strMessage, IDS_SETTINGS_NEED_BANDWIDTH ); AfxMessageBox( strMessage, MB_ICONEXCLAMATION ); GetDlgItem( IDC_DOWNLOADS_BANDWIDTH_LIMIT )->SetFocus(); return FALSE; } return CSettingsPage::OnKillActive(); }
static UniValue GetNetworksInfo() { UniValue networks(UniValue::VARR); for(int n=0; n<NET_MAX; ++n) { enum Network network = static_cast<enum Network>(n); if(network == NET_UNROUTABLE || network == NET_INTERNAL) continue; proxyType proxy; UniValue obj(UniValue::VOBJ); GetProxy(network, proxy); obj.pushKV("name", GetNetworkName(network)); obj.pushKV("limited", IsLimited(network)); obj.pushKV("reachable", IsReachable(network)); obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string()); obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials); networks.push_back(obj); } return networks; }
void ThreadIRCSeed() { // Don't connect to IRC if we won't use IPv4 connections. if (IsLimited(NET_IPV4)) return; // ... or if we won't make outbound connections and won't accept inbound ones. if (mapArgs.count("-connect") && fNoListen) return; // ... or if IRC is not enabled. if (GetBoolArg("-irc", false)) return; int nErrorWait = 10; int nRetryWait = 10; int nNameRetry = 0; for(;;) { boost::this_thread::interruption_point(); CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org CService addrIRC("irc.lfnet.org", 6667, true); if (addrIRC.IsValid()) addrConnect = addrIRC; SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket, nConnectTimeout)) { LogPrintf("IRC connect failed\n"); nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; }; if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname")) { closesocket(hSocket); hSocket = INVALID_SOCKET; nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; }; CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses CService addrLocal; std::string strMyName; // Don't use our IP as our nick if we're not listening // or if it keeps failing because the nick is already in use. if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); if (strMyName == "") strMyName = strprintf("x%u", GetRand(1000000000)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str()); int nRet = RecvUntil(hSocket, " 004 ", " 433 "); if (nRet != 1) { closesocket(hSocket); hSocket = INVALID_SOCKET; if (nRet == 2) { LogPrintf("IRC name already in use\n"); nNameRetry++; Wait(10); continue; }; nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; }; nNameRetry = 0; MilliSleep(500); // Get our external IP from the IRC server and re-nick before joining the channel CNetAddr addrFromIRC; if (GetIPFromIRC(hSocket, strMyName, addrFromIRC)) { LogPrintf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str()); // Don't use our IP as our nick if we're not listening if (!fNoListen && addrFromIRC.IsRoutable()) { // IRC lets you to re-nick AddLocal(addrFromIRC, LOCAL_IRC); strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); }; }; if (fTestNet) { Send(hSocket, "JOIN #sdcoinTEST\r"); Send(hSocket, "WHO #sdcoinTEST\r"); } else { // randomly join #StealthCash00-#StealthCash05 //int channel_number = GetRandInt(5); // Channel number is always 0 for initial release int channel_number = 0; Send(hSocket, strprintf("JOIN #sdcoin%02d\r", channel_number).c_str()); Send(hSocket, strprintf("WHO #sdcoin%02d\r", channel_number).c_str()); }; int64_t nStart = GetTime(); std::string strLine; strLine.reserve(10000); while (RecvLineIRC(hSocket, strLine)) { boost::this_thread::interruption_point(); if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':') continue; std::vector<std::string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 2) continue; char pszName[10000]; pszName[0] = '\0'; if (vWords[1] == "352" && vWords.size() >= 8) { // index 7 is limited to 16 characters // could get full length name at index 10, but would be different from join messages strlcpy(pszName, vWords[7].c_str(), sizeof(pszName)); LogPrintf("IRC got who\n"); }; if (vWords[1] == "JOIN" && vWords[0].size() > 1) { // :[email protected] JOIN :#channelname strlcpy(pszName, vWords[0].c_str() + 1, sizeof(pszName)); if (strchr(pszName, '!')) *strchr(pszName, '!') = '\0'; LogPrintf("IRC got join\n"); }; if (pszName[0] == 'u') { CAddress addr; if (DecodeAddress(pszName, addr)) { addr.nTime = GetAdjustedTime(); if (addrman.Add(addr, addrConnect, 51 * 60)) LogPrintf("IRC got new address: %s\n", addr.ToString().c_str()); nGotIRCAddresses++; } else { LogPrintf("IRC decode failed\n"); }; }; }; closesocket(hSocket); hSocket = INVALID_SOCKET; if (GetTime() - nStart > 20 * 60) { nErrorWait /= 3; nRetryWait /= 3; }; nRetryWait = nRetryWait * 11 / 10; if (!Wait(nRetryWait += 60)) return; }; }
void CBitcoinServer::BitcoinNetMaintain() { CChainManager& chain = CChainManager::CreateChainManagerInstance(); // chain.LoadBitcoinBlockIndex(); getAddrFromDb(); getAddrFromDnsSeed(); while(true) { if (!m_oneShot.empty()) { std::string strDest; strDest = m_oneShot.front(); m_oneShot.pop_front(); SOCKET hSocket = INVALID_SOCKET; CAddress addr; if (openNetworkConnection(addr, strDest.c_str(), hSocket)) { boost::shared_ptr<CBitcoinNode> node = createNode(hSocket, addr); if (node) { node->fOneShot = true; m_nodesManager.insert(node); node->PushVersion(); } } else { m_oneShot.push_back(strDest); } } if (Bitcoin_MAX_CONNECTED_SOCKECT > m_nodesManager.getNodesSize()) { do { SOCKET hSocket = INVALID_SOCKET; int nUnkBias = 10 + (int)min(m_nodesManager.getNodesSize(), Bitcoin_MAX_CONNECTED_SOCKECT)*10; CAddress addr = m_BitcoinAddrMan.Select(nUnkBias); if (!addr.IsValid() || m_nodesManager.exist(addr) || IsLocal(addr)) { break; } if (IsLimited(addr) || addr.GetPort() != Bitcoin_DEFAULT_PORT) { break; } if (openNetworkConnection(addr, NULL, hSocket)) { boost::shared_ptr<CBitcoinNode> node = createNode(hSocket, addr); if (node) { m_nodesManager.insert(node); node->PushVersion(); } } }while(false); } m_nodesManager.sockectSelect(); m_nodesManager.clearDisconnectNodes(); m_nodesManager.startSync(); } }
void CDownloadsSettingsPage::OnOK() { UpdateData( TRUE ); AntiVirus.UpdateData( m_wndAntiVirus ); // Figure out what the text in the queue limit box means DWORD nQueueLimit = 0; if ( IsLimited( m_sQueueLimit ) ) { // Max queue is limited, calculate number int nPosition = 1, nCount = m_sQueueLimit.GetLength(); while ( nCount-- ) { TCHAR cCharacter = m_sQueueLimit.GetAt( nCount ); if ( ( cCharacter >= '0' ) && ( cCharacter <= '9' ) ) { nQueueLimit += ( ( cCharacter - '0') * nPosition ); nPosition *= 10; } } } else { // Max queue is not limited nQueueLimit = 0; } // Check the queue limit value is okay if ( ( nQueueLimit > 0 ) && ( nQueueLimit < 2000 ) && ( ! Settings.Live.QueueLimitWarning ) && ( Settings.eDonkey.EnableToday || Settings.eDonkey.EnableAlways ) && ( Settings.Downloads.QueueLimit != (int)nQueueLimit ) ) { // Warn the user about setting the max queue wait limit too low CString strMessage; LoadString( strMessage, IDS_SETTINGS_WARN_QUEUELIMIT ); if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDNO ) { nQueueLimit = 0; } else { // Don't need to warn the user again. Settings.Live.QueueLimitWarning = TRUE; } } // Put new values in the settings. Settings.Downloads.CompletePath = m_sDownloadsPath; Settings.Downloads.IncompletePath = m_sIncompletePath; Settings.Downloads.MaxFiles = m_nMaxDownFiles; Settings.Downloads.MaxTransfers = m_nMaxDownTransfers; Settings.Downloads.MaxFileTransfers = m_nMaxFileTransfers; Settings.Downloads.QueueLimit = nQueueLimit; Settings.Bandwidth.Downloads = static_cast< DWORD >( Settings.ParseVolume( m_sBandwidthLimit ) ); Settings.Connection.RequireForTransfers = m_bRequireConnect != FALSE; // Normalize data Settings.Normalize( &Settings.Downloads.MaxFiles ); m_nMaxDownFiles = Settings.Downloads.MaxFiles; Settings.Normalize( &Settings.Downloads.MaxTransfers ); m_nMaxDownTransfers = Settings.Downloads.MaxTransfers; Settings.Normalize( &Settings.Downloads.MaxFileTransfers ); m_nMaxFileTransfers = Settings.Downloads.MaxFileTransfers; Settings.Normalize( &Settings.Downloads.QueueLimit ); // Redraw the text in the queue limit box (in case the limit changed) if ( Settings.Downloads.QueueLimit > 0 ) m_sQueueLimit.Format( _T("%u"), Settings.Downloads.QueueLimit ); else m_sQueueLimit = _T("MAX"); // Display any data changes UpdateData( FALSE ); CreateDirectory( m_sDownloadsPath ); CreateDirectory( m_sIncompletePath ); // CreateDirectory( m_sTorrentPath ); if ( m_bDownloadsChanged ) { if ( LibraryFolders.GetFolderCount() == 0 ) { LibraryFolders.AddFolder( m_sDownloadsPath ); } else if ( ! LibraryFolders.IsFolderShared( m_sDownloadsPath ) ) { CString strFormat, strMessage; LoadString( strFormat, IDS_LIBRARY_DOWNLOADS_ADD ); strMessage.Format( strFormat, (LPCTSTR)m_sDownloadsPath ); if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES ) { CLibraryFolder* pFolder = LibraryFolders.AddFolder( m_sDownloadsPath ); if ( pFolder ) { LoadString( strMessage, IDS_LIBRARY_DOWNLOADS_SHARE ); BOOL bShare = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES; CQuickLock oLock( Library.m_pSection ); if ( LibraryFolders.CheckFolder( pFolder, TRUE ) ) pFolder->SetShared( bShare ? TRI_TRUE : TRI_FALSE ); Library.Update(); } } } } CSettingsPage::OnOK(); }