mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge #21328: net, refactor: pass uint16 CService::port as uint16
52dd40a9fetest: add missing netaddress include headers (Jon Atack)6f09c0f6b5util: add missing braces and apply clang format to SplitHostPort() (Jon Atack)2875a764f7util: add ParseUInt16(), use it in SplitHostPort() (Jon Atack)6423c8175fp2p, refactor: pass and use uint16_t CService::port as uint16_t (Jon Atack) Pull request description: As noticed during review today in https://github.com/bitcoin/bitcoin/pull/20685#discussion_r584873708 of the upcoming I2P network support, `CService::port` is `uint16_t` but is passed around the codebase and into the ctors as `int`, which causes uneeded conversions and casts. We can avoid these (including in the incoming I2P code without further changes to it) by using ports with the correct type. The remaining conversions are pushed out to the user input boundaries where they can be range-checked and raise with user feedback in the next patch. ACKs for top commit: practicalswift: cr ACK52dd40a9fe: patch looks correct MarcoFalke: cr ACK52dd40a9fevasild: ACK52dd40a9feTree-SHA512: 203c1cab3189a206c55ecada77b9548b810281cdc533252b8e3330ae0606b467731c75f730ce9deb07cbaab66facf97e1ffd2051084ff9077cba6750366b0432
This commit is contained in:
@@ -113,7 +113,7 @@ void CConnman::AddAddrFetch(const std::string& strDest)
|
||||
|
||||
uint16_t GetListenPort()
|
||||
{
|
||||
return (uint16_t)(gArgs.GetArg("-port", Params().GetDefaultPort()));
|
||||
return static_cast<uint16_t>(gArgs.GetArg("-port", Params().GetDefaultPort()));
|
||||
}
|
||||
|
||||
// find 'best' local address for a particular peer
|
||||
@@ -394,7 +394,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
|
||||
|
||||
// Resolve
|
||||
const int default_port = Params().GetDefaultPort();
|
||||
const uint16_t default_port{Params().GetDefaultPort()};
|
||||
if (pszDest) {
|
||||
std::vector<CService> resolved;
|
||||
if (Lookup(pszDest, resolved, default_port, fNameLookup && !HaveNameProxy(), 256) && !resolved.empty()) {
|
||||
@@ -462,7 +462,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||
return nullptr;
|
||||
}
|
||||
std::string host;
|
||||
int port = default_port;
|
||||
uint16_t port{default_port};
|
||||
SplitHostPort(std::string(pszDest), port, host);
|
||||
bool proxyConnectionFailed;
|
||||
connected = ConnectThroughProxy(proxy, host, port, *sock, nConnectTimeout,
|
||||
|
||||
Reference in New Issue
Block a user