summaryrefslogtreecommitdiff
path: root/org
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2009-11-01 13:48:51 +0000
committerMatthew Johnson <mjj29@qadesh.matthew.ath.cx>2009-11-01 13:48:51 +0000
commit94883c197697e54be33f3255f93f47d04d2223a5 (patch)
tree13c0a09102a899cceb560a91cc9d0cec960de5d1 /org
parentd49879de16c25757e4d6be0a5338f062c069bedb (diff)
fix tcp timestamp issues
Diffstat (limited to 'org')
-rw-r--r--org/freedesktop/dbus/Transport.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/org/freedesktop/dbus/Transport.java b/org/freedesktop/dbus/Transport.java
index 7c289f8..ccde1e9 100644
--- a/org/freedesktop/dbus/Transport.java
+++ b/org/freedesktop/dbus/Transport.java
@@ -109,9 +109,13 @@ public class Transport
col.setDecomposition(Collator.FULL_DECOMPOSITION);
col.setStrength(Collator.PRIMARY);
}
- public static final int LOCK_TIMEOUT = 1000;
- public static final int COOKIE_TIMEOUT = 120;
+ public static final int LOCK_TIMEOUT = 1000;
+ public static final int NEW_KEY_TIMEOUT_SECONDS = 60 * 5;
+ public static final int EXPIRE_KEYS_TIMEOUT_SECONDS = NEW_KEY_TIMEOUT_SECONDS + (60 * 2);
+ public static final int MAX_TIME_TRAVEL_SECONDS = 60 * 5;
+ public static final int COOKIE_TIMEOUT = 240;
public static final String COOKIE_CONTEXT = "org_freedesktop_java";
+
private String findCookie(String context, String ID) throws IOException
{
String homedir = System.getProperty("user.home");
@@ -119,15 +123,18 @@ public class Transport
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
String s = null;
String cookie = null;
- long timestamp = System.currentTimeMillis()/1000;
- while (null != (s = r.readLine())) {
- String[] line = s.split(" ");
- long time = Long.parseLong(line[1]);
- if (line[0].equals(ID) && (timestamp - time) < COOKIE_TIMEOUT) {
- cookie = line[2];
- break;
- }
- }
+ long now = System.currentTimeMillis()/1000;
+ while (null != (s = r.readLine())) {
+ String[] line = s.split(" ");
+ long timestamp = Long.parseLong(line[1]);
+ if (line[0].equals(ID) && (! (timestamp < 0 ||
+ (now + MAX_TIME_TRAVEL_SECONDS) < timestamp ||
+ (now - EXPIRE_KEYS_TIMEOUT_SECONDS) > timestamp))) {
+ cookie = line[2];
+ break;
+ }
+ }
+ r.close();
return cookie;
}
private void addCookie(String context, String ID, long timestamp, String cookie) throws IOException