Skip to content

Commit

Permalink
Remove all Fred usages of deprecated CurrentTimeUTC
Browse files Browse the repository at this point in the history
Only get() and getInMillis() were used within Fred. These methods can
trivially be replaced by new Date() and System.currentTimeMillis()
respectively.
  • Loading branch information
bertm committed Oct 15, 2023
1 parent a01b276 commit b53b937
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 37 deletions.
25 changes: 13 additions & 12 deletions src/freenet/client/async/ClientRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import freenet.node.SendableRequest;
import freenet.node.useralerts.SimpleUserAlert;
import freenet.node.useralerts.UserAlert;
import freenet.support.CurrentTimeUTC;
import freenet.support.Logger;
import freenet.support.Logger.LogLevel;
import freenet.support.io.ResumeFailedException;
Expand Down Expand Up @@ -125,10 +124,12 @@ public int hashCode() {
protected int totalBlocks;
/** Number of blocks we have successfully completed a fetch/put for. */
protected int successfulBlocks;
/**
* ATTENTION: This may be null for very old databases.
* @see #getLatestSuccess() Explanation of the content and especially the default value. */
protected Date latestSuccess = CurrentTimeUTC.get();
/**
* ATTENTION: This may be null for very old databases.
*
* @see #getLatestSuccess() Explanation of the content and especially the default value.
*/
protected Date latestSuccess = new Date();
/** Number of blocks which have failed. */
protected int failedBlocks;
/** Number of blocks which have failed fatally. */
Expand Down Expand Up @@ -174,8 +175,8 @@ public Date getLatestFailure() {
protected synchronized void resetBlocks() {
totalBlocks = 0;
successfulBlocks = 0;
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
latestSuccess = CurrentTimeUTC.get();
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
latestSuccess = new Date();
failedBlocks = 0;
fatallyFailedBlocks = 0;
latestFailure = null;
Expand Down Expand Up @@ -242,7 +243,7 @@ public void completedBlock(boolean dontNotify, ClientContext context) {
synchronized(this) {
if(cancelled) return;
successfulBlocks++;
latestSuccess = CurrentTimeUTC.get();
latestSuccess = new Date();
}
if(dontNotify) return;
notifyClients(context);
Expand All @@ -254,7 +255,7 @@ public void completedBlock(boolean dontNotify, ClientContext context) {
public void failedBlock(boolean dontNotify, ClientContext context) {
synchronized(this) {
failedBlocks++;
latestFailure = CurrentTimeUTC.get();
latestFailure = new Date();
}
if(!dontNotify)
notifyClients(context);
Expand All @@ -269,7 +270,7 @@ public void failedBlock(ClientContext context) {
public void fatallyFailedBlock(ClientContext context) {
synchronized(this) {
fatallyFailedBlocks++;
latestFailure = CurrentTimeUTC.get();
latestFailure = new Date();
}
notifyClients(context);
}
Expand Down Expand Up @@ -331,8 +332,8 @@ protected void clearCountersOnRestart() {
this.minSuccessBlocks = 0;
this.sentToNetwork = false;
this.successfulBlocks = 0;
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
this.latestSuccess = CurrentTimeUTC.get();
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
this.latestSuccess = new Date();
this.totalBlocks = 0;
}

Expand Down
3 changes: 1 addition & 2 deletions src/freenet/client/events/SplitfileProgressEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Date;

import freenet.client.async.ClientRequester;
import freenet.support.CurrentTimeUTC;
import freenet.support.LogThresholdCallback;
import freenet.support.Logger;
import freenet.support.Logger.LogLevel;
Expand Down Expand Up @@ -61,7 +60,7 @@ protected SplitfileProgressEvent() {
totalBlocks = 0;
succeedBlocks = 0;
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
latestSuccess = CurrentTimeUTC.get();
latestSuccess = new Date();
failedBlocks = 0;
fatallyFailedBlocks = 0;
latestFailure = null;
Expand Down
3 changes: 1 addition & 2 deletions src/freenet/clients/fcp/ClientGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import freenet.crypt.HashResult;
import freenet.keys.FreenetURI;
import freenet.node.NodeClientCore;
import freenet.support.CurrentTimeUTC;
import freenet.support.LogThresholdCallback;
import freenet.support.Logger;
import freenet.support.Logger.LogLevel;
Expand Down Expand Up @@ -931,7 +930,7 @@ synchronized RequestStatus getStatus() {
boolean totalFinalized = false;
int total = 0, min = 0, fetched = 0, fatal = 0, failed = 0;
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
Date latestSuccess = CurrentTimeUTC.get();
Date latestSuccess = new Date();
Date latestFailure = null;

if(progressPending != null) {
Expand Down
3 changes: 1 addition & 2 deletions src/freenet/clients/fcp/ClientPut.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import freenet.keys.FreenetURI;
import freenet.node.NodeClientCore;
import freenet.support.Base64;
import freenet.support.CurrentTimeUTC;
import freenet.support.IllegalBase64Exception;
import freenet.support.LogThresholdCallback;
import freenet.support.Logger;
Expand Down Expand Up @@ -525,7 +524,7 @@ RequestStatus getStatus() {

int total=0, min=0, fetched=0, fatal=0, failed=0;
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
Date latestSuccess = CurrentTimeUTC.get();
Date latestSuccess = new Date();
Date latestFailure = null;
boolean totalFinalized = false;

Expand Down
3 changes: 1 addition & 2 deletions src/freenet/clients/fcp/ClientPutDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import freenet.clients.fcp.RequestIdentifier.RequestType;
import freenet.keys.FreenetURI;
import freenet.node.NodeClientCore;
import freenet.support.CurrentTimeUTC;
import freenet.support.LogThresholdCallback;
import freenet.support.Logger;
import freenet.support.Logger.LogLevel;
Expand Down Expand Up @@ -380,7 +379,7 @@ RequestStatus getStatus() {

int total=0, min=0, fetched=0, fatal=0, failed=0;
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
Date latestSuccess = CurrentTimeUTC.get();
Date latestSuccess = new Date();
Date latestFailure = null;
boolean totalFinalized = false;

Expand Down
5 changes: 2 additions & 3 deletions src/freenet/clients/fcp/RequestStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import freenet.clients.fcp.ClientRequest.Persistence;
import freenet.keys.FreenetURI;
import freenet.l10n.NodeL10n;
import freenet.support.CurrentTimeUTC;

/** The status of a request. Cached copy i.e. can be accessed outside the database thread
* even for a persistent request.
Expand Down Expand Up @@ -41,7 +40,7 @@ public abstract class RequestStatus implements Cloneable {
/** The download or upload has finished.
* @param success Did it succeed? */
synchronized void setFinished(boolean success) {
this.latestSuccess = CurrentTimeUTC.get();
this.latestSuccess = new Date();
this.hasFinished = true;
this.hasSucceeded = success;
this.hasStarted = true;
Expand All @@ -50,7 +49,7 @@ synchronized void setFinished(boolean success) {

synchronized void restart(boolean started) {
// See ClientRequester.getLatestSuccess() for why this defaults to current time.
this.latestSuccess = CurrentTimeUTC.get();
this.latestSuccess = new Date();
this.hasFinished = false;
this.hasSucceeded = false;
this.hasStarted = started;
Expand Down
3 changes: 1 addition & 2 deletions src/freenet/clients/http/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Date;
import java.util.HashSet;

import freenet.support.CurrentTimeUTC;
import freenet.support.TimeUtil;

/**
Expand Down Expand Up @@ -271,7 +270,7 @@ <TheSeeker> The following grammar uses the notation, and tokens DIGIT (decimal d
}

public static Date validateExpirationDate(Date expirationDate) {
if(CurrentTimeUTC.get().after(expirationDate))
if(new Date().after(expirationDate))
throw new IllegalArgumentException("Illegal expiration date, is in past: " + expirationDate);

return expirationDate;
Expand Down
7 changes: 3 additions & 4 deletions src/freenet/clients/http/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Set;
import java.util.UUID;

import freenet.support.CurrentTimeUTC;
import freenet.support.LRUMap;
import freenet.support.Logger;
import freenet.support.StringValidityChecker;
Expand Down Expand Up @@ -252,7 +251,7 @@ public String getCookieNamespace() {
public synchronized Session createSession(String userID, ToadletContext context) {
// We must synchronize around the fetching of the time and mSessionsByID.push() because mSessionsByID is no sorting data structure: It's a plain
// LRUMap so to ensure that it stays sorted the operation "getTime(); push();" must be atomic.
long time = CurrentTimeUTC.getInMillis();
long time = System.currentTimeMillis();

removeExpiredSessions(time);

Expand All @@ -279,7 +278,7 @@ public synchronized boolean sessionExists(ToadletContext context) {
if(sessionID == null)
return false;

removeExpiredSessions(CurrentTimeUTC.getInMillis());
removeExpiredSessions(System.currentTimeMillis());

return mSessionsByID.containsKey(sessionID);
}
Expand All @@ -299,7 +298,7 @@ public synchronized Session useSession(ToadletContext context) {

// We must synchronize around the fetching of the time and mSessionsByID.push() because mSessionsByID is no sorting data structure: It's a plain
// LRUMap so to ensure that it stays sorted the operation "getTime(); push();" must be atomic.
long time = CurrentTimeUTC.getInMillis();
long time = System.currentTimeMillis();

removeExpiredSessions(time);

Expand Down
4 changes: 2 additions & 2 deletions src/freenet/support/LRUCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ private final class Entry {

public Entry(final Value myValue) {
mValue = myValue;
mExpirationDate = (mExpirationDelay < Long.MAX_VALUE) ? (CurrentTimeUTC.getInMillis() + mExpirationDelay) : (Long.MAX_VALUE);
mExpirationDate = (mExpirationDelay < Long.MAX_VALUE) ? (System.currentTimeMillis() + mExpirationDelay) : (Long.MAX_VALUE);
}

public boolean expired(final long time) {
return mExpirationDate < time;
}

public boolean expired() {
return expired(CurrentTimeUTC.getInMillis());
return expired(System.currentTimeMillis());
}

public Value getValue() {
Expand Down
10 changes: 4 additions & 6 deletions test/freenet/clients/http/CookieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.junit.Before;
import org.junit.Test;

import freenet.support.CurrentTimeUTC;

public class CookieTest {

static final String VALID_PATH = "/Freetalk";
Expand All @@ -28,7 +26,7 @@ public class CookieTest {
@Before
public void setUp() throws Exception {
validPath = new URI(VALID_PATH);
validExpiresDate = new Date(CurrentTimeUTC.getInMillis()+60*60*1000);
validExpiresDate = new Date(System.currentTimeMillis() + 60 * 60 * 1000);
cookie = new Cookie(validPath, VALID_NAME, VALID_VALUE, validExpiresDate);
}

Expand Down Expand Up @@ -81,18 +79,18 @@ public void testCookieURIStringStringDate() throws URISyntaxException {
// TODO: Test for more invalid characters in value;

try {
new Cookie(validPath, VALID_NAME, VALID_VALUE, new Date(CurrentTimeUTC.getInMillis()-1));
new Cookie(validPath, VALID_NAME, VALID_VALUE, new Date(System.currentTimeMillis() - 1));
fail("Constructor allows construction of expired cookies.");
} catch(RuntimeException e) {}
}

@Test
public void testEqualsObject() throws URISyntaxException {
assertEquals(cookie, cookie);
assertEquals(cookie, new Cookie(validPath, VALID_NAME, VALID_VALUE, new Date(CurrentTimeUTC.getInMillis()+60*1000)));
assertEquals(cookie, new Cookie(validPath, VALID_NAME, VALID_VALUE, new Date(System.currentTimeMillis() + 60 * 1000)));

// Value is not checked in equals().
assertEquals(cookie, new Cookie(validPath, VALID_NAME, "", new Date(CurrentTimeUTC.getInMillis()+60*1000)));
assertEquals(cookie, new Cookie(validPath, VALID_NAME, "", new Date(System.currentTimeMillis() + 60 * 1000)));

assertFalse(cookie.equals(new Cookie(new URI(VALID_PATH.toLowerCase()), VALID_NAME, VALID_VALUE, validExpiresDate)));
assertEquals(cookie, new Cookie(validPath, VALID_NAME.toLowerCase(), VALID_VALUE, validExpiresDate));
Expand Down

0 comments on commit b53b937

Please sign in to comment.