// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
-#include <stdint.h>
-
#include "headers.h"
#include "irc.h"
#include "db.h"
//
bool fClient = false;
bool fAllowDNS = false;
-uint64_t nLocalServices = (fClient ? 0 : NODE_NETWORK);
+uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK);
CAddress addrLocalHost("0.0.0.0", 0, false, nLocalServices);
static CNode* pnodeLocalHost = NULL;
-uint64_t nLocalHostNonce = 0;
+uint64 nLocalHostNonce = 0;
array<int, 10> vnThreadsRunning;
static SOCKET hListenSocket = INVALID_SOCKET;
map<vector<unsigned char>, CAddress> mapAddresses;
CCriticalSection cs_mapAddresses;
map<CInv, CDataStream> mapRelay;
-deque<pair<int64_t, CInv> > vRelayExpiration;
+deque<pair<int64, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;
-map<CInv, int64_t> mapAlreadyAskedFor;
+map<CInv, int64> mapAlreadyAskedFor;
// Settings
int fUseProxy = false;
-bool AddAddress(CAddress addr, int64_t nTimePenalty, CAddrDB *pAddrDB)
+bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
{
if (!addr.IsRoutable())
return false;
if (addr.ip == addrLocalHost.ip)
return false;
- addr.nTime = max((int64_t)0, (int64_t)addr.nTime - nTimePenalty);
+ addr.nTime = max((int64)0, (int64)addr.nTime - nTimePenalty);
bool fUpdated = false;
bool fNew = false;
CAddress addrFound = addr;
fUpdated = true;
}
bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
- int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
+ int64 nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
if (addrFound.nTime < addr.nTime - nUpdateInterval)
{
// Periodically update most recently seen time
void AddressCurrentlyConnected(const CAddress& addr)
{
+ CAddress *paddrFound = NULL;
+
CRITICAL_BLOCK(cs_mapAddresses)
{
// Only if it's been published already
map<vector<unsigned char>, CAddress>::iterator it = mapAddresses.find(addr.GetKey());
if (it != mapAddresses.end())
+ paddrFound = &(*it).second;
+ }
+
+ if (paddrFound)
+ {
+ int64 nUpdateInterval = 20 * 60;
+ if (paddrFound->nTime < GetAdjustedTime() - nUpdateInterval)
{
- CAddress& addrFound = (*it).second;
- int64_t nUpdateInterval = 20 * 60;
- if (addrFound.nTime < GetAdjustedTime() - nUpdateInterval)
- {
- // Periodically update most recently seen time
- addrFound.nTime = GetAdjustedTime();
- CAddrDB addrdb;
- addrdb.WriteAddress(addrFound);
- }
+ // Periodically update most recently seen time
+ paddrFound->nTime = GetAdjustedTime();
+ CAddrDB addrdb;
+ addrdb.WriteAddress(*paddrFound);
}
}
}
return NULL;
}
-CNode* ConnectNode(CAddress addrConnect, int64_t nTimeout)
+CNode* ConnectNode(CAddress addrConnect, int64 nTimeout)
{
if (addrConnect.ip == addrLocalHost.ip)
return NULL;
void CNode::PushVersion()
{
/// when NTP implemented, change to just nTime = GetAdjustedTime()
- int64_t nTime = (fInbound ? GetAdjustedTime() : GetTime());
+ int64 nTime = (fInbound ? GetAdjustedTime() : GetTime());
CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr);
CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost);
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
-std::map<unsigned int, int64_t> CNode::setBanned;
+std::map<unsigned int, int64> CNode::setBanned;
CCriticalSection CNode::cs_setBanned;
void CNode::ClearBanned()
bool fResult = false;
CRITICAL_BLOCK(cs_setBanned)
{
- std::map<unsigned int, int64_t>::iterator i = setBanned.find(ip);
+ std::map<unsigned int, int64>::iterator i = setBanned.find(ip);
if (i != setBanned.end())
{
- int64_t t = (*i).second;
+ int64 t = (*i).second;
if (GetTime() < t)
fResult = true;
}
nMisbehavior += howmuch;
if (nMisbehavior >= GetArg("-banscore", 100))
{
- int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
+ int64 banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
CRITICAL_BLOCK(cs_setBanned)
if (setBanned[addr.ip] < banTime)
setBanned[addr.ip] = banTime;
if (!fTestNet)
{
printf("Loading addresses from DNS seeds (could take a while)\n");
- CAddrDB addrDB;
- addrDB.TxnBegin();
for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) {
vector<CAddress> vaddr;
if (Lookup(strDNSSeed[seed_idx], vaddr, NODE_NETWORK, -1, true))
{
+ CAddrDB addrDB;
+ addrDB.TxnBegin();
BOOST_FOREACH (CAddress& addr, vaddr)
{
if (addr.GetByte(3) != 127)
found++;
}
}
+ addrDB.TxnCommit(); // Save addresses (it's ok if this fails)
}
}
-
- addrDB.TxnCommit(); // Save addresses (it's ok if this fails)
}
printf("%d addresses found from DNS seeds\n", found);
// Connect to specific addresses
if (mapArgs.count("-connect"))
{
- for (int64_t nLoop = 0;; nLoop++)
+ for (int64 nLoop = 0;; nLoop++)
{
BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"])
{
}
// Initiate network connections
- int64_t nStart = GetTime();
+ int64 nStart = GetTime();
loop
{
// Limit outbound connections
if (fShutdown)
return;
+ bool fAddSeeds = false;
+
CRITICAL_BLOCK(cs_mapAddresses)
{
// Add seed nodes if IRC isn't working
bool fTOR = (fUseProxy && addrProxy.port == htons(9050));
- if (mapAddresses.empty() && (GetTime() - nStart > 60 || fTOR) && !fTestNet)
+ if (mapAddresses.empty() && (GetTime() - nStart > 60 || fUseProxy) && !fTestNet)
+ fAddSeeds = true;
+ }
+
+ if (fAddSeeds)
+ {
+ for (int i = 0; i < ARRAYLEN(pnSeed); i++)
{
- for (int i = 0; i < ARRAYLEN(pnSeed); i++)
- {
- // It'll only connect to one or two seed nodes because once it connects,
- // it'll get a pile of addresses with newer timestamps.
- // Seed nodes are given a random 'last seen time' of between one and two
- // weeks ago.
- const int64_t nOneWeek = 7*24*60*60;
- CAddress addr;
- addr.ip = pnSeed[i];
- addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek;
- AddAddress(addr);
- }
+ // It'll only connect to one or two seed nodes because once it connects,
+ // it'll get a pile of addresses with newer timestamps.
+ // Seed nodes are given a random 'last seen time' of between one and two
+ // weeks ago.
+ const int64 nOneWeek = 7*24*60*60;
+ CAddress addr;
+ addr.ip = pnSeed[i];
+ addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek;
+ AddAddress(addr);
}
}
-
//
// Choose an address to connect to based on most recently seen
//
CAddress addrConnect;
- int64_t nBest = std::numeric_limits<int64_t>::min();
+ int64 nBest = std::numeric_limits<int64>::min();
// Only connect to one address per a.b.?.? range.
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
BOOST_FOREACH(CNode* pnode, vNodes)
setConnected.insert(pnode->addr.ip & 0x0000ffff);
- int64_t nANow = GetAdjustedTime();
+ int64 nANow = GetAdjustedTime();
CRITICAL_BLOCK(cs_mapAddresses)
{
const CAddress& addr = item.second;
if (!addr.IsIPv4() || !addr.IsValid() || setConnected.count(addr.ip & 0x0000ffff))
continue;
- int64_t nSinceLastSeen = nANow - addr.nTime;
- int64_t nSinceLastTry = nANow - addr.nLastTry;
+ int64 nSinceLastSeen = nANow - addr.nTime;
+ int64 nSinceLastTry = nANow - addr.nLastTry;
// Randomize the order in a deterministic way, putting the standard port first
- int64_t nRandomizer = (uint64_t)(nStart * 4951 + addr.nLastTry * 9567851 + addr.ip * 7789) % (2 * 60 * 60);
+ int64 nRandomizer = (uint64)(nStart * 4951 + addr.nLastTry * 9567851 + addr.ip * 7789) % (2 * 60 * 60);
if (addr.port != htons(GetDefaultPort()))
nRandomizer += 2 * 60 * 60;
// 30 days 27 hours
// 90 days 46 hours
// 365 days 93 hours
- int64_t nDelay = (int64_t)(3600.0 * sqrt(fabs((double)nSinceLastSeen) / 3600.0) + nRandomizer);
+ int64 nDelay = (int64)(3600.0 * sqrt(fabs((double)nSinceLastSeen) / 3600.0) + nRandomizer);
// Fast reconnect for one hour after last seen
if (nSinceLastSeen < 60 * 60)
// If multiple addresses are ready, prioritize by time since
// last seen and time since last tried.
- int64_t nScore = min(nSinceLastTry, (int64_t)24 * 60 * 60) - nSinceLastSeen - nRandomizer;
+ int64 nScore = min(nSinceLastTry, (int64)24 * 60 * 60) - nSinceLastSeen - nRandomizer;
if (nScore > nBest)
{
nBest = nScore;
printf("StopNode()\n");
fShutdown = true;
nTransactionsUpdated++;
- int64_t nStart = GetTime();
+ int64 nStart = GetTime();
while (vnThreadsRunning[0] > 0 || vnThreadsRunning[2] > 0 || vnThreadsRunning[3] > 0 || vnThreadsRunning[4] > 0
#ifdef USE_UPNP
|| vnThreadsRunning[5] > 0