mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
net: remove CService::ToString() use ToStringAddrPort() instead
Both methods do the same thing, so simplify to having just one. `ToString()` is too generic in this case and it is unclear what it does, given that there are similar methods: `ToStringAddr()` (inherited from `CNetAddr`), `ToStringPort()` and `ToStringAddrPort()`.
This commit is contained in:
parent
944a9de08a
commit
96c791dd20
16 changed files with 79 additions and 86 deletions
|
@ -481,7 +481,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
|
|||
assert(infoDelete.nRefCount > 0);
|
||||
infoDelete.nRefCount--;
|
||||
vvNew[nUBucket][nUBucketPos] = -1;
|
||||
LogPrint(BCLog::ADDRMAN, "Removed %s from new[%i][%i]\n", infoDelete.ToString(), nUBucket, nUBucketPos);
|
||||
LogPrint(BCLog::ADDRMAN, "Removed %s from new[%i][%i]\n", infoDelete.ToStringAddrPort(), nUBucket, nUBucketPos);
|
||||
if (infoDelete.nRefCount == 0) {
|
||||
Delete(nIdDelete);
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
|
|||
vvNew[nUBucket][nUBucketPos] = nIdEvict;
|
||||
nNew++;
|
||||
LogPrint(BCLog::ADDRMAN, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
|
||||
infoOld.ToString(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
|
||||
infoOld.ToStringAddrPort(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
|
||||
}
|
||||
assert(vvTried[nKBucket][nKBucketPos] == -1);
|
||||
|
||||
|
@ -610,7 +610,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
|
|||
pinfo->nRefCount++;
|
||||
vvNew[nUBucket][nUBucketPos] = nId;
|
||||
LogPrint(BCLog::ADDRMAN, "Added %s mapped to AS%i to new[%i][%i]\n",
|
||||
addr.ToString(), m_netgroupman.GetMappedAS(addr), nUBucket, nUBucketPos);
|
||||
addr.ToStringAddrPort(), m_netgroupman.GetMappedAS(addr), nUBucket, nUBucketPos);
|
||||
} else {
|
||||
if (pinfo->nRefCount == 0) {
|
||||
Delete(nId);
|
||||
|
@ -661,15 +661,15 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSecond
|
|||
// Output the entry we'd be colliding with, for debugging purposes
|
||||
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
|
||||
LogPrint(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
|
||||
colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "",
|
||||
addr.ToString(),
|
||||
colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "",
|
||||
addr.ToStringAddrPort(),
|
||||
m_tried_collisions.size());
|
||||
return false;
|
||||
} else {
|
||||
// move nId to the tried tables
|
||||
MakeTried(info, nId);
|
||||
LogPrint(BCLog::ADDRMAN, "Moved %s mapped to AS%i to tried[%i][%i]\n",
|
||||
addr.ToString(), m_netgroupman.GetMappedAS(addr), tried_bucket, tried_bucket_pos);
|
||||
addr.ToStringAddrPort(), m_netgroupman.GetMappedAS(addr), tried_bucket, tried_bucket_pos);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -738,7 +738,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
|
|||
const AddrInfo& info{it_found->second};
|
||||
// With probability GetChance() * fChanceFactor, return the entry.
|
||||
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
|
||||
LogPrint(BCLog::ADDRMAN, "Selected %s from tried\n", info.ToString());
|
||||
LogPrint(BCLog::ADDRMAN, "Selected %s from tried\n", info.ToStringAddrPort());
|
||||
return {info, info.m_last_try};
|
||||
}
|
||||
// Otherwise start over with a (likely) different bucket, and increased chance factor.
|
||||
|
@ -766,7 +766,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
|
|||
const AddrInfo& info{it_found->second};
|
||||
// With probability GetChance() * fChanceFactor, return the entry.
|
||||
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
|
||||
LogPrint(BCLog::ADDRMAN, "Selected %s from new\n", info.ToString());
|
||||
LogPrint(BCLog::ADDRMAN, "Selected %s from new\n", info.ToStringAddrPort());
|
||||
return {info, info.m_last_try};
|
||||
}
|
||||
// Otherwise start over with a (likely) different bucket, and increased chance factor.
|
||||
|
@ -883,7 +883,7 @@ void AddrManImpl::ResolveCollisions_()
|
|||
|
||||
// Give address at least 60 seconds to successfully connect
|
||||
if (current_time - info_old.m_last_try > 60s) {
|
||||
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToString(), info_new.ToString());
|
||||
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToStringAddrPort(), info_new.ToStringAddrPort());
|
||||
|
||||
// Replaces an existing address already in the tried table with the new address
|
||||
Good_(info_new, false, current_time);
|
||||
|
@ -893,7 +893,7 @@ void AddrManImpl::ResolveCollisions_()
|
|||
// If the collision hasn't resolved in some reasonable amount of time,
|
||||
// just evict the old entry -- we must not be able to
|
||||
// connect to it for some reason.
|
||||
LogPrint(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToString(), info_new.ToString());
|
||||
LogPrint(BCLog::ADDRMAN, "Unable to test; replacing %s with %s in tried table anyway\n", info_old.ToStringAddrPort(), info_new.ToStringAddrPort());
|
||||
Good_(info_new, false, current_time);
|
||||
erase_collision = true;
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ static bool HTTPReq_JSONRPC(const std::any& context, HTTPRequest* req)
|
|||
|
||||
JSONRPCRequest jreq;
|
||||
jreq.context = context;
|
||||
jreq.peerAddr = req->GetPeer().ToString();
|
||||
jreq.peerAddr = req->GetPeer().ToStringAddrPort();
|
||||
if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
|
||||
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", jreq.peerAddr);
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
|
|||
// Early address-based allow check
|
||||
if (!ClientAllowed(hreq->GetPeer())) {
|
||||
LogPrint(BCLog::HTTP, "HTTP request from %s rejected: Client network is not allowed RPC access\n",
|
||||
hreq->GetPeer().ToString());
|
||||
hreq->GetPeer().ToStringAddrPort());
|
||||
hreq->WriteReply(HTTP_FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
|
@ -230,13 +230,13 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
|
|||
// Early reject unknown HTTP methods
|
||||
if (hreq->GetRequestMethod() == HTTPRequest::UNKNOWN) {
|
||||
LogPrint(BCLog::HTTP, "HTTP request from %s rejected: Unknown HTTP request method\n",
|
||||
hreq->GetPeer().ToString());
|
||||
hreq->GetPeer().ToStringAddrPort());
|
||||
hreq->WriteReply(HTTP_BAD_METHOD);
|
||||
return;
|
||||
}
|
||||
|
||||
LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
|
||||
RequestMethodString(hreq->GetRequestMethod()), SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), hreq->GetPeer().ToString());
|
||||
RequestMethodString(hreq->GetRequestMethod()), SanitizeString(hreq->GetURI(), SAFE_CHARS_URI).substr(0, 100), hreq->GetPeer().ToStringAddrPort());
|
||||
|
||||
// Find registered handler for prefix
|
||||
std::string strURI = hreq->GetURI();
|
||||
|
|
|
@ -233,7 +233,7 @@ bool Session::Connect(const CService& to, Connection& conn, bool& proxy_error)
|
|||
|
||||
throw std::runtime_error(strprintf("\"%s\"", connect_reply.full));
|
||||
} catch (const std::runtime_error& e) {
|
||||
Log("Error connecting to %s: %s", to.ToString(), e.what());
|
||||
Log("Error connecting to %s: %s", to.ToStringAddrPort(), e.what());
|
||||
CheckControlSock();
|
||||
return false;
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ std::unique_ptr<Sock> Session::Hello() const
|
|||
}
|
||||
|
||||
if (!ConnectSocketDirectly(m_control_host, *sock, nConnectTimeout, true)) {
|
||||
throw std::runtime_error(strprintf("Cannot connect to %s", m_control_host.ToString()));
|
||||
throw std::runtime_error(strprintf("Cannot connect to %s", m_control_host.ToStringAddrPort()));
|
||||
}
|
||||
|
||||
SendRequestAndGetReply(*sock, "HELLO VERSION MIN=3.1 MAX=3.1");
|
||||
|
@ -371,7 +371,7 @@ void Session::CreateIfNotCreatedAlready()
|
|||
const auto session_type = m_transient ? "transient" : "persistent";
|
||||
const auto session_id = GetRandHash().GetHex().substr(0, 10); // full is overkill, too verbose in the logs
|
||||
|
||||
Log("Creating %s SAM session %s with %s", session_type, session_id, m_control_host.ToString());
|
||||
Log("Creating %s SAM session %s with %s", session_type, session_id, m_control_host.ToStringAddrPort());
|
||||
|
||||
auto sock = Hello();
|
||||
|
||||
|
@ -408,7 +408,7 @@ void Session::CreateIfNotCreatedAlready()
|
|||
Log("%s SAM session %s created, my address=%s",
|
||||
Capitalize(session_type),
|
||||
m_session_id,
|
||||
m_my_addr.ToString());
|
||||
m_my_addr.ToStringAddrPort());
|
||||
}
|
||||
|
||||
std::unique_ptr<Sock> Session::StreamAccept()
|
||||
|
|
|
@ -104,7 +104,7 @@ static bool NatpmpMapping(natpmp_t* natpmp, const struct in_addr& external_ipv4_
|
|||
AddLocal(external, LOCAL_MAPPED);
|
||||
external_ip_discovered = true;
|
||||
}
|
||||
LogPrintf("natpmp: Port mapping successful. External address = %s\n", external.ToString());
|
||||
LogPrintf("natpmp: Port mapping successful. External address = %s\n", external.ToStringAddrPort());
|
||||
return true;
|
||||
} else {
|
||||
LogPrintf("natpmp: Port mapping failed.\n");
|
||||
|
|
42
src/net.cpp
42
src/net.cpp
|
@ -196,7 +196,7 @@ static std::vector<CAddress> ConvertSeeds(const std::vector<uint8_t> &vSeedsIn)
|
|||
s >> endpoint;
|
||||
CAddress addr{endpoint, GetDesirableServiceFlags(NODE_NONE)};
|
||||
addr.nTime = rng.rand_uniform_delay(Now<NodeSeconds>() - one_week, -one_week);
|
||||
LogPrint(BCLog::NET, "Added hardcoded seed: %s\n", addr.ToString());
|
||||
LogPrint(BCLog::NET, "Added hardcoded seed: %s\n", addr.ToStringAddrPort());
|
||||
vSeedsOut.push_back(addr);
|
||||
}
|
||||
return vSeedsOut;
|
||||
|
@ -258,7 +258,7 @@ std::optional<CService> GetLocalAddrForPeer(CNode& node)
|
|||
}
|
||||
if (addrLocal.IsRoutable() || gArgs.GetBoolArg("-addrmantest", false))
|
||||
{
|
||||
LogPrint(BCLog::NET, "Advertising address %s to peer=%d\n", addrLocal.ToString(), node.GetId());
|
||||
LogPrint(BCLog::NET, "Advertising address %s to peer=%d\n", addrLocal.ToStringAddrPort(), node.GetId());
|
||||
return addrLocal;
|
||||
}
|
||||
// Address is unroutable. Don't advertise.
|
||||
|
@ -295,7 +295,7 @@ bool AddLocal(const CService& addr_, int nScore)
|
|||
if (!IsReachable(addr))
|
||||
return false;
|
||||
|
||||
LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore);
|
||||
LogPrintf("AddLocal(%s,%i)\n", addr.ToStringAddrPort(), nScore);
|
||||
|
||||
{
|
||||
LOCK(g_maplocalhost_mutex);
|
||||
|
@ -318,7 +318,7 @@ bool AddLocal(const CNetAddr &addr, int nScore)
|
|||
void RemoveLocal(const CService& addr)
|
||||
{
|
||||
LOCK(g_maplocalhost_mutex);
|
||||
LogPrintf("RemoveLocal(%s)\n", addr.ToString());
|
||||
LogPrintf("RemoveLocal(%s)\n", addr.ToStringAddrPort());
|
||||
mapLocalHost.erase(addr);
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
|||
}
|
||||
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "trying connection %s lastseen=%.1fhrs\n",
|
||||
pszDest ? pszDest : addrConnect.ToString(),
|
||||
pszDest ? pszDest : addrConnect.ToStringAddrPort(),
|
||||
Ticks<HoursDouble>(pszDest ? 0h : Now<NodeSeconds>() - addrConnect.nTime));
|
||||
|
||||
// Resolve
|
||||
|
@ -464,7 +464,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
|||
const CService rnd{resolved[GetRand(resolved.size())]};
|
||||
addrConnect = CAddress{MaybeFlipIPv6toCJDNS(rnd), NODE_NONE};
|
||||
if (!addrConnect.IsValid()) {
|
||||
LogPrint(BCLog::NET, "Resolver returned invalid address %s for %s\n", addrConnect.ToString(), pszDest);
|
||||
LogPrint(BCLog::NET, "Resolver returned invalid address %s for %s\n", addrConnect.ToStringAddrPort(), pszDest);
|
||||
return nullptr;
|
||||
}
|
||||
// It is possible that we already have a connection to the IP/port pszDest resolved to.
|
||||
|
@ -593,7 +593,7 @@ void CNode::SetAddrLocal(const CService& addrLocalIn) {
|
|||
AssertLockNotHeld(m_addr_local_mutex);
|
||||
LOCK(m_addr_local_mutex);
|
||||
if (addrLocal.IsValid()) {
|
||||
error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToString(), addrLocalIn.ToString());
|
||||
error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToStringAddrPort(), addrLocalIn.ToStringAddrPort());
|
||||
} else {
|
||||
addrLocal = addrLocalIn;
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ void CNode::CopyStats(CNodeStats& stats)
|
|||
|
||||
// Leave string empty if addrLocal invalid (not filled in yet)
|
||||
CService addrLocalUnlocked = GetAddrLocal();
|
||||
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToString() : "";
|
||||
stats.addrLocal = addrLocalUnlocked.IsValid() ? addrLocalUnlocked.ToStringAddrPort() : "";
|
||||
|
||||
X(m_conn_type);
|
||||
}
|
||||
|
@ -967,12 +967,12 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
|||
}
|
||||
|
||||
if (!fNetworkActive) {
|
||||
LogPrint(BCLog::NET, "connection from %s dropped: not accepting new connections\n", addr.ToString());
|
||||
LogPrint(BCLog::NET, "connection from %s dropped: not accepting new connections\n", addr.ToStringAddrPort());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sock->IsSelectable()) {
|
||||
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString());
|
||||
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToStringAddrPort());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -981,14 +981,14 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
|||
const int on{1};
|
||||
if (sock->SetSockOpt(IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) == SOCKET_ERROR) {
|
||||
LogPrint(BCLog::NET, "connection from %s: unable to set TCP_NODELAY, continuing anyway\n",
|
||||
addr.ToString());
|
||||
addr.ToStringAddrPort());
|
||||
}
|
||||
|
||||
// Don't accept connections from banned peers.
|
||||
bool banned = m_banman && m_banman->IsBanned(addr);
|
||||
if (!NetPermissions::HasFlag(permission_flags, NetPermissionFlags::NoBan) && banned)
|
||||
{
|
||||
LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", addr.ToString());
|
||||
LogPrint(BCLog::NET, "connection from %s dropped (banned)\n", addr.ToStringAddrPort());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -996,7 +996,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
|||
bool discouraged = m_banman && m_banman->IsDiscouraged(addr);
|
||||
if (!NetPermissions::HasFlag(permission_flags, NetPermissionFlags::NoBan) && nInbound + 1 >= nMaxInbound && discouraged)
|
||||
{
|
||||
LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", addr.ToString());
|
||||
LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", addr.ToStringAddrPort());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1034,7 +1034,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
|||
pnode->AddRef();
|
||||
m_msgproc->InitializeNode(*pnode, nodeServices);
|
||||
|
||||
LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToString());
|
||||
LogPrint(BCLog::NET, "connection from %s accepted\n", addr.ToStringAddrPort());
|
||||
|
||||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
|
@ -1771,7 +1771,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||
!HasAllDesirableServiceFlags(addr.nServices) ||
|
||||
setConnected.count(m_netgroupman.GetGroup(addr))) continue;
|
||||
addrConnect = addr;
|
||||
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToString());
|
||||
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToStringAddrPort());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1851,7 +1851,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||
if (!interruptNet.sleep_for(rng.rand_uniform_duration<CThreadInterrupt::Clock>(FEELER_SLEEP_WINDOW))) {
|
||||
return;
|
||||
}
|
||||
LogPrint(BCLog::NET, "Making feeler connection to %s\n", addrConnect.ToString());
|
||||
LogPrint(BCLog::NET, "Making feeler connection to %s\n", addrConnect.ToStringAddrPort());
|
||||
}
|
||||
|
||||
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, conn_type);
|
||||
|
@ -2080,7 +2080,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
|
|||
socklen_t len = sizeof(sockaddr);
|
||||
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
|
||||
{
|
||||
strError = strprintf(Untranslated("Bind address family for %s not supported"), addrBind.ToString());
|
||||
strError = strprintf(Untranslated("Bind address family for %s not supported"), addrBind.ToStringAddrPort());
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original);
|
||||
return false;
|
||||
}
|
||||
|
@ -2120,13 +2120,13 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
|
|||
if (sock->Bind(reinterpret_cast<struct sockaddr*>(&sockaddr), len) == SOCKET_ERROR) {
|
||||
int nErr = WSAGetLastError();
|
||||
if (nErr == WSAEADDRINUSE)
|
||||
strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running."), addrBind.ToString(), PACKAGE_NAME);
|
||||
strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running."), addrBind.ToStringAddrPort(), PACKAGE_NAME);
|
||||
else
|
||||
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %s)"), addrBind.ToString(), NetworkErrorString(nErr));
|
||||
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %s)"), addrBind.ToStringAddrPort(), NetworkErrorString(nErr));
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original);
|
||||
return false;
|
||||
}
|
||||
LogPrintf("Bound to %s\n", addrBind.ToString());
|
||||
LogPrintf("Bound to %s\n", addrBind.ToStringAddrPort());
|
||||
|
||||
// Listen for incoming connections
|
||||
if (sock->Listen(SOMAXCONN) == SOCKET_ERROR)
|
||||
|
@ -2848,7 +2848,7 @@ void CaptureMessageToFile(const CAddress& addr,
|
|||
auto now = GetTime<std::chrono::microseconds>();
|
||||
|
||||
// Windows folder names cannot include a colon
|
||||
std::string clean_addr = addr.ToString();
|
||||
std::string clean_addr = addr.ToStringAddrPort();
|
||||
std::replace(clean_addr.begin(), clean_addr.end(), ':', '_');
|
||||
|
||||
fs::path base_path = gArgs.GetDataDirNet() / "message_capture" / fs::u8path(clean_addr);
|
||||
|
|
|
@ -1391,7 +1391,7 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)
|
|||
nonce, strSubVersion, nNodeStartingHeight, tx_relay));
|
||||
|
||||
if (fLogIPs) {
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, them=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addr_you.ToString(), tx_relay, nodeid);
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, them=%s, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addr_you.ToStringAddrPort(), tx_relay, nodeid);
|
||||
} else {
|
||||
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, txrelay=%d, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, tx_relay, nodeid);
|
||||
}
|
||||
|
@ -3217,7 +3217,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// Disconnect if we connected to ourself
|
||||
if (pfrom.IsInboundConn() && !m_connman.CheckIncomingNonce(nNonce))
|
||||
{
|
||||
LogPrintf("connected to self at %s, disconnecting\n", pfrom.addr.ToString());
|
||||
LogPrintf("connected to self at %s, disconnecting\n", pfrom.addr.ToStringAddrPort());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3344,11 +3344,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
std::string remoteAddr;
|
||||
if (fLogIPs)
|
||||
remoteAddr = ", peeraddr=" + pfrom.addr.ToString();
|
||||
remoteAddr = ", peeraddr=" + pfrom.addr.ToStringAddrPort();
|
||||
|
||||
LogPrint(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s\n",
|
||||
cleanSubVer, pfrom.nVersion,
|
||||
peer->m_starting_height, addrMe.ToString(), fRelay, pfrom.GetId(),
|
||||
peer->m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
|
||||
remoteAddr);
|
||||
|
||||
int64_t nTimeOffset = nTime - GetTime();
|
||||
|
@ -3391,7 +3391,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
if (!pfrom.IsInboundConn()) {
|
||||
LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s (%s)\n",
|
||||
pfrom.nVersion.load(), peer->m_starting_height,
|
||||
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToString()) : ""),
|
||||
pfrom.GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToStringAddrPort()) : ""),
|
||||
pfrom.ConnectionTypeAsString());
|
||||
}
|
||||
|
||||
|
|
|
@ -925,11 +925,6 @@ std::string CService::ToStringAddrPort() const
|
|||
}
|
||||
}
|
||||
|
||||
std::string CService::ToString() const
|
||||
{
|
||||
return ToStringAddrPort();
|
||||
}
|
||||
|
||||
CSubNet::CSubNet():
|
||||
valid(false)
|
||||
{
|
||||
|
|
|
@ -535,7 +535,6 @@ public:
|
|||
friend bool operator!=(const CService& a, const CService& b) { return !(a == b); }
|
||||
friend bool operator<(const CService& a, const CService& b);
|
||||
std::vector<unsigned char> GetKey() const;
|
||||
std::string ToString() const;
|
||||
std::string ToStringPort() const;
|
||||
std::string ToStringAddrPort() const;
|
||||
|
||||
|
|
|
@ -488,7 +488,7 @@ std::unique_ptr<Sock> CreateSockTCP(const CService& address_family)
|
|||
struct sockaddr_storage sockaddr;
|
||||
socklen_t len = sizeof(sockaddr);
|
||||
if (!address_family.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
|
||||
LogPrintf("Cannot create socket for %s: unsupported network\n", address_family.ToString());
|
||||
LogPrintf("Cannot create socket for %s: unsupported network\n", address_family.ToStringAddrPort());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -549,11 +549,11 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
|||
struct sockaddr_storage sockaddr;
|
||||
socklen_t len = sizeof(sockaddr);
|
||||
if (sock.Get() == INVALID_SOCKET) {
|
||||
LogPrintf("Cannot connect to %s: invalid socket\n", addrConnect.ToString());
|
||||
LogPrintf("Cannot connect to %s: invalid socket\n", addrConnect.ToStringAddrPort());
|
||||
return false;
|
||||
}
|
||||
if (!addrConnect.GetSockAddr((struct sockaddr*)&sockaddr, &len)) {
|
||||
LogPrintf("Cannot connect to %s: unsupported network\n", addrConnect.ToString());
|
||||
LogPrintf("Cannot connect to %s: unsupported network\n", addrConnect.ToStringAddrPort());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -570,11 +570,11 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
|||
Sock::Event occurred;
|
||||
if (!sock.Wait(std::chrono::milliseconds{nTimeout}, requested, &occurred)) {
|
||||
LogPrintf("wait for connect to %s failed: %s\n",
|
||||
addrConnect.ToString(),
|
||||
addrConnect.ToStringAddrPort(),
|
||||
NetworkErrorString(WSAGetLastError()));
|
||||
return false;
|
||||
} else if (occurred == 0) {
|
||||
LogPrint(BCLog::NET, "connection attempt to %s timed out\n", addrConnect.ToString());
|
||||
LogPrint(BCLog::NET, "connection attempt to %s timed out\n", addrConnect.ToStringAddrPort());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -586,13 +586,13 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
|||
socklen_t sockerr_len = sizeof(sockerr);
|
||||
if (sock.GetSockOpt(SOL_SOCKET, SO_ERROR, (sockopt_arg_type)&sockerr, &sockerr_len) ==
|
||||
SOCKET_ERROR) {
|
||||
LogPrintf("getsockopt() for %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
|
||||
LogPrintf("getsockopt() for %s failed: %s\n", addrConnect.ToStringAddrPort(), NetworkErrorString(WSAGetLastError()));
|
||||
return false;
|
||||
}
|
||||
if (sockerr != 0) {
|
||||
LogConnectFailure(manual_connection,
|
||||
"connect() to %s failed after wait: %s",
|
||||
addrConnect.ToString(),
|
||||
addrConnect.ToStringAddrPort(),
|
||||
NetworkErrorString(sockerr));
|
||||
return false;
|
||||
}
|
||||
|
@ -603,7 +603,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const Sock& sock, int nT
|
|||
else
|
||||
#endif
|
||||
{
|
||||
LogConnectFailure(manual_connection, "connect() to %s failed: %s", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
|
||||
LogConnectFailure(manual_connection, "connect() to %s failed: %s", addrConnect.ToStringAddrPort(), NetworkErrorString(WSAGetLastError()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ static RPCHelpMan getpeerinfo()
|
|||
obj.pushKV("id", stats.nodeid);
|
||||
obj.pushKV("addr", stats.m_addr_name);
|
||||
if (stats.addrBind.IsValid()) {
|
||||
obj.pushKV("addrbind", stats.addrBind.ToString());
|
||||
obj.pushKV("addrbind", stats.addrBind.ToStringAddrPort());
|
||||
}
|
||||
if (!(stats.addrLocal.empty())) {
|
||||
obj.pushKV("addrlocal", stats.addrLocal);
|
||||
|
@ -493,7 +493,7 @@ static RPCHelpMan getaddednodeinfo()
|
|||
UniValue addresses(UniValue::VARR);
|
||||
if (info.fConnected) {
|
||||
UniValue address(UniValue::VOBJ);
|
||||
address.pushKV("address", info.resolvedAddress.ToString());
|
||||
address.pushKV("address", info.resolvedAddress.ToStringAddrPort());
|
||||
address.pushKV("connected", info.fInbound ? "inbound" : "outbound");
|
||||
addresses.push_back(address);
|
||||
}
|
||||
|
|
|
@ -69,14 +69,14 @@ BOOST_AUTO_TEST_CASE(addrman_simple)
|
|||
// Test: Does Addrman respond correctly when empty.
|
||||
BOOST_CHECK_EQUAL(addrman->size(), 0U);
|
||||
auto addr_null = addrman->Select().first;
|
||||
BOOST_CHECK_EQUAL(addr_null.ToString(), "[::]:0");
|
||||
BOOST_CHECK_EQUAL(addr_null.ToStringAddrPort(), "[::]:0");
|
||||
|
||||
// Test: Does Addrman::Add work as expected.
|
||||
CService addr1 = ResolveService("250.1.1.1", 8333);
|
||||
BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source));
|
||||
BOOST_CHECK_EQUAL(addrman->size(), 1U);
|
||||
auto addr_ret1 = addrman->Select().first;
|
||||
BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:8333");
|
||||
BOOST_CHECK_EQUAL(addr_ret1.ToStringAddrPort(), "250.1.1.1:8333");
|
||||
|
||||
// Test: Does IP address deduplication work correctly.
|
||||
// Expected dup IP should not be added.
|
||||
|
@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
|
|||
BOOST_CHECK(addrman->Add({CAddress(addr1_port, NODE_NONE)}, source));
|
||||
BOOST_CHECK_EQUAL(addrman->size(), 2U);
|
||||
auto addr_ret2 = addrman->Select().first;
|
||||
BOOST_CHECK(addr_ret2.ToString() == "250.1.1.1:8333" || addr_ret2.ToString() == "250.1.1.1:8334");
|
||||
BOOST_CHECK(addr_ret2.ToStringAddrPort() == "250.1.1.1:8333" || addr_ret2.ToStringAddrPort() == "250.1.1.1:8334");
|
||||
|
||||
// Test: Add same IP but diff port to tried table; this converts the entry with
|
||||
// the specified port to tried, but not the other.
|
||||
|
@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
|
|||
BOOST_CHECK_EQUAL(addrman->size(), 2U);
|
||||
bool newOnly = true;
|
||||
auto addr_ret3 = addrman->Select(newOnly).first;
|
||||
BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:8333");
|
||||
BOOST_CHECK_EQUAL(addr_ret3.ToStringAddrPort(), "250.1.1.1:8333");
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,16 +146,16 @@ BOOST_AUTO_TEST_CASE(addrman_select)
|
|||
|
||||
bool newOnly = true;
|
||||
auto addr_ret1 = addrman->Select(newOnly).first;
|
||||
BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:8333");
|
||||
BOOST_CHECK_EQUAL(addr_ret1.ToStringAddrPort(), "250.1.1.1:8333");
|
||||
|
||||
// Test: move addr to tried, select from new expected nothing returned.
|
||||
BOOST_CHECK(addrman->Good(CAddress(addr1, NODE_NONE)));
|
||||
BOOST_CHECK_EQUAL(addrman->size(), 1U);
|
||||
auto addr_ret2 = addrman->Select(newOnly).first;
|
||||
BOOST_CHECK_EQUAL(addr_ret2.ToString(), "[::]:0");
|
||||
BOOST_CHECK_EQUAL(addr_ret2.ToStringAddrPort(), "[::]:0");
|
||||
|
||||
auto addr_ret3 = addrman->Select().first;
|
||||
BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:8333");
|
||||
BOOST_CHECK_EQUAL(addr_ret3.ToStringAddrPort(), "250.1.1.1:8333");
|
||||
|
||||
BOOST_CHECK_EQUAL(addrman->size(), 1U);
|
||||
|
||||
|
@ -714,7 +714,7 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
|
|||
BOOST_CHECK(addrman->size() == 0);
|
||||
|
||||
// Empty addrman should return blank addrman info.
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
|
||||
// Add twenty two addresses.
|
||||
CNetAddr source = ResolveIP("252.2.2.2");
|
||||
|
@ -724,7 +724,7 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
|
|||
|
||||
// No collisions in tried.
|
||||
BOOST_CHECK(addrman->Good(addr));
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
}
|
||||
|
||||
// Ensure Good handles duplicates well.
|
||||
|
@ -736,7 +736,7 @@ BOOST_AUTO_TEST_CASE(addrman_selecttriedcollision)
|
|||
BOOST_CHECK(!addrman->Good(addr));
|
||||
|
||||
// Verify duplicate address not marked as a collision.
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -758,13 +758,13 @@ BOOST_AUTO_TEST_CASE(addrman_noevict)
|
|||
CService addr36 = ResolveService("250.1.1.36");
|
||||
BOOST_CHECK(addrman->Add({CAddress(addr36, NODE_NONE)}, source));
|
||||
BOOST_CHECK(!addrman->Good(addr36));
|
||||
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToString(), "250.1.1.19:0");
|
||||
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.19:0");
|
||||
|
||||
// 36 should be discarded and 19 not evicted.
|
||||
// This means we keep 19 in the tried table and
|
||||
// 36 stays in the new table.
|
||||
addrman->ResolveCollisions();
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
|
||||
// Lets create two collisions.
|
||||
for (unsigned int i = 37; i < 59; i++) {
|
||||
|
@ -778,18 +778,18 @@ BOOST_AUTO_TEST_CASE(addrman_noevict)
|
|||
BOOST_CHECK(addrman->Add({CAddress(addr59, NODE_NONE)}, source));
|
||||
BOOST_CHECK(!addrman->Good(addr59));
|
||||
|
||||
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToString(), "250.1.1.10:0");
|
||||
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.10:0");
|
||||
|
||||
// Cause a second collision in the new table.
|
||||
BOOST_CHECK(!addrman->Add({CAddress(addr36, NODE_NONE)}, source));
|
||||
|
||||
// 36 still cannot be moved from new to tried due to colliding with 19
|
||||
BOOST_CHECK(!addrman->Good(addr36));
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() != "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() != "[::]:0");
|
||||
|
||||
// Resolve all collisions.
|
||||
addrman->ResolveCollisions();
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
||||
|
@ -799,7 +799,7 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
|||
BOOST_CHECK(addrman->size() == 0);
|
||||
|
||||
// Empty addrman should return blank addrman info.
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
|
||||
// Add 35 addresses
|
||||
CNetAddr source = ResolveIP("252.2.2.2");
|
||||
|
@ -817,7 +817,7 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
|||
BOOST_CHECK(!addrman->Good(addr));
|
||||
|
||||
auto info = addrman->SelectTriedCollision().first;
|
||||
BOOST_CHECK_EQUAL(info.ToString(), "250.1.1.19:0");
|
||||
BOOST_CHECK_EQUAL(info.ToStringAddrPort(), "250.1.1.19:0");
|
||||
|
||||
// Ensure test of address fails, so that it is evicted.
|
||||
// Update entry in tried by setting last good connection in the deep past.
|
||||
|
@ -826,7 +826,7 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
|||
|
||||
// Should swap 36 for 19.
|
||||
addrman->ResolveCollisions();
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
AddressPosition addr_pos{addrman->FindAddressEntry(CAddress(addr, NODE_NONE)).value()};
|
||||
BOOST_CHECK(addr_pos.tried);
|
||||
|
||||
|
@ -835,18 +835,18 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
|||
// We check this by verifying Good() returns false and also verifying that
|
||||
// we have no collisions.
|
||||
BOOST_CHECK(!addrman->Good(addr));
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
|
||||
// 19 should fail as a collision (not a duplicate) if we now attempt to move
|
||||
// it to the tried table.
|
||||
CService addr19 = ResolveService("250.1.1.19");
|
||||
BOOST_CHECK(!addrman->Good(addr19));
|
||||
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToString(), "250.1.1.36:0");
|
||||
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.36:0");
|
||||
|
||||
// Eviction is also successful if too much time has passed since last try
|
||||
SetMockTime(GetTime() + 4 * 60 *60);
|
||||
addrman->ResolveCollisions();
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToString() == "[::]:0");
|
||||
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
|
||||
//Now 19 is in tried again, and 36 back to new
|
||||
AddressPosition addr_pos19{addrman->FindAddressEntry(CAddress(addr19, NODE_NONE)).value()};
|
||||
BOOST_CHECK(addr_pos19.tried);
|
||||
|
|
|
@ -59,7 +59,7 @@ FUZZ_TARGET(http_request)
|
|||
const std::string body = http_request.ReadBody();
|
||||
assert(body.empty());
|
||||
const CService service = http_request.GetPeer();
|
||||
assert(service.ToString() == "[::]:0");
|
||||
assert(service.ToStringAddrPort() == "[::]:0");
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
evhttp_request_free(evreq);
|
||||
|
|
|
@ -79,7 +79,6 @@ FUZZ_TARGET(netaddress)
|
|||
const CService service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
|
||||
(void)service.GetKey();
|
||||
(void)service.GetPort();
|
||||
(void)service.ToString();
|
||||
(void)service.ToStringAddrPort();
|
||||
(void)service.ToStringPort();
|
||||
(void)CServiceHash()(service);
|
||||
|
|
|
@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(netbase_splithost)
|
|||
bool static TestParse(std::string src, std::string canon)
|
||||
{
|
||||
CService addr(LookupNumeric(src, 65535));
|
||||
return canon == addr.ToString();
|
||||
return canon == addr.ToStringAddrPort();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(netbase_lookupnumeric)
|
||||
|
|
|
@ -421,7 +421,7 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
|
|||
return;
|
||||
}
|
||||
service = LookupNumeric(std::string(service_id+".onion"), Params().GetDefaultPort());
|
||||
LogPrintfCategory(BCLog::TOR, "Got service ID %s, advertising service %s\n", service_id, service.ToString());
|
||||
LogPrintfCategory(BCLog::TOR, "Got service ID %s, advertising service %s\n", service_id, service.ToStringAddrPort());
|
||||
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
|
||||
LogPrint(BCLog::TOR, "Cached service private key to %s\n", fs::PathToString(GetPrivateKeyFile()));
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue