aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-09-12 13:42:52 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-09-12 22:51:46 +0200
commit36193af47c8dcff53e59498c416b85b59e0d0f91 (patch)
tree2cd1adfafb69d6e2b6e2bf627c39048692decf0a /src
parent2b08c55f01996e0b05763f05eac50b83ba9d5a8e (diff)
[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.
Diffstat (limited to 'src')
-rw-r--r--src/kernel/chainparams.h10
-rw-r--r--src/net.cpp14
-rw-r--r--src/net.h3
3 files changed, 15 insertions, 12 deletions
diff --git a/src/kernel/chainparams.h b/src/kernel/chainparams.h
index f1df878f60..63837bb23e 100644
--- a/src/kernel/chainparams.h
+++ b/src/kernel/chainparams.h
@@ -8,7 +8,6 @@
#include <consensus/params.h>
#include <kernel/messagestartchars.h>
-#include <netaddress.h>
#include <primitives/block.h>
#include <uint256.h>
#include <util/chaintype.h>
@@ -89,15 +88,6 @@ public:
const Consensus::Params& GetConsensus() const { return consensus; }
const MessageStartChars& MessageStart() const { return pchMessageStart; }
uint16_t GetDefaultPort() const { return nDefaultPort; }
- uint16_t GetDefaultPort(Network net) const
- {
- return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
- }
- uint16_t GetDefaultPort(const std::string& addr) const
- {
- CNetAddr a;
- return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
- }
const CBlock& GenesisBlock() const { return genesis; }
/** Default value for -checkmempool and -checkblockindex argument */
diff --git a/src/net.cpp b/src/net.cpp
index 129b049269..bfa2738e45 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -470,7 +470,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
// Resolve
- const uint16_t default_port{pszDest != nullptr ? m_params.GetDefaultPort(pszDest) :
+ const uint16_t default_port{pszDest != nullptr ? GetDefaultPort(pszDest) :
m_params.GetDefaultPort()};
if (pszDest) {
const std::vector<CService> resolved{Lookup(pszDest, default_port, fNameLookup && !HaveNameProxy(), 256)};
@@ -2769,7 +2769,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
}
for (const std::string& strAddNode : lAddresses) {
- CService service(LookupNumeric(strAddNode, m_params.GetDefaultPort(strAddNode)));
+ CService service(LookupNumeric(strAddNode, GetDefaultPort(strAddNode)));
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
if (service.IsValid()) {
// strAddNode is an IP:port
@@ -3094,6 +3094,16 @@ NodeId CConnman::GetNewNodeId()
return nLastNodeId.fetch_add(1, std::memory_order_relaxed);
}
+uint16_t CConnman::GetDefaultPort(Network net) const
+{
+ return net == NET_I2P ? I2P_SAM31_PORT : m_params.GetDefaultPort();
+}
+
+uint16_t CConnman::GetDefaultPort(const std::string& addr) const
+{
+ CNetAddr a;
+ return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : m_params.GetDefaultPort();
+}
bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlags permissions)
{
diff --git a/src/net.h b/src/net.h
index eaa0fa3280..145b5cf666 100644
--- a/src/net.h
+++ b/src/net.h
@@ -1358,6 +1358,9 @@ private:
// Whether the node should be passed out in ForEach* callbacks
static bool NodeFullyConnected(const CNode* pnode);
+ uint16_t GetDefaultPort(Network net) const;
+ uint16_t GetDefaultPort(const std::string& addr) const;
+
// Network usage totals
mutable Mutex m_total_bytes_sent_mutex;
std::atomic<uint64_t> nTotalBytesRecv{0};