aboutsummaryrefslogtreecommitdiff
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
parent457754d2c24f7e53c55f4b68155a5fa702552327 (diff)
Keep port information for local addresses
-rw-r--r--src/irc.cpp2
-rw-r--r--src/net.cpp26
-rw-r--r--src/net.h23
3 files changed, 29 insertions, 22 deletions
diff --git a/src/irc.cpp b/src/irc.cpp
index f20152495e..525bd7a8da 100644
--- a/src/irc.cpp
+++ b/src/irc.cpp
@@ -246,7 +246,7 @@ void ThreadIRCSeed2(void* parg)
return;
}
- CNetAddr addrLocal;
+ CService addrLocal;
string strMyName;
if (GetLocal(addrLocal, &addrConnect))
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
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;
diff --git a/src/net.h b/src/net.h
index be167b001f..398b89dcfc 100644
--- a/src/net.h
+++ b/src/net.h
@@ -44,22 +44,23 @@ bool StopNode();
enum
{
- LOCAL_NONE,
- LOCAL_IF,
- LOCAL_UPNP,
- LOCAL_IRC,
- LOCAL_HTTP,
- LOCAL_MANUAL,
+ LOCAL_NONE, // unknown
+ LOCAL_IF, // address a local interface listens on
+ LOCAL_UPNP, // address reported by UPnP
+ LOCAL_IRC, // address reported by IRC (deprecated)
+ LOCAL_HTTP, // address reported by whatismyip.com and similars
+ LOCAL_MANUAL, // address explicitly specified (-externalip=)
LOCAL_MAX
};
void SetLimited(enum Network net, bool fLimited = true);
bool IsLimited(const CNetAddr& addr);
-bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
-bool SeenLocal(const CNetAddr& addr);
-bool IsLocal(const CNetAddr& addr);
-bool GetLocal(CNetAddr &addr, const CNetAddr *paddrPeer = NULL);
+bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
+bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE, int port = -1);
+bool SeenLocal(const CService& addr);
+bool IsLocal(const CService& addr);
+bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
bool IsReachable(const CNetAddr &addr);
CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);
@@ -142,7 +143,7 @@ public:
unsigned int nMessageStart;
CAddress addr;
std::string addrName;
- CNetAddr addrLocal;
+ CService addrLocal;
int nVersion;
std::string strSubVer;
bool fOneShot;