Skip to content

Commit 36193af

Browse files
committed
[refactor] Remove netaddress.h from kernel headers
Move functions requiring the netaddress.h include out of libbitcoinkernel source files. The netaddress.h file contains many non-consensus related definitions and should thus not be part of the libbitcoinkernel. This commit makes netaddress.h no longer a required include for users of the libbitcoinkernel. This commit is part of the libbitcoinkernel project, namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel.
1 parent 2b08c55 commit 36193af

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/kernel/chainparams.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <consensus/params.h>
1010
#include <kernel/messagestartchars.h>
11-
#include <netaddress.h>
1211
#include <primitives/block.h>
1312
#include <uint256.h>
1413
#include <util/chaintype.h>
@@ -89,15 +88,6 @@ class CChainParams
8988
const Consensus::Params& GetConsensus() const { return consensus; }
9089
const MessageStartChars& MessageStart() const { return pchMessageStart; }
9190
uint16_t GetDefaultPort() const { return nDefaultPort; }
92-
uint16_t GetDefaultPort(Network net) const
93-
{
94-
return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
95-
}
96-
uint16_t GetDefaultPort(const std::string& addr) const
97-
{
98-
CNetAddr a;
99-
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
100-
}
10191

10292
const CBlock& GenesisBlock() const { return genesis; }
10393
/** Default value for -checkmempool and -checkblockindex argument */

src/net.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
470470
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
471471

472472
// Resolve
473-
const uint16_t default_port{pszDest != nullptr ? m_params.GetDefaultPort(pszDest) :
473+
const uint16_t default_port{pszDest != nullptr ? GetDefaultPort(pszDest) :
474474
m_params.GetDefaultPort()};
475475
if (pszDest) {
476476
const std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
@@ -2769,7 +2769,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
27692769
}
27702770

27712771
for (const std::string& strAddNode : lAddresses) {
2772-
CService service(LookupNumeric(strAddNode, m_params.GetDefaultPort(strAddNode)));
2772+
CService service(LookupNumeric(strAddNode, GetDefaultPort(strAddNode)));
27732773
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
27742774
if (service.IsValid()) {
27752775
// strAddNode is an IP:port
@@ -3094,6 +3094,16 @@ NodeId CConnman::GetNewNodeId()
30943094
return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
30953095
}
30963096

3097+
uint16_t CConnman::GetDefaultPort(Network net) const
3098+
{
3099+
return net == NET_I2P ? I2P_SAM31_PORT : m_params.GetDefaultPort();
3100+
}
3101+
3102+
uint16_t CConnman::GetDefaultPort(const std::string& addr) const
3103+
{
3104+
CNetAddr a;
3105+
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : m_params.GetDefaultPort();
3106+
}
30973107

30983108
bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlags permissions)
30993109
{

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,9 @@ class CConnman
13581358
// Whether the node should be passed out in ForEach* callbacks
13591359
static bool NodeFullyConnected(const CNode* pnode);
13601360

1361+
uint16_t GetDefaultPort(Network net) const;
1362+
uint16_t GetDefaultPort(const std::string& addr) const;
1363+
13611364
// Network usage totals
13621365
mutable Mutex m_total_bytes_sent_mutex;
13631366
std::atomic<uint64_t> nTotalBytesRecv{0};

0 commit comments

Comments
 (0)