aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-05-10 20:35:13 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-11 15:29:19 +0200
commit7fa4443f77a659031e277337770b506fcf954d69 (patch)
tree9464645df0c9ed33668586fe924d4c02e54ec1a1 /src/net.cpp
parent457754d2c24f7e53c55f4b68155a5fa702552327 (diff)
downloadbitcoin-7fa4443f77a659031e277337770b506fcf954d69.tar.xz
Keep port information for local addresses
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 79d0a8ddbc..a43b76d79c 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -46,7 +46,7 @@ bool fClient = false;
static bool fUseUPnP = false;
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK);
static CCriticalSection cs_mapLocalHost;
-static map<CNetAddr, int> mapLocalHost;
+static map<CService, int> mapLocalHost;
static bool vfReachable[NET_MAX] = {};
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
@@ -96,7 +96,7 @@ void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd)
}
// find 'best' local address for a particular peer
-bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer)
+bool GetLocal(CService& addr, const CNetAddr *paddrPeer)
{
if (fUseProxy || mapArgs.count("-connect") || fNoListen)
return false;
@@ -105,7 +105,7 @@ bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer)
int nBestReachability = -1;
{
LOCK(cs_mapLocalHost);
- for (map<CNetAddr, int>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++)
+ for (map<CService, int>::iterator it = mapLocalHost.begin(); it != mapLocalHost.end(); it++)
{
int nCount = (*it).second;
int nReachability = (*it).first.GetReachabilityFrom(paddrPeer);
@@ -124,11 +124,10 @@ bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer)
CAddress GetLocalAddress(const CNetAddr *paddrPeer)
{
CAddress ret(CService("0.0.0.0",0),0);
- CNetAddr addr;
+ CService addr;
if (GetLocal(addr, paddrPeer))
{
- ret.SetIP(addr);
- ret.SetPort(GetListenPort());
+ ret = CAddress(addr);
ret.nServices = nLocalServices;
ret.nTime = GetAdjustedTime();
}
@@ -196,7 +195,7 @@ void static AdvertizeLocal()
if (pnode->fSuccessfullyConnected)
{
CAddress addrLocal = GetLocalAddress(&pnode->addr);
- if (addrLocal.IsRoutable() && (CNetAddr)addrLocal != (CNetAddr)pnode->addrLocal)
+ if (addrLocal.IsRoutable() && (CService)addrLocal != (CService)pnode->addrLocal)
{
pnode->PushAddress(addrLocal);
pnode->addrLocal = addrLocal;
@@ -206,7 +205,7 @@ void static AdvertizeLocal()
}
// learn a new local address
-bool AddLocal(const CNetAddr& addr, int nScore)
+bool AddLocal(const CService& addr, int nScore)
{
if (!addr.IsRoutable())
return false;
@@ -226,6 +225,13 @@ bool AddLocal(const CNetAddr& addr, int nScore)
return true;
}
+bool AddLocal(const CNetAddr& addr, int nScore, int port)
+{
+ if (port == -1)
+ port = GetListenPort();
+ return AddLocal(CService(addr, port), nScore);
+}
+
/** Make a particular network entirely off-limits (no automatic connects to it) */
void SetLimited(enum Network net, bool fLimited)
{
@@ -240,7 +246,7 @@ bool IsLimited(const CNetAddr& addr)
}
/** vote for a local address */
-bool SeenLocal(const CNetAddr& addr)
+bool SeenLocal(const CService& addr)
{
{
LOCK(cs_mapLocalHost);
@@ -255,7 +261,7 @@ bool SeenLocal(const CNetAddr& addr)
}
/** check whether a given address is potentially local */
-bool IsLocal(const CNetAddr& addr)
+bool IsLocal(const CService& addr)
{
LOCK(cs_mapLocalHost);
return mapLocalHost.count(addr) > 0;