Skip to content

Conversation

@anonstudy
Copy link

Changes proposed in this pull request:

Announcer.Java

This PR refactors the enoughPeers method by extracting the logic for shutting down the announcement into a separate method.

Changes:

  • Created a new private method shutdownAnnouncement in the class
  • Updated the enoughPeers method to call shutdownAnnouncement where appropriate

Rationale:

  • Single Responsibility Principle: The new method has a clear, single purpose of handling the announcement shutdown process.
  • Easier maintenance: Changes to the announcement shutdown logic can now be made in one place.
  • Potential for reuse: If announcement shutdown is needed elsewhere, it can now be easily called from other methods.

Note:

  • This refactoring does not change any functionality; it only reorganizes the existing code.

DarknetPeerNode.Java

This PR refactors the readExtraPeerDataFile method by extracting the file reading logic into a separate method.

Changes:

  • Created a new private method readFile that takes a file path as input and returns the file contents as a string
  • Updated readExtraPeerDataFile to use the new readFile method

Rationale:

  • Improved separation of concerns: The readExtraPeerDataFile method now focuses on data processing, while file I/O is handled separately.
  • Increased reusability: The readFile method can be used in other parts of the codebase where file reading is needed.
  • Better error handling: File I/O errors can be managed consistently in one place.

Note:

  • This refactoring does not change the overall functionality; it reorganizes the existing code for better structure.

Copy link
Contributor

@ArneBab ArneBab left a comment

Choose a reason for hiding this comment

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

The code changes look good, thank you!

Please remove the intellij setup from the PR, so we can merge just the cleaned up code.

Copy link
Contributor

Choose a reason for hiding this comment

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

No. Please do not commit configuration for your local IDE.

return false;
}
Logger.normal(this, "extraPeerDataFile: "+extraPeerDataFile.getPath());
FileInputStream fis;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this? Unused, that’s what it is!

Logger.normal(this, "extraPeerDataFile: "+extraPeerDataFile.getPath());
FileInputStream fis;
SimpleFieldSet fs = readFile(extraPeerDataFile);
if (fs == null) return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add braces for all blocks.

FileInputStream fis;
SimpleFieldSet fs = readFile(extraPeerDataFile);
if (fs == null) return false;
if(fs == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent whitespace (cf. to the line directly above this).

Copy link
Contributor

@Bombe Bombe Aug 27, 2024

Choose a reason for hiding this comment

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

Also, wait, what? fs has already been found to be non-null so this if can never be true.

deleteExtraPeerDataFile(fileNumber);
return true;
}
boolean parseResult = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

As this variable is not used outside the try block, please declare it inside the try block.

Logger.error(this, "Could not parse extra peer data: "+e2+ '\n' +fs.toString(),e2);
gotError = true;
}
return !gotError;
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole construct seems to be over-complicated. Both parseResult and gotError (declared at the wrong end of the method) do not fulfill any real purpose here and can be removed without any damage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the changes for both of these files mixed into a single pull request? Please file separate pull requests; smaller pull requests are easier to handle than larger ones.

return false;
}

private boolean shutdownAnnouncement() {
Copy link
Contributor

Choose a reason for hiding this comment

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

“shutdownAnnouncement” sounds like a command but the method doesn’t do anything, and it returns a value. What is actually meant here? Is the shutdown announcement being shown? Should it be? Should announcements be shut down? Please rename the method in a way that makes it clearer what it does.

}
return true;
}
if (shutdownAnnouncement()) return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Always use braces for blocks, and only one statement per line, please.

@Bombe
Copy link
Contributor

Bombe commented Sep 15, 2024

The code changes look good, thank you!

Sorry for barging into this, apparently I had started a review a couple of weeks ago but never got around to finish it. :)

@ArneBab
Copy link
Contributor

ArneBab commented Sep 15, 2024

The code changes look good, thank you!

Sorry for barging into this, apparently I had started a review a couple of weeks ago but never got around to finish it. :)

I reviewed just the change — the refactoring — not the original code. There are a lot more issues in the original code than just the ones fixed here, but I think they can be fixed in an independent PR.

@Bombe
Copy link
Contributor

Bombe commented Sep 16, 2024

The code changes look good, thank you!

Sorry for barging into this, apparently I had started a review a couple of weeks ago but never got around to finish it. :)

I reviewed just the change — the refactoring — not the original code. There are a lot more issues in the original code than just the ones fixed here, but I think they can be fixed in an independent PR.

Some of the code is indeed the original code, just moved around, but some of it is new code, and for that code my comments still stand. 🙂

@ArneBab
Copy link
Contributor

ArneBab commented Aug 16, 2025

@anonstudy are you planning to still do changes for the review by @Bombe ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants