Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

laanwj
Copy link
Member

@laanwj laanwj commented Apr 27, 2024

i’m looking at this code anyway for #17012, so thought i’d might just as well modernize the logging:

  • Use log level and log category NET (comes closest imo-because the mapping is for P2P)
    • Port mapping errors are logged to Warning category instead of Error, because they’re not fatal, and not generally considered very serious problems.
  • Prefix UPnP and natpmp messages consistently.

@laanwj laanwj added the P2P label Apr 27, 2024
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 27, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK brunoerg, stickies-v

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29641 (scripted-diff: Use LogInfo/LogDebug over LogPrintf/LogPrint by maflcko)

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.

Copy link
Contributor

@paplorinc paplorinc left a 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);
Copy link
Contributor

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

Copy link
Member Author

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");
Copy link
Contributor

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));
Copy link
Contributor

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?

Copy link
Member Author

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());
Copy link
Contributor

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

Copy link
Member Author

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).

@brunoerg
Copy link
Contributor

Concept ACK

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, but it's probably better to use the new macros introduced in #28318? Currently, the conditional macros (which this PR would need) don't take a category parameter, but if you think that's important perhaps it'd be good to chime in on the conversation on #29256.

@laanwj
Copy link
Member Author

laanwj commented Apr 30, 2024

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.

@laanwj
Copy link
Member Author

laanwj commented Apr 30, 2024

Honestly, on second thought, i don't feel like repeating this argument. i'll do everyone a favor and close this.

@laanwj laanwj closed this Apr 30, 2024
@stickies-v
Copy link
Contributor

stickies-v commented Apr 30, 2024

i prefer being explicit and not using macros myself TBH

LogPrintLevel is a macro too? edit: oh, I suppose you mean multiple macros

The way it's done now, it's clear where the messages come from and what their level is

What #29256 proposes is that you'd be able to do exactly that with the shorthand LogWarning(BCLog::NET, "natpmp: initnatpmp() failed with %d error.\n", r_init);, hence why I thought you'd be interested in chiming in on that pull. Apologies for derailing this PR, that was not my intent.

@laanwj
Copy link
Member Author

laanwj commented Apr 30, 2024

What #29256 proposes is that you'd be able to do exactly that with the shorthand LogWarning(BCLog::NET, "natpmp: initnatpmp() failed with %d error.\n", r_init);, hence why I thought you'd be interested in chiming in on that pull. Apologies for derailing this PR, that was not my intent.

Thanks, i'll keep it in mind.

Apologies for derailing this PR, that was not my intent.

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants