diff --git a/src/freenet/node/PeerNode.java b/src/freenet/node/PeerNode.java index e8aefa11be9..b6b828c58e9 100644 --- a/src/freenet/node/PeerNode.java +++ b/src/freenet/node/PeerNode.java @@ -3891,6 +3891,11 @@ protected void setJFKBuffer(byte[] bufferJFK) { private long timeLastAcceptedAnnouncement; private long[] runningAnnounceUIDs = new long[0]; + /** Protection against too many simultaneous announcements over a single + * connection. + * @param uid The announcement UID. + * @return True if we should accept the announcement. False to reject it. + */ public synchronized boolean shouldAcceptAnnounce(long uid) { long now = System.currentTimeMillis(); if(runningAnnounceUIDs.length < MAX_SIMULTANEOUS_ANNOUNCEMENTS && @@ -3899,6 +3904,7 @@ public synchronized boolean shouldAcceptAnnounce(long uid) { if(runningAnnounceUIDs.length > 0) System.arraycopy(runningAnnounceUIDs, 0, newList, 0, runningAnnounceUIDs.length); newList[runningAnnounceUIDs.length] = uid; + runningAnnounceUIDs = newList; timeLastAcceptedAnnouncement = now; return true; } else { @@ -3906,23 +3912,29 @@ public synchronized boolean shouldAcceptAnnounce(long uid) { } } + /** Report that an announcement finished. */ public synchronized boolean completedAnnounce(long uid) { - final int runningAnnounceUIDsLength = runningAnnounceUIDs.length; - if(runningAnnounceUIDsLength < 1) return false; - long[] newList = new long[runningAnnounceUIDsLength - 1]; + if(runningAnnounceUIDs.length < 1) return false; + long[] newList = new long[runningAnnounceUIDs.length - 1]; int x = 0; - for(int i=0;i