-
Notifications
You must be signed in to change notification settings - Fork 212
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
Refactor methods for separation of concern #973
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,6 +359,15 @@ boolean enoughPeers() { | |
} | ||
return true; | ||
} | ||
if (shutdownAnnouncement()) return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always use braces for blocks, and only one statement per line, please. |
||
|
||
synchronized(timeGotEnoughPeersLock) { | ||
timeGotEnoughPeers = -1; | ||
} | ||
return false; | ||
} | ||
|
||
private boolean shutdownAnnouncement() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
boolean killAnnouncement = false; | ||
if((!node.getNodeUpdater().isEnabled()) || | ||
(node.getNodeUpdater().canUpdateNow() && !node.getNodeUpdater().isArmed())) { | ||
|
@@ -382,7 +391,7 @@ boolean enoughPeers() { | |
} | ||
|
||
} | ||
|
||
if(killAnnouncement) { | ||
node.getExecutor().execute(new Runnable() { | ||
|
||
|
@@ -395,7 +404,7 @@ public void run() { | |
node.getPeers().disconnectAndRemove(pn, true, true, true); | ||
} | ||
} | ||
|
||
}); | ||
return true; | ||
} else { | ||
|
@@ -411,10 +420,6 @@ public void run() { | |
return true; | ||
} | ||
} | ||
|
||
synchronized(timeGotEnoughPeersLock) { | ||
timeGotEnoughPeers = -1; | ||
} | ||
return false; | ||
} | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,12 +510,34 @@ public boolean readExtraPeerDataFile(File extraPeerDataFile, int fileNumber) { | |
return false; | ||
} | ||
Logger.normal(this, "extraPeerDataFile: "+extraPeerDataFile.getPath()); | ||
FileInputStream fis; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this? Unused, that’s what it is! |
||
SimpleFieldSet fs = readFile(extraPeerDataFile); | ||
if (fs == null) return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add braces for all blocks. |
||
if(fs == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent whitespace (cf. to the line directly above this). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, wait, what? |
||
Logger.normal(this, "Deleting corrupt (too short?) file: "+extraPeerDataFile); | ||
deleteExtraPeerDataFile(fileNumber); | ||
return true; | ||
} | ||
boolean parseResult = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this variable is not used outside the |
||
try { | ||
parseResult = parseExtraPeerData(fs, extraPeerDataFile, fileNumber); | ||
if(!parseResult) { | ||
gotError = true; | ||
} | ||
} catch (FSParseException e2) { | ||
Logger.error(this, "Could not parse extra peer data: "+e2+ '\n' +fs.toString(),e2); | ||
gotError = true; | ||
} | ||
return !gotError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole construct seems to be over-complicated. Both |
||
} | ||
|
||
private SimpleFieldSet readFile(File extraPeerDataFile) { | ||
FileInputStream fis; | ||
try { | ||
fis = new FileInputStream(extraPeerDataFile); | ||
} catch (FileNotFoundException e1) { | ||
Logger.normal(this, "Extra peer data file not found: "+extraPeerDataFile.getPath()); | ||
return false; | ||
Logger.normal(this, "Extra peer data file not found: "+ extraPeerDataFile.getPath()); | ||
return null; | ||
} | ||
InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8); | ||
BufferedReader br = new BufferedReader(isr); | ||
|
@@ -531,25 +553,10 @@ public boolean readExtraPeerDataFile(File extraPeerDataFile, int fileNumber) { | |
try { | ||
br.close(); | ||
} catch (IOException e5) { | ||
Logger.error(this, "Ignoring "+e5+" caught reading "+extraPeerDataFile.getPath(), e5); | ||
Logger.error(this, "Ignoring "+e5+" caught reading "+ extraPeerDataFile.getPath(), e5); | ||
} | ||
} | ||
if(fs == null) { | ||
Logger.normal(this, "Deleting corrupt (too short?) file: "+extraPeerDataFile); | ||
deleteExtraPeerDataFile(fileNumber); | ||
return true; | ||
} | ||
boolean parseResult = false; | ||
try { | ||
parseResult = parseExtraPeerData(fs, extraPeerDataFile, fileNumber); | ||
if(!parseResult) { | ||
gotError = true; | ||
} | ||
} catch (FSParseException e2) { | ||
Logger.error(this, "Could not parse extra peer data: "+e2+ '\n' +fs.toString(),e2); | ||
gotError = true; | ||
} | ||
return !gotError; | ||
return fs; | ||
} | ||
|
||
private boolean parseExtraPeerData(SimpleFieldSet fs, File extraPeerDataFile, int fileNumber) throws FSParseException { | ||
|
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.
No. Please do not commit configuration for your local IDE.