scripted-diff: LogPrintLevel(*,BCLog::Level::*,*) -> LogError()/LogWarning()

This is a minimal behavior change and changes log output from:

  [net:error] Something bad happened
  [net:warning] Something problematic happened

to either

  [error] Something bad happened
  [warning] Something problematic happened

or, when -loglevelalways=1 is enabled:

  [all:error] Something bad happened
  [all:warning] Something problematic happened

Such a behavior change is desired, because all warning and error logs
are written in the same style in the source code and they are logged in
the same format for log consumers.

-BEGIN VERIFY SCRIPT-

 sed --regexp-extended --in-place \
   's/LogPrintLevel\((BCLog::[^,]*), BCLog::Level::(Error|Warning), */Log\2(/g' \
   $( git grep -l LogPrintLevel ':(exclude)src/test/logging_tests.cpp' )

-END VERIFY SCRIPT-
This commit is contained in:
MarcoFalke committed 2025-12-09 10:44:33 +01:00
1 parent fa6c7a1954
commit fa89f60e31
9 files changed
+44 -44

No files matched your search

+9 -9
View File
@@ -73,7 +73,7 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
// Create a netlink socket. // Create a netlink socket.
auto sock{CreateSock(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)}; auto sock{CreateSock(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)};
if (!sock) { if (!sock) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "socket(AF_NETLINK): %s\n", NetworkErrorString(errno)); LogError("socket(AF_NETLINK): %s\n", NetworkErrorString(errno));
return std::nullopt; return std::nullopt;
} }
@@ -110,7 +110,7 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
request.dst_hdr.nla_len = sizeof(nlattr) + dst_data_len; request.dst_hdr.nla_len = sizeof(nlattr) + dst_data_len;
if (sock->Send(&request, request.hdr.nlmsg_len, 0) != static_cast<ssize_t>(request.hdr.nlmsg_len)) { if (sock->Send(&request, request.hdr.nlmsg_len, 0) != static_cast<ssize_t>(request.hdr.nlmsg_len)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "send() to netlink socket: %s\n", NetworkErrorString(errno)); LogError("send() to netlink socket: %s\n", NetworkErrorString(errno));
return std::nullopt; return std::nullopt;
} }
@@ -124,13 +124,13 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
recv_result = sock->Recv(response, sizeof(response), 0); recv_result = sock->Recv(response, sizeof(response), 0);
} while (recv_result < 0 && (errno == EINTR || errno == EAGAIN)); } while (recv_result < 0 && (errno == EINTR || errno == EAGAIN));
if (recv_result < 0) { if (recv_result < 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "recv() from netlink socket: %s\n", NetworkErrorString(errno)); LogError("recv() from netlink socket: %s\n", NetworkErrorString(errno));
return std::nullopt; return std::nullopt;
} }
total_bytes_read += recv_result; total_bytes_read += recv_result;
if (total_bytes_read > NETLINK_MAX_RESPONSE_SIZE) { if (total_bytes_read > NETLINK_MAX_RESPONSE_SIZE) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "Netlink response exceeded size limit (%zu bytes, family=%d)\n", NETLINK_MAX_RESPONSE_SIZE, family); LogWarning("Netlink response exceeded size limit (%zu bytes, family=%d)\n", NETLINK_MAX_RESPONSE_SIZE, family);
return std::nullopt; return std::nullopt;
} }
@@ -200,7 +200,7 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
destination_address.si_family = family; destination_address.si_family = family;
status = GetBestInterfaceEx((sockaddr*)&destination_address, &best_if_idx); status = GetBestInterfaceEx((sockaddr*)&destination_address, &best_if_idx);
if (status != NO_ERROR) { if (status != NO_ERROR) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Could not get best interface for default route: %s\n", NetworkErrorString(status)); LogError("Could not get best interface for default route: %s\n", NetworkErrorString(status));
return std::nullopt; return std::nullopt;
} }
@@ -208,7 +208,7 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
// Leave interface_luid at all-zeros to use interface index instead. // Leave interface_luid at all-zeros to use interface index instead.
status = GetBestRoute2(&interface_luid, best_if_idx, nullptr, &destination_address, 0, &best_route, &best_source_address); status = GetBestRoute2(&interface_luid, best_if_idx, nullptr, &destination_address, 0, &best_route, &best_source_address);
if (status != NO_ERROR) { if (status != NO_ERROR) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Could not get best route for default route for interface index %d: %s\n", LogError("Could not get best route for default route for interface index %d: %s\n",
best_if_idx, NetworkErrorString(status)); best_if_idx, NetworkErrorString(status));
return std::nullopt; return std::nullopt;
} }
@@ -235,12 +235,12 @@ std::optional<CNetAddr> QueryDefaultGatewayImpl(sa_family_t family)
// The size of the available data is determined by calling sysctl() with oldp=nullptr. See sysctl(3). // The size of the available data is determined by calling sysctl() with oldp=nullptr. See sysctl(3).
size_t l = 0; size_t l = 0;
if (sysctl(/*name=*/mib, /*namelen=*/sizeof(mib) / sizeof(int), /*oldp=*/nullptr, /*oldlenp=*/&l, /*newp=*/nullptr, /*newlen=*/0) < 0) { if (sysctl(/*name=*/mib, /*namelen=*/sizeof(mib) / sizeof(int), /*oldp=*/nullptr, /*oldlenp=*/&l, /*newp=*/nullptr, /*newlen=*/0) < 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Could not get sysctl length of routing table: %s\n", SysErrorString(errno)); LogError("Could not get sysctl length of routing table: %s\n", SysErrorString(errno));
return std::nullopt; return std::nullopt;
} }
std::vector<std::byte> buf(l); std::vector<std::byte> buf(l);
if (sysctl(/*name=*/mib, /*namelen=*/sizeof(mib) / sizeof(int), /*oldp=*/buf.data(), /*oldlenp=*/&l, /*newp=*/nullptr, /*newlen=*/0) < 0) { if (sysctl(/*name=*/mib, /*namelen=*/sizeof(mib) / sizeof(int), /*oldp=*/buf.data(), /*oldlenp=*/&l, /*newp=*/nullptr, /*newlen=*/0) < 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Could not get sysctl data of routing table: %s\n", SysErrorString(errno)); LogError("Could not get sysctl data of routing table: %s\n", SysErrorString(errno));
return std::nullopt; return std::nullopt;
} }
// Iterate over messages (each message is a routing table entry). // Iterate over messages (each message is a routing table entry).
@@ -340,7 +340,7 @@ std::vector<CNetAddr> GetLocalAddresses()
if (status != NO_ERROR) { if (status != NO_ERROR) {
// This includes ERROR_NO_DATA if there are no addresses and thus there's not even one PIP_ADAPTER_ADDRESSES // This includes ERROR_NO_DATA if there are no addresses and thus there's not even one PIP_ADAPTER_ADDRESSES
// record in the returned structure. // record in the returned structure.
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Could not get local adapter addresses: %s\n", NetworkErrorString(status)); LogError("Could not get local adapter addresses: %s\n", NetworkErrorString(status));
return addresses; return addresses;
} }
+20 -20
View File
@@ -243,7 +243,7 @@ std::optional<std::vector<uint8_t>> PCPSendRecv(Sock &sock, const std::string &p
if (interrupt) return std::nullopt; if (interrupt) return std::nullopt;
Sock::Event occurred = 0; Sock::Event occurred = 0;
if (!sock.Wait(deadline - cur_time, Sock::RECV, &occurred)) { if (!sock.Wait(deadline - cur_time, Sock::RECV, &occurred)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "%s: Could not wait on socket: %s\n", protocol, NetworkErrorString(WSAGetLastError())); LogWarning("%s: Could not wait on socket: %s\n", protocol, NetworkErrorString(WSAGetLastError()));
return std::nullopt; // Network-level error, probably no use retrying. return std::nullopt; // Network-level error, probably no use retrying.
} }
if (!occurred) { if (!occurred) {
@@ -288,13 +288,13 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
// Create IPv4 UDP socket // Create IPv4 UDP socket
auto sock{CreateSock(AF_INET, SOCK_DGRAM, IPPROTO_UDP)}; auto sock{CreateSock(AF_INET, SOCK_DGRAM, IPPROTO_UDP)};
if (!sock) { if (!sock) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Could not create UDP socket: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("natpmp: Could not create UDP socket: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
// Associate UDP socket to gateway. // Associate UDP socket to gateway.
if (sock->Connect((struct sockaddr*)&dest_addr, dest_addrlen) != 0) { if (sock->Connect((struct sockaddr*)&dest_addr, dest_addrlen) != 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Could not connect to gateway: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("natpmp: Could not connect to gateway: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
@@ -302,7 +302,7 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
struct sockaddr_in internal; struct sockaddr_in internal;
socklen_t internal_addrlen = sizeof(struct sockaddr_in); socklen_t internal_addrlen = sizeof(struct sockaddr_in);
if (sock->GetSockName((struct sockaddr*)&internal, &internal_addrlen) != 0) { if (sock->GetSockName((struct sockaddr*)&internal, &internal_addrlen) != 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Could not get sock name: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("natpmp: Could not get sock name: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
@@ -314,11 +314,11 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
auto recv_res = PCPSendRecv(*sock, "natpmp", request, num_tries, timeout_per_try, auto recv_res = PCPSendRecv(*sock, "natpmp", request, num_tries, timeout_per_try,
[&](const std::span<const uint8_t> response) -> bool { [&](const std::span<const uint8_t> response) -> bool {
if (response.size() < NATPMP_GETEXTERNAL_RESPONSE_SIZE) { if (response.size() < NATPMP_GETEXTERNAL_RESPONSE_SIZE) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Response too small\n"); LogWarning("natpmp: Response too small\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
if (response[NATPMP_HDR_VERSION_OFS] != NATPMP_VERSION || response[NATPMP_HDR_OP_OFS] != (NATPMP_RESPONSE | NATPMP_OP_GETEXTERNAL)) { if (response[NATPMP_HDR_VERSION_OFS] != NATPMP_VERSION || response[NATPMP_HDR_OP_OFS] != (NATPMP_RESPONSE | NATPMP_OP_GETEXTERNAL)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Response to wrong command\n"); LogWarning("natpmp: Response to wrong command\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
return true; return true;
@@ -332,7 +332,7 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
Assume(response.size() >= NATPMP_GETEXTERNAL_RESPONSE_SIZE); Assume(response.size() >= NATPMP_GETEXTERNAL_RESPONSE_SIZE);
uint16_t result_code = ReadBE16(response.data() + NATPMP_RESPONSE_HDR_RESULT_OFS); uint16_t result_code = ReadBE16(response.data() + NATPMP_RESPONSE_HDR_RESULT_OFS);
if (result_code != NATPMP_RESULT_SUCCESS) { if (result_code != NATPMP_RESULT_SUCCESS) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Getting external address failed with result %s\n", NATPMPResultString(result_code)); LogWarning("natpmp: Getting external address failed with result %s\n", NATPMPResultString(result_code));
return MappingError::PROTOCOL_ERROR; return MappingError::PROTOCOL_ERROR;
} }
@@ -352,16 +352,16 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
recv_res = PCPSendRecv(*sock, "natpmp", request, num_tries, timeout_per_try, recv_res = PCPSendRecv(*sock, "natpmp", request, num_tries, timeout_per_try,
[&](const std::span<const uint8_t> response) -> bool { [&](const std::span<const uint8_t> response) -> bool {
if (response.size() < NATPMP_MAP_RESPONSE_SIZE) { if (response.size() < NATPMP_MAP_RESPONSE_SIZE) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Response too small\n"); LogWarning("natpmp: Response too small\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
if (response[0] != NATPMP_VERSION || response[1] != (NATPMP_RESPONSE | NATPMP_OP_MAP_TCP)) { if (response[0] != NATPMP_VERSION || response[1] != (NATPMP_RESPONSE | NATPMP_OP_MAP_TCP)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Response to wrong command\n"); LogWarning("natpmp: Response to wrong command\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
uint16_t internal_port = ReadBE16(response.data() + NATPMP_MAP_RESPONSE_INTERNAL_PORT_OFS); uint16_t internal_port = ReadBE16(response.data() + NATPMP_MAP_RESPONSE_INTERNAL_PORT_OFS);
if (internal_port != port) { if (internal_port != port) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Response port doesn't match request\n"); LogWarning("natpmp: Response port doesn't match request\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
return true; return true;
@@ -374,7 +374,7 @@ std::variant<MappingResult, MappingError> NATPMPRequestPortMap(const CNetAddr &g
Assume(response.size() >= NATPMP_MAP_RESPONSE_SIZE); Assume(response.size() >= NATPMP_MAP_RESPONSE_SIZE);
uint16_t result_code = ReadBE16(response.data() + NATPMP_RESPONSE_HDR_RESULT_OFS); uint16_t result_code = ReadBE16(response.data() + NATPMP_RESPONSE_HDR_RESULT_OFS);
if (result_code != NATPMP_RESULT_SUCCESS) { if (result_code != NATPMP_RESULT_SUCCESS) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: Port mapping failed with result %s\n", NATPMPResultString(result_code)); LogWarning("natpmp: Port mapping failed with result %s\n", NATPMPResultString(result_code));
if (result_code == NATPMP_RESULT_NO_RESOURCES) { if (result_code == NATPMP_RESULT_NO_RESOURCES) {
return MappingError::NO_RESOURCES; return MappingError::NO_RESOURCES;
} }
@@ -404,20 +404,20 @@ std::variant<MappingResult, MappingError> PCPRequestPortMap(const PCPMappingNonc
// Create UDP socket (IPv4 or IPv6 based on provided gateway). // Create UDP socket (IPv4 or IPv6 based on provided gateway).
auto sock{CreateSock(dest_addr.ss_family, SOCK_DGRAM, IPPROTO_UDP)}; auto sock{CreateSock(dest_addr.ss_family, SOCK_DGRAM, IPPROTO_UDP)};
if (!sock) { if (!sock) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Could not create UDP socket: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("pcp: Could not create UDP socket: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
// Make sure that we send from requested destination address, anything else will be // Make sure that we send from requested destination address, anything else will be
// rejected by a security-conscious router. // rejected by a security-conscious router.
if (sock->Bind((struct sockaddr*)&bind_addr, bind_addrlen) != 0) { if (sock->Bind((struct sockaddr*)&bind_addr, bind_addrlen) != 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Could not bind to address: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("pcp: Could not bind to address: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
// Associate UDP socket to gateway. // Associate UDP socket to gateway.
if (sock->Connect((struct sockaddr*)&dest_addr, dest_addrlen) != 0) { if (sock->Connect((struct sockaddr*)&dest_addr, dest_addrlen) != 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Could not connect to gateway: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("pcp: Could not connect to gateway: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
@@ -427,7 +427,7 @@ std::variant<MappingResult, MappingError> PCPRequestPortMap(const PCPMappingNonc
struct sockaddr_storage internal_addr; struct sockaddr_storage internal_addr;
socklen_t internal_addrlen = sizeof(struct sockaddr_storage); socklen_t internal_addrlen = sizeof(struct sockaddr_storage);
if (sock->GetSockName((struct sockaddr*)&internal_addr, &internal_addrlen) != 0) { if (sock->GetSockName((struct sockaddr*)&internal_addr, &internal_addrlen) != 0) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Could not get sock name: %s\n", NetworkErrorString(WSAGetLastError())); LogWarning("pcp: Could not get sock name: %s\n", NetworkErrorString(WSAGetLastError()));
return MappingError::NETWORK_ERROR; return MappingError::NETWORK_ERROR;
} }
CService internal; CService internal;
@@ -469,23 +469,23 @@ std::variant<MappingResult, MappingError> PCPRequestPortMap(const PCPMappingNonc
return true; // Let it through to caller. return true; // Let it through to caller.
} }
if (response.size() < (PCP_HDR_SIZE + PCP_MAP_SIZE)) { if (response.size() < (PCP_HDR_SIZE + PCP_MAP_SIZE)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Response too small\n"); LogWarning("pcp: Response too small\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
if (response[PCP_HDR_VERSION_OFS] != PCP_VERSION || response[PCP_HDR_OP_OFS] != (PCP_RESPONSE | PCP_OP_MAP)) { if (response[PCP_HDR_VERSION_OFS] != PCP_VERSION || response[PCP_HDR_OP_OFS] != (PCP_RESPONSE | PCP_OP_MAP)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Response to wrong command\n"); LogWarning("pcp: Response to wrong command\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
// Handle MAP opcode response. See RFC6887 Figure 10. // Handle MAP opcode response. See RFC6887 Figure 10.
// Check that returned mapping nonce matches our request. // Check that returned mapping nonce matches our request.
if (!std::ranges::equal(response.subspan(PCP_HDR_SIZE + PCP_MAP_NONCE_OFS, PCP_MAP_NONCE_SIZE), nonce)) { if (!std::ranges::equal(response.subspan(PCP_HDR_SIZE + PCP_MAP_NONCE_OFS, PCP_MAP_NONCE_SIZE), nonce)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Mapping nonce mismatch\n"); LogWarning("pcp: Mapping nonce mismatch\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
uint8_t protocol = response[PCP_HDR_SIZE + 12]; uint8_t protocol = response[PCP_HDR_SIZE + 12];
uint16_t internal_port = ReadBE16(response.data() + PCP_HDR_SIZE + 16); uint16_t internal_port = ReadBE16(response.data() + PCP_HDR_SIZE + 16);
if (protocol != PCP_PROTOCOL_TCP || internal_port != port) { if (protocol != PCP_PROTOCOL_TCP || internal_port != port) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Response protocol or port doesn't match request\n"); LogWarning("pcp: Response protocol or port doesn't match request\n");
return false; // Wasn't response to what we expected, try receiving next packet. return false; // Wasn't response to what we expected, try receiving next packet.
} }
return true; return true;
@@ -508,7 +508,7 @@ std::variant<MappingResult, MappingError> PCPRequestPortMap(const PCPMappingNonc
uint16_t external_port = ReadBE16(response.data() + PCP_HDR_SIZE + PCP_MAP_EXTERNAL_PORT_OFS); uint16_t external_port = ReadBE16(response.data() + PCP_HDR_SIZE + PCP_MAP_EXTERNAL_PORT_OFS);
CNetAddr external_addr{PCPUnwrapAddress(response.subspan(PCP_HDR_SIZE + PCP_MAP_EXTERNAL_IP_OFS, ADDR_IPV6_SIZE))}; CNetAddr external_addr{PCPUnwrapAddress(response.subspan(PCP_HDR_SIZE + PCP_MAP_EXTERNAL_IP_OFS, ADDR_IPV6_SIZE))};
if (result_code != PCP_RESULT_SUCCESS) { if (result_code != PCP_RESULT_SUCCESS) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "pcp: Mapping failed with result %s\n", PCPResultString(result_code)); LogWarning("pcp: Mapping failed with result %s\n", PCPResultString(result_code));
if (result_code == PCP_RESULT_NO_RESOURCES) { if (result_code == PCP_RESULT_NO_RESOURCES) {
return MappingError::NO_RESOURCES; return MappingError::NO_RESOURCES;
} }
+1 -1
View File
@@ -149,7 +149,7 @@ bool Session::Listen(Connection& conn)
conn.sock = StreamAccept(); conn.sock = StreamAccept();
return true; return true;
} catch (const std::runtime_error& e) { } catch (const std::runtime_error& e) {
LogPrintLevel(BCLog::I2P, BCLog::Level::Error, "Couldn't listen: %s\n", e.what()); LogError("Couldn't listen: %s\n", e.what());
CheckControlSock(); CheckControlSock();
} }
return false; return false;
+2 -2
View File
@@ -100,12 +100,12 @@ static void ProcessPCP()
// Log message if we got NO_RESOURCES. // Log message if we got NO_RESOURCES.
if (no_resources) { if (no_resources) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "portmap: At least one mapping failed because of a NO_RESOURCES error. This usually indicates that the port is already used on the router. If this is the only instance of bitcoin running on the network, this will resolve itself automatically. Otherwise, you might want to choose a different P2P port to prevent this conflict.\n"); LogWarning("portmap: At least one mapping failed because of a NO_RESOURCES error. This usually indicates that the port is already used on the router. If this is the only instance of bitcoin running on the network, this will resolve itself automatically. Otherwise, you might want to choose a different P2P port to prevent this conflict.\n");
} }
// Sanity-check returned lifetime. // Sanity-check returned lifetime.
if (actual_lifetime < 30) { if (actual_lifetime < 30) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "portmap: Got impossibly short mapping lifetime of %d seconds\n", actual_lifetime); LogWarning("portmap: Got impossibly short mapping lifetime of %d seconds\n", actual_lifetime);
return; return;
} }
// RFC6887 11.2.1 recommends that clients send their first renewal packet at a time chosen with uniform random // RFC6887 11.2.1 recommends that clients send their first renewal packet at a time chosen with uniform random
+6 -6
View File
@@ -369,7 +369,7 @@ static CService GetBindAddress(const Sock& sock)
if (!sock.GetSockName((struct sockaddr*)&sockaddr_bind, &sockaddr_bind_len)) { if (!sock.GetSockName((struct sockaddr*)&sockaddr_bind, &sockaddr_bind_len)) {
addr_bind.SetSockAddr((const struct sockaddr*)&sockaddr_bind, sockaddr_bind_len); addr_bind.SetSockAddr((const struct sockaddr*)&sockaddr_bind, sockaddr_bind_len);
} else { } else {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "getsockname failed\n"); LogWarning("getsockname failed\n");
} }
return addr_bind; return addr_bind;
} }
@@ -1746,7 +1746,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
CService addr; CService addr;
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr, len)) { if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr, len)) {
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "Unknown socket family\n"); LogWarning("Unknown socket family\n");
} else { } else {
addr = MaybeFlipIPv6toCJDNS(addr); addr = MaybeFlipIPv6toCJDNS(addr);
} }
@@ -3143,14 +3143,14 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len)) if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
{ {
strError = Untranslated(strprintf("Bind address family for %s not supported", addrBind.ToStringAddrPort())); strError = Untranslated(strprintf("Bind address family for %s not supported", addrBind.ToStringAddrPort()));
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original); LogError("%s\n", strError.original);
return false; return false;
} }
std::unique_ptr<Sock> sock = CreateSock(addrBind.GetSAFamily(), SOCK_STREAM, IPPROTO_TCP); std::unique_ptr<Sock> sock = CreateSock(addrBind.GetSAFamily(), SOCK_STREAM, IPPROTO_TCP);
if (!sock) { if (!sock) {
strError = Untranslated(strprintf("Couldn't open socket for incoming connections (socket returned error %s)", NetworkErrorString(WSAGetLastError()))); strError = Untranslated(strprintf("Couldn't open socket for incoming connections (socket returned error %s)", NetworkErrorString(WSAGetLastError())));
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original); LogError("%s\n", strError.original);
return false; return false;
} }
@@ -3185,7 +3185,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running."), addrBind.ToStringAddrPort(), CLIENT_NAME); strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running."), addrBind.ToStringAddrPort(), CLIENT_NAME);
else else
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %s)"), addrBind.ToStringAddrPort(), 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); LogError("%s\n", strError.original);
return false; return false;
} }
LogInfo("Bound to %s\n", addrBind.ToStringAddrPort()); LogInfo("Bound to %s\n", addrBind.ToStringAddrPort());
@@ -3194,7 +3194,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
if (sock->Listen(SOMAXCONN) == SOCKET_ERROR) if (sock->Listen(SOMAXCONN) == SOCKET_ERROR)
{ {
strError = strprintf(_("Listening for incoming connections failed (listen returned error %s)"), NetworkErrorString(WSAGetLastError())); strError = strprintf(_("Listening for incoming connections failed (listen returned error %s)"), NetworkErrorString(WSAGetLastError()));
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original); LogError("%s\n", strError.original);
return false; return false;
} }
+2 -2
View File
@@ -650,7 +650,7 @@ std::unique_ptr<Sock> ConnectDirectly(const CService& dest, bool manual_connecti
{ {
auto sock = CreateSock(dest.GetSAFamily(), SOCK_STREAM, IPPROTO_TCP); auto sock = CreateSock(dest.GetSAFamily(), SOCK_STREAM, IPPROTO_TCP);
if (!sock) { if (!sock) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Cannot create a socket for connecting to %s\n", dest.ToStringAddrPort()); LogError("Cannot create a socket for connecting to %s\n", dest.ToStringAddrPort());
return {}; return {};
} }
@@ -678,7 +678,7 @@ std::unique_ptr<Sock> Proxy::Connect() const
#ifdef HAVE_SOCKADDR_UN #ifdef HAVE_SOCKADDR_UN
auto sock = CreateSock(AF_UNIX, SOCK_STREAM, 0); auto sock = CreateSock(AF_UNIX, SOCK_STREAM, 0);
if (!sock) { if (!sock) {
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "Cannot create a socket for connecting to %s\n", m_unix_socket_path); LogError("Cannot create a socket for connecting to %s\n", m_unix_socket_path);
return {}; return {};
} }
+2 -2
View File
@@ -863,7 +863,7 @@ FlatFilePos BlockManager::FindNextBlockPos(unsigned int nAddSize, unsigned int n
// a reindex. A flush error might also leave some of the data files // a reindex. A flush error might also leave some of the data files
// untrimmed. // untrimmed.
if (!FlushBlockFile(last_blockfile, /*fFinalize=*/true, finalize_undo)) { if (!FlushBlockFile(last_blockfile, /*fFinalize=*/true, finalize_undo)) {
LogPrintLevel(BCLog::BLOCKSTORAGE, BCLog::Level::Warning, LogWarning(
"Failed to flush previous block file %05i (finalize=1, finalize_undo=%i) before opening new block file %05i\n", "Failed to flush previous block file %05i (finalize=1, finalize_undo=%i) before opening new block file %05i\n",
last_blockfile, finalize_undo, nFile); last_blockfile, finalize_undo, nFile);
} }
@@ -987,7 +987,7 @@ bool BlockManager::WriteBlockUndo(const CBlockUndo& blockundo, BlockValidationSt
// fact it is. Note though, that a failed flush might leave the data // fact it is. Note though, that a failed flush might leave the data
// file untrimmed. // file untrimmed.
if (!FlushUndoFile(pos.nFile, true)) { if (!FlushUndoFile(pos.nFile, true)) {
LogPrintLevel(BCLog::BLOCKSTORAGE, BCLog::Level::Warning, "Failed to flush undo file %05i\n", pos.nFile); LogWarning("Failed to flush undo file %05i\n", pos.nFile);
} }
} else if (pos.nFile == cursor.file_num && block.nHeight > cursor.undo_height) { } else if (pos.nFile == cursor.file_num && block.nHeight > cursor.undo_height) {
cursor.undo_height = block.nHeight; cursor.undo_height = block.nHeight;
+1 -1
View File
@@ -102,7 +102,7 @@ bool CCoinsViewDB::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &hashB
std::vector<uint256> old_heads = GetHeadBlocks(); std::vector<uint256> old_heads = GetHeadBlocks();
if (old_heads.size() == 2) { if (old_heads.size() == 2) {
if (old_heads[0] != hashBlock) { if (old_heads[0] != hashBlock) {
LogPrintLevel(BCLog::COINDB, BCLog::Level::Error, "The coins database detected an inconsistent state, likely due to a previous crash or shutdown. You will need to restart bitcoind with the -reindex-chainstate or -reindex configuration option.\n"); LogError("The coins database detected an inconsistent state, likely due to a previous crash or shutdown. You will need to restart bitcoind with the -reindex-chainstate or -reindex configuration option.\n");
} }
assert(old_heads[0] == hashBlock); assert(old_heads[0] == hashBlock);
old_tip = old_heads[1]; old_tip = old_heads[1];
+1 -1
View File
@@ -2798,7 +2798,7 @@ bool Chainstate::FlushStateToDisk(
// TODO: Handle return error, or add detailed comment why it is // TODO: Handle return error, or add detailed comment why it is
// safe to not return an error upon failure. // safe to not return an error upon failure.
if (!m_blockman.FlushChainstateBlockFile(m_chain.Height())) { if (!m_blockman.FlushChainstateBlockFile(m_chain.Height())) {
LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Warning, "%s: Failed to flush block file.\n", __func__); LogWarning("%s: Failed to flush block file.\n", __func__);
} }
} }