@@ -206,15 +206,13 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
206
206
// Otherwise, return the unroutable 0.0.0.0 but filled in with
207
207
// the normal parameters, since the IP may be changed to a useful
208
208
// one by discovery.
209
- CAddress GetLocalAddress (const CNetAddr *paddrPeer, ServiceFlags nLocalServices )
209
+ CService GetLocalAddress (const CNetAddr& addrPeer )
210
210
{
211
- CAddress ret ( CService ( CNetAddr (),GetListenPort ()), nLocalServices) ;
211
+ CService ret{ CNetAddr (), GetListenPort ()} ;
212
212
CService addr;
213
- if (GetLocal (addr, paddrPeer))
214
- {
215
- ret = CAddress (addr, nLocalServices);
213
+ if (GetLocal (addr, &addrPeer)) {
214
+ ret = CService{addr};
216
215
}
217
- ret.nTime = GetAdjustedTime ();
218
216
return ret;
219
217
}
220
218
@@ -233,35 +231,35 @@ bool IsPeerAddrLocalGood(CNode *pnode)
233
231
IsReachable (addrLocal.GetNetwork ());
234
232
}
235
233
236
- std::optional<CAddress > GetLocalAddrForPeer (CNode *pnode )
234
+ std::optional<CService > GetLocalAddrForPeer (CNode& node )
237
235
{
238
- CAddress addrLocal = GetLocalAddress (&pnode-> addr , pnode-> GetLocalServices ()) ;
236
+ CService addrLocal{ GetLocalAddress (node. addr )} ;
239
237
if (gArgs .GetBoolArg (" -addrmantest" , false )) {
240
238
// use IPv4 loopback during addrmantest
241
- addrLocal = CAddress ( CService (LookupNumeric (" 127.0.0.1" , GetListenPort ())), pnode-> GetLocalServices ( ));
239
+ addrLocal = CService (LookupNumeric (" 127.0.0.1" , GetListenPort ()));
242
240
}
243
241
// If discovery is enabled, sometimes give our peer the address it
244
242
// tells us that it sees us as in case it has a better idea of our
245
243
// address than we do.
246
244
FastRandomContext rng;
247
- if (IsPeerAddrLocalGood (pnode ) && (!addrLocal.IsRoutable () ||
245
+ if (IsPeerAddrLocalGood (&node ) && (!addrLocal.IsRoutable () ||
248
246
rng.randbits ((GetnScore (addrLocal) > LOCAL_MANUAL) ? 3 : 1 ) == 0 ))
249
247
{
250
- if (pnode-> IsInboundConn ()) {
248
+ if (node. IsInboundConn ()) {
251
249
// For inbound connections, assume both the address and the port
252
250
// as seen from the peer.
253
- addrLocal = CAddress{pnode-> GetAddrLocal (), addrLocal. nServices , addrLocal. nTime };
251
+ addrLocal = CService{node. GetAddrLocal ()};
254
252
} else {
255
253
// For outbound connections, assume just the address as seen from
256
254
// the peer and leave the port in `addrLocal` as returned by
257
255
// `GetLocalAddress()` above. The peer has no way to observe our
258
256
// listening port when we have initiated the connection.
259
- addrLocal.SetIP (pnode-> GetAddrLocal ());
257
+ addrLocal.SetIP (node. GetAddrLocal ());
260
258
}
261
259
}
262
260
if (addrLocal.IsRoutable () || gArgs .GetBoolArg (" -addrmantest" , false ))
263
261
{
264
- LogPrint (BCLog::NET, " Advertising address %s to peer=%d\n " , addrLocal.ToString (), pnode-> GetId ());
262
+ LogPrint (BCLog::NET, " Advertising address %s to peer=%d\n " , addrLocal.ToString (), node. GetId ());
265
263
return addrLocal;
266
264
}
267
265
// Address is unroutable. Don't advertise.
@@ -543,7 +541,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
543
541
addr_bind = GetBindAddress (*sock);
544
542
}
545
543
CNode* pnode = new CNode (id,
546
- nLocalServices,
547
544
std::move (sock),
548
545
addrConnect,
549
546
CalculateKeyedNetGroup (addrConnect),
@@ -603,7 +600,6 @@ Network CNode::ConnectedThroughNetwork() const
603
600
void CNode::CopyStats (CNodeStats& stats)
604
601
{
605
602
stats.nodeid = this ->GetId ();
606
- X (nServices);
607
603
X (addr);
608
604
X (addrBind);
609
605
stats.m_network = ConnectedThroughNetwork ();
@@ -880,7 +876,7 @@ bool CConnman::AttemptToEvictConnection()
880
876
.m_min_ping_time = node->m_min_ping_time ,
881
877
.m_last_block_time = node->m_last_block_time ,
882
878
.m_last_tx_time = node->m_last_tx_time ,
883
- .fRelevantServices = HasAllDesirableServiceFlags ( node->nServices ) ,
879
+ .fRelevantServices = node->m_has_all_wanted_services ,
884
880
.m_relay_txs = node->m_relays_txs .load (),
885
881
.fBloomFilter = node->m_bloom_filter_loaded .load (),
886
882
.nKeyedNetGroup = node->nKeyedNetGroup ,
@@ -1014,7 +1010,6 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
1014
1010
1015
1011
const bool inbound_onion = std::find (m_onion_binds.begin (), m_onion_binds.end (), addr_bind) != m_onion_binds.end ();
1016
1012
CNode* pnode = new CNode (id,
1017
- nodeServices,
1018
1013
std::move (sock),
1019
1014
addr,
1020
1015
CalculateKeyedNetGroup (addr),
@@ -1026,7 +1021,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
1026
1021
pnode->AddRef ();
1027
1022
pnode->m_permissionFlags = permissionFlags;
1028
1023
pnode->m_prefer_evict = discouraged;
1029
- m_msgproc->InitializeNode (pnode);
1024
+ m_msgproc->InitializeNode (* pnode, nodeServices );
1030
1025
1031
1026
LogPrint (BCLog::NET, " connection from %s accepted\n " , addr.ToString ());
1032
1027
@@ -1964,7 +1959,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
1964
1959
if (grantOutbound)
1965
1960
grantOutbound->MoveTo (pnode->grantOutbound );
1966
1961
1967
- m_msgproc->InitializeNode (pnode);
1962
+ m_msgproc->InitializeNode (* pnode, nLocalServices );
1968
1963
{
1969
1964
LOCK (m_nodes_mutex);
1970
1965
m_nodes.push_back (pnode);
@@ -2708,7 +2703,10 @@ ServiceFlags CConnman::GetLocalServices() const
2708
2703
2709
2704
unsigned int CConnman::GetReceiveFloodSize () const { return nReceiveFloodSize; }
2710
2705
2711
- CNode::CNode (NodeId idIn, ServiceFlags nLocalServicesIn, std::shared_ptr<Sock> sock, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
2706
+ CNode::CNode (NodeId idIn, std::shared_ptr<Sock> sock, const CAddress& addrIn,
2707
+ uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn,
2708
+ const CAddress& addrBindIn, const std::string& addrNameIn,
2709
+ ConnectionType conn_type_in, bool inbound_onion)
2712
2710
: m_sock{sock},
2713
2711
m_connected{GetTime<std::chrono::seconds>()},
2714
2712
addr (addrIn),
@@ -2718,8 +2716,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, std::shared_ptr<Sock> s
2718
2716
nKeyedNetGroup(nKeyedNetGroupIn),
2719
2717
id(idIn),
2720
2718
nLocalHostNonce(nLocalHostNonceIn),
2721
- m_conn_type(conn_type_in),
2722
- nLocalServices(nLocalServicesIn)
2719
+ m_conn_type(conn_type_in)
2723
2720
{
2724
2721
if (inbound_onion) assert (conn_type_in == ConnectionType::INBOUND);
2725
2722
0 commit comments