mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes. Replace int typedefs with int##_t from stdint.h. Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h. Normalize QT_VERSION ifs where possible. Resolve some indirect dependencies as direct ones. Remove extern declarations from .cpp files.
This commit is contained in:
62
src/net.cpp
62
src/net.cpp
@@ -7,32 +7,34 @@
|
||||
#include "bitcoin-config.h"
|
||||
#endif
|
||||
|
||||
#include "chainparams.h"
|
||||
#include "db.h"
|
||||
#include "net.h"
|
||||
#include "core.h"
|
||||
|
||||
#include "addrman.h"
|
||||
#include "chainparams.h"
|
||||
#include "core.h"
|
||||
#include "db.h"
|
||||
#include "ui_interface.h"
|
||||
#include "script.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPNP
|
||||
#include <miniupnpc/miniwget.h>
|
||||
#include <miniupnpc/miniupnpc.h>
|
||||
#include <miniupnpc/miniwget.h>
|
||||
#include <miniupnpc/upnpcommands.h>
|
||||
#include <miniupnpc/upnperrors.h>
|
||||
#endif
|
||||
|
||||
// Dump addresses to peers.dat every 15 minutes (900s)
|
||||
#define DUMP_ADDRESSES_INTERVAL 900
|
||||
#if !defined(HAVE_MSG_NOSIGNAL)
|
||||
|
||||
#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
@@ -53,14 +55,14 @@ struct LocalServiceInfo {
|
||||
// Global state variables
|
||||
//
|
||||
bool fDiscover = true;
|
||||
uint64 nLocalServices = NODE_NETWORK;
|
||||
uint64_t nLocalServices = NODE_NETWORK;
|
||||
static CCriticalSection cs_mapLocalHost;
|
||||
static map<CNetAddr, LocalServiceInfo> mapLocalHost;
|
||||
static bool vfReachable[NET_MAX] = {};
|
||||
static bool vfLimited[NET_MAX] = {};
|
||||
static CNode* pnodeLocalHost = NULL;
|
||||
static CNode* pnodeSync = NULL;
|
||||
uint64 nLocalHostNonce = 0;
|
||||
uint64_t nLocalHostNonce = 0;
|
||||
static std::vector<SOCKET> vhListenSocket;
|
||||
CAddrMan addrman;
|
||||
int nMaxConnections = 125;
|
||||
@@ -68,9 +70,9 @@ int nMaxConnections = 125;
|
||||
vector<CNode*> vNodes;
|
||||
CCriticalSection cs_vNodes;
|
||||
map<CInv, CDataStream> mapRelay;
|
||||
deque<pair<int64, CInv> > vRelayExpiration;
|
||||
deque<pair<int64_t, CInv> > vRelayExpiration;
|
||||
CCriticalSection cs_mapRelay;
|
||||
limitedmap<CInv, int64> mapAlreadyAskedFor(MAX_INV_SZ);
|
||||
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
|
||||
|
||||
static deque<string> vOneShots;
|
||||
CCriticalSection cs_vOneShots;
|
||||
@@ -426,8 +428,8 @@ void AddressCurrentlyConnected(const CService& addr)
|
||||
|
||||
|
||||
|
||||
uint64 CNode::nTotalBytesRecv = 0;
|
||||
uint64 CNode::nTotalBytesSent = 0;
|
||||
uint64_t CNode::nTotalBytesRecv = 0;
|
||||
uint64_t CNode::nTotalBytesSent = 0;
|
||||
CCriticalSection CNode::cs_totalBytesRecv;
|
||||
CCriticalSection CNode::cs_totalBytesSent;
|
||||
|
||||
@@ -545,7 +547,7 @@ void CNode::PushVersion()
|
||||
int nBestHeight = g_signals.GetHeight().get_value_or(0);
|
||||
|
||||
/// when NTP implemented, change to just nTime = GetAdjustedTime()
|
||||
int64 nTime = (fInbound ? GetAdjustedTime() : GetTime());
|
||||
int64_t nTime = (fInbound ? GetAdjustedTime() : GetTime());
|
||||
CAddress addrYou = (addr.IsRoutable() && !IsProxy(addr) ? addr : CAddress(CService("0.0.0.0",0)));
|
||||
CAddress addrMe = GetLocalAddress(&addr);
|
||||
RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));
|
||||
@@ -558,7 +560,7 @@ void CNode::PushVersion()
|
||||
|
||||
|
||||
|
||||
std::map<CNetAddr, int64> CNode::setBanned;
|
||||
std::map<CNetAddr, int64_t> CNode::setBanned;
|
||||
CCriticalSection CNode::cs_setBanned;
|
||||
|
||||
void CNode::ClearBanned()
|
||||
@@ -571,10 +573,10 @@ bool CNode::IsBanned(CNetAddr ip)
|
||||
bool fResult = false;
|
||||
{
|
||||
LOCK(cs_setBanned);
|
||||
std::map<CNetAddr, int64>::iterator i = setBanned.find(ip);
|
||||
std::map<CNetAddr, int64_t>::iterator i = setBanned.find(ip);
|
||||
if (i != setBanned.end())
|
||||
{
|
||||
int64 t = (*i).second;
|
||||
int64_t t = (*i).second;
|
||||
if (GetTime() < t)
|
||||
fResult = true;
|
||||
}
|
||||
@@ -593,7 +595,7 @@ bool CNode::Misbehaving(int howmuch)
|
||||
nMisbehavior += howmuch;
|
||||
if (nMisbehavior >= GetArg("-banscore", 100))
|
||||
{
|
||||
int64 banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
|
||||
int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
|
||||
LogPrintf("Misbehaving: %s (%d -> %d) DISCONNECTING\n", addr.ToString().c_str(), nMisbehavior-howmuch, nMisbehavior);
|
||||
{
|
||||
LOCK(cs_setBanned);
|
||||
@@ -631,7 +633,7 @@ void CNode::copyStats(CNodeStats &stats)
|
||||
// since pingtime does not update until the ping is complete, which might take a while.
|
||||
// So, if a ping is taking an unusually long time in flight,
|
||||
// the caller can immediately detect that this is happening.
|
||||
int64 nPingUsecWait = 0;
|
||||
int64_t nPingUsecWait = 0;
|
||||
if ((0 != nPingNonceSent) && (0 != nPingUsecStart)) {
|
||||
nPingUsecWait = GetTimeMicros() - nPingUsecStart;
|
||||
}
|
||||
@@ -1252,12 +1254,12 @@ void ThreadDNSAddressSeed()
|
||||
|
||||
void DumpAddresses()
|
||||
{
|
||||
int64 nStart = GetTimeMillis();
|
||||
int64_t nStart = GetTimeMillis();
|
||||
|
||||
CAddrDB adb;
|
||||
adb.Write(addrman);
|
||||
|
||||
LogPrint("net", "Flushed %d addresses to peers.dat %"PRI64d"ms\n",
|
||||
LogPrint("net", "Flushed %d addresses to peers.dat %"PRId64"ms\n",
|
||||
addrman.size(), GetTimeMillis() - nStart);
|
||||
}
|
||||
|
||||
@@ -1284,7 +1286,7 @@ void ThreadOpenConnections()
|
||||
// Connect to specific addresses
|
||||
if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0)
|
||||
{
|
||||
for (int64 nLoop = 0;; nLoop++)
|
||||
for (int64_t nLoop = 0;; nLoop++)
|
||||
{
|
||||
ProcessOneShot();
|
||||
BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"])
|
||||
@@ -1301,7 +1303,7 @@ void ThreadOpenConnections()
|
||||
}
|
||||
|
||||
// Initiate network connections
|
||||
int64 nStart = GetTime();
|
||||
int64_t nStart = GetTime();
|
||||
while (true)
|
||||
{
|
||||
ProcessOneShot();
|
||||
@@ -1340,7 +1342,7 @@ void ThreadOpenConnections()
|
||||
}
|
||||
}
|
||||
|
||||
int64 nANow = GetAdjustedTime();
|
||||
int64_t nANow = GetAdjustedTime();
|
||||
|
||||
int nTries = 0;
|
||||
while (true)
|
||||
@@ -1885,25 +1887,25 @@ void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataSt
|
||||
}
|
||||
}
|
||||
|
||||
void CNode::RecordBytesRecv(uint64 bytes)
|
||||
void CNode::RecordBytesRecv(uint64_t bytes)
|
||||
{
|
||||
LOCK(cs_totalBytesRecv);
|
||||
nTotalBytesRecv += bytes;
|
||||
}
|
||||
|
||||
void CNode::RecordBytesSent(uint64 bytes)
|
||||
void CNode::RecordBytesSent(uint64_t bytes)
|
||||
{
|
||||
LOCK(cs_totalBytesSent);
|
||||
nTotalBytesSent += bytes;
|
||||
}
|
||||
|
||||
uint64 CNode::GetTotalBytesRecv()
|
||||
uint64_t CNode::GetTotalBytesRecv()
|
||||
{
|
||||
LOCK(cs_totalBytesRecv);
|
||||
return nTotalBytesRecv;
|
||||
}
|
||||
|
||||
uint64 CNode::GetTotalBytesSent()
|
||||
uint64_t CNode::GetTotalBytesSent()
|
||||
{
|
||||
LOCK(cs_totalBytesSent);
|
||||
return nTotalBytesSent;
|
||||
|
||||
Reference in New Issue
Block a user