[freenet-cvs] r11753 - trunk/freenet/src/freenet/node/fcp

bback at freenetproject.org bback at freenetproject.org
Sat Feb 10 19:36:20 UTC 2007


Author: bback
Date: 2007-02-10 19:36:19 +0000 (Sat, 10 Feb 2007)
New Revision: 11753

Added:
   trunk/freenet/src/freenet/node/fcp/PersistentRequestModifiedMessage.java
Modified:
   trunk/freenet/src/freenet/node/fcp/ClientRequest.java
   trunk/freenet/src/freenet/node/fcp/ModifyPersistentRequest.java
Log:
added PersistentRequestModified message

Modified: trunk/freenet/src/freenet/node/fcp/ClientRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientRequest.java	2007-02-10 18:58:02 UTC (rev 11752)
+++ trunk/freenet/src/freenet/node/fcp/ClientRequest.java	2007-02-10 19:36:19 UTC (rev 11753)
@@ -306,9 +306,52 @@
     /**
      * Called after a ModifyPersistentRequest. Send a PersistentTagMessage to the clients.
      */
-    public void requestWasModified() {
-        FCPMessage msg = persistentTagMessage();
-        client.queueClientRequestMessage(msg, 0);
+    /**
+     * Called after a ModifyPersistentRequest. 
+     */
+    public void requestWasModified(String newClientToken, short newPriorityClass) {
+
+        boolean clientTokenChanged = false;
+        boolean priorityClassChanged = false;
+        
+        if(newClientToken != null) {
+            if( clientToken != null ) {
+                if( !newClientToken.equals(clientToken) ) {
+                    setClientToken(newClientToken); // token changed
+                    clientTokenChanged = true;
+                }
+            } else {
+                setClientToken(newClientToken); // first time the token is set
+                clientTokenChanged = true;
+            }
+        }
+
+        if(newPriorityClass >= 0 && newPriorityClass != priorityClass) {
+            setPriorityClass(newPriorityClass);
+            priorityClassChanged = true;
+        }
+
+        if( clientTokenChanged || priorityClassChanged ) {
+            if(persistenceType != ClientRequest.PERSIST_CONNECTION) {
+                if(client != null)
+                    client.server.forceStorePersistentRequests();
+            }
+        } else {
+            return; // quick return, nothing was changed
+        }
+
+        // this could become too complex with more parameters, but for now its ok
+        final PersistentRequestModifiedMessage modifiedMsg;
+        if( clientTokenChanged && priorityClassChanged ) {
+            modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, priorityClass, clientToken);
+        } else if( priorityClassChanged ) {
+            modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, priorityClass);
+        } else if( clientTokenChanged ) {
+            modifiedMsg = new PersistentRequestModifiedMessage(identifier, global, clientToken);
+        } else {
+            return; // paranoia, we should not be here if nothing was changed!
+        }
+        client.queueClientRequestMessage(modifiedMsg, 0);
     }
 
     /**

Modified: trunk/freenet/src/freenet/node/fcp/ModifyPersistentRequest.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ModifyPersistentRequest.java	2007-02-10 18:58:02 UTC (rev 11752)
+++ trunk/freenet/src/freenet/node/fcp/ModifyPersistentRequest.java	2007-02-10 19:36:19 UTC (rev 11753)
@@ -72,13 +72,7 @@
 			Logger.error(this, "Huh ? the request is null!");
 			return;
 		}
-		if(clientToken != null)
-			req.setClientToken(clientToken);
-		if(priorityClass >= 0)
-			req.setPriorityClass(priorityClass);
-		if(req.isPersistentForever())
-			client.server.forceStorePersistentRequests();
-
-        req.requestWasModified();
+        
+        req.requestWasModified(clientToken, priorityClass);
 	}
 }

Added: trunk/freenet/src/freenet/node/fcp/PersistentRequestModifiedMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/PersistentRequestModifiedMessage.java	                        (rev 0)
+++ trunk/freenet/src/freenet/node/fcp/PersistentRequestModifiedMessage.java	2007-02-10 19:36:19 UTC (rev 11753)
@@ -0,0 +1,56 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.node.fcp;
+
+import freenet.node.*;
+import freenet.support.*;
+
+/**
+ * Node answer message after a ModifyPerPersistentRequest message from client. 
+ */
+public class PersistentRequestModifiedMessage extends FCPMessage {
+
+    private final String ident;
+    private final boolean global;
+
+    private final SimpleFieldSet fs;
+    
+    protected PersistentRequestModifiedMessage(String identifier, boolean global) {
+        // remembered for the MessageInvalidException only
+        this.ident = identifier;
+        this.global = global;
+
+        fs = new SimpleFieldSet(true);
+        fs.putSingle("Identifier", identifier);
+        if(global) fs.putSingle("Global", "true");
+    }
+
+    public PersistentRequestModifiedMessage(String identifier, boolean global, short priorityClass) {
+        this(identifier, global);
+        fs.putSingle("PriorityClass", Short.toString(priorityClass));
+    }
+
+    public PersistentRequestModifiedMessage(String identifier, boolean global, String clientToken) {
+        this(identifier, global);
+        fs.putSingle("ClientToken", clientToken);
+    }
+
+    public PersistentRequestModifiedMessage(String identifier, boolean global, short priorityClass, String clientToken) {
+        this(identifier, global);
+        fs.putSingle("PriorityClass", Short.toString(priorityClass));
+        fs.putSingle("ClientToken", clientToken);
+    }
+
+    public SimpleFieldSet getFieldSet() {
+        return fs;
+    }
+
+    public String getName() {
+        return "PersistentRequestModified";
+    }
+
+    public void run(FCPConnectionHandler handler, Node node) throws MessageInvalidException {
+        throw new MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "PersistentRequestModified goes from server to client not the other way around", ident, global);
+    }
+}




More information about the cvs mailing list