@@ -46,7 +46,7 @@ bool fClient = false;
46
46
static bool fUseUPnP = false ;
47
47
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK);
48
48
static CCriticalSection cs_mapLocalHost;
49
- static map<CNetAddr , int > mapLocalHost;
49
+ static map<CService , int > mapLocalHost;
50
50
static bool vfReachable[NET_MAX] = {};
51
51
static bool vfLimited[NET_MAX] = {};
52
52
static CNode* pnodeLocalHost = NULL ;
@@ -96,7 +96,7 @@ void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd)
96
96
}
97
97
98
98
// find 'best' local address for a particular peer
99
- bool GetLocal (CNetAddr & addr, const CNetAddr *paddrPeer)
99
+ bool GetLocal (CService & addr, const CNetAddr *paddrPeer)
100
100
{
101
101
if (fUseProxy || mapArgs.count (" -connect" ) || fNoListen )
102
102
return false ;
@@ -105,7 +105,7 @@ bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer)
105
105
int nBestReachability = -1 ;
106
106
{
107
107
LOCK (cs_mapLocalHost);
108
- for (map<CNetAddr , int >::iterator it = mapLocalHost.begin (); it != mapLocalHost.end (); it++)
108
+ for (map<CService , int >::iterator it = mapLocalHost.begin (); it != mapLocalHost.end (); it++)
109
109
{
110
110
int nCount = (*it).second ;
111
111
int nReachability = (*it).first .GetReachabilityFrom (paddrPeer);
@@ -124,11 +124,10 @@ bool GetLocal(CNetAddr& addr, const CNetAddr *paddrPeer)
124
124
CAddress GetLocalAddress (const CNetAddr *paddrPeer)
125
125
{
126
126
CAddress ret (CService (" 0.0.0.0" ,0 ),0 );
127
- CNetAddr addr;
127
+ CService addr;
128
128
if (GetLocal (addr, paddrPeer))
129
129
{
130
- ret.SetIP (addr);
131
- ret.SetPort (GetListenPort ());
130
+ ret = CAddress (addr);
132
131
ret.nServices = nLocalServices;
133
132
ret.nTime = GetAdjustedTime ();
134
133
}
@@ -196,7 +195,7 @@ void static AdvertizeLocal()
196
195
if (pnode->fSuccessfullyConnected )
197
196
{
198
197
CAddress addrLocal = GetLocalAddress (&pnode->addr );
199
- if (addrLocal.IsRoutable () && (CNetAddr )addrLocal != (CNetAddr )pnode->addrLocal )
198
+ if (addrLocal.IsRoutable () && (CService )addrLocal != (CService )pnode->addrLocal )
200
199
{
201
200
pnode->PushAddress (addrLocal);
202
201
pnode->addrLocal = addrLocal;
@@ -206,7 +205,7 @@ void static AdvertizeLocal()
206
205
}
207
206
208
207
// learn a new local address
209
- bool AddLocal (const CNetAddr & addr, int nScore)
208
+ bool AddLocal (const CService & addr, int nScore)
210
209
{
211
210
if (!addr.IsRoutable ())
212
211
return false ;
@@ -226,6 +225,13 @@ bool AddLocal(const CNetAddr& addr, int nScore)
226
225
return true ;
227
226
}
228
227
228
+ bool AddLocal (const CNetAddr& addr, int nScore, int port)
229
+ {
230
+ if (port == -1 )
231
+ port = GetListenPort ();
232
+ return AddLocal (CService (addr, port), nScore);
233
+ }
234
+
229
235
/* * Make a particular network entirely off-limits (no automatic connects to it) */
230
236
void SetLimited (enum Network net, bool fLimited )
231
237
{
@@ -240,7 +246,7 @@ bool IsLimited(const CNetAddr& addr)
240
246
}
241
247
242
248
/* * vote for a local address */
243
- bool SeenLocal (const CNetAddr & addr)
249
+ bool SeenLocal (const CService & addr)
244
250
{
245
251
{
246
252
LOCK (cs_mapLocalHost);
@@ -255,7 +261,7 @@ bool SeenLocal(const CNetAddr& addr)
255
261
}
256
262
257
263
/* * check whether a given address is potentially local */
258
- bool IsLocal (const CNetAddr & addr)
264
+ bool IsLocal (const CService & addr)
259
265
{
260
266
LOCK (cs_mapLocalHost);
261
267
return mapLocalHost.count (addr) > 0 ;
0 commit comments