New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: Modernize logging in UPnP and nat-pmp code #29978
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -54,7 +54,7 @@ static bool NatpmpInit(natpmp_t* natpmp) | |||
{ | |||
const int r_init = initnatpmp(natpmp, /* detect gateway automatically */ 0, /* forced gateway - NOT APPLIED*/ 0); | |||
if (r_init == 0) return true; | |||
LogPrintf("natpmp: initnatpmp() failed with %d error.\n", r_init); | |||
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: initnatpmp() failed with %d error.\n", r_init); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the message states it's an error, but the level is warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've mentioned this in my post: these are intentionally logged at Warning level as port mapping failures are not generally considered very serious problems, there's no reason to unnecessarily worry users about them
@@ -72,12 +72,12 @@ static bool NatpmpDiscover(natpmp_t* natpmp, struct in_addr& external_ipv4_addr) | |||
external_ipv4_addr = response.pnu.publicaddress.addr; | |||
return true; | |||
} else if (r_read == NATPMP_ERR_NOGATEWAYSUPPORT) { | |||
LogPrintf("natpmp: The gateway does not support NAT-PMP.\n"); | |||
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "natpmp: The gateway does not support NAT-PMP.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the condition error code indicates this should also be an error
@@ -192,21 +192,21 @@ static bool ProcessUpnp() | |||
|
|||
if (r != UPNPCOMMAND_SUCCESS) { | |||
ret = false; | |||
LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port, port, lanaddr, r, strupnperror(r)); | |||
LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "UPnP: AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port, port, lanaddr, r, strupnperror(r)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was the message changed on purpose to confirm to the rest of the logs?
Shouldn't we rather remove the prefixes now that the category is specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this was on purpose. i've kept the prefix because nat-pmp and UPnP messages should be distinguishable.
} else { | ||
if (externalIPAddress[0]) { | ||
std::optional<CNetAddr> resolved{LookupHost(externalIPAddress, false)}; | ||
if (resolved.has_value()) { | ||
LogPrintf("UPnP: ExternalIPAddress = %s\n", resolved->ToStringAddr()); | ||
LogPrintLevel(BCLog::NET, BCLog::Level::Info, "UPnP: ExternalIPAddress = %s\n", resolved->ToStringAddr()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these should probably be debugs, if they're spammy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no reason to believe this message is spammy. Mind that it was logged as an unconditional message, and no one ever complained (this one is also reasonably important).
Concept ACK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dunno, i prefer being explicit and not using macros myself TBH, what would macros add? At least more cognitive overload ("what macro to use here"). The way it's done now, it's clear where the messages come from and what their level is. i'm fine with changing if you really insist. But as you say, it isn't even possible with the current ones. |
Honestly, on second thought, i don't feel like repeating this argument. i'll do everyone a favor and close this. |
What #29256 proposes is that you'd be able to do exactly that with the shorthand |
Thanks, i'll keep it in mind.
No need for apologies ! you're right, i don't know what has been discussed when i was gone, i should not be doing things like this, besides there's more serious things to work on 😄 |
i’m looking at this code anyway for #17012, so thought i’d might just as well modernize the logging:
NET
(comes closest imo-because the mapping is for P2P)