Author: zothar
Date: 2006-11-30 02:36:03 +0000 (Thu, 30 Nov 2006)
New Revision: 11132

Modified:
   trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/PeerNode.java
Log:
Fix multiple extraPeerDataType bug on N2NTMs that were queued by the sender and 
then given a second extraPeerDataType when storing on the receiver.  This 
appears it might have caused the deletion of the N2NTM to fail possibly.  Also 
send a N2NTM as a N2NM when we can when sending queued N2NTMs, not just when 
not queued.  Add some tracing information to help debug the N2NTM flood bug if 
this+toad_'s changes haven't already fixed it; some can be used for other 
interesting things as well.

Modified: trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java    2006-11-30 
02:20:06 UTC (rev 11131)
+++ trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java    2006-11-30 
02:36:03 UTC (rev 11132)
@@ -120,8 +120,8 @@
          if (request.isPartSet("send")) {
                  String message = request.getPartAsString("message", 5*1024);
                  message = message.trim();
-                       if(message.length() > 2000) {
-                               this.writeReply(ctx, 400, "text/plain", "Too 
long", "N2NTMs are limited to 2000 characters");
+                       if(message.length() > 1024) {
+                               this.writeReply(ctx, 400, "text/plain", "Too 
long", "N2NTMs are limited to 1024 characters");
                                return;
                        }
                        HTMLNode pageNode = 
ctx.getPageMaker().getPageNode("Send Node to Node Text Message Processing");
@@ -139,13 +139,16 @@
                                        String sendStatusLong;
                                        String sendStatusClass;
                                        try {
+                                               long now = 
System.currentTimeMillis();
                                                SimpleFieldSet fs = new 
SimpleFieldSet();
                                                fs.put("type", 
Integer.toString(Node.N2N_TEXT_MESSAGE_TYPE_USERALERT));
                                                fs.put("source_nodename", 
Base64.encode(node.getMyName().getBytes()));
                                                fs.put("target_nodename", 
Base64.encode(pn.getName().getBytes()));
                                                fs.put("text", 
Base64.encode(message.getBytes()));
+                                               fs.put("composedTime", 
Long.toString(now));
+                                               fs.put("sentTime", 
Long.toString(now));
                                                Message n2ntm;
-                                               if(Version.buildNumber() < 
1000) {  // FIXME/TODO: This test shouldn't be need eventually
+                                               if(Version.buildNumber() < 
1000) {  // FIXME/TODO: This test shouldn't be needed eventually
                                                        n2ntm = 
DMT.createNodeToNodeTextMessage(Node.N2N_TEXT_MESSAGE_TYPE_USERALERT, 
node.getMyName(), pn.getName(), message);
                                                } else {
                                                        n2ntm = 
DMT.createNodeToNodeMessage(Node.N2N_TEXT_MESSAGE_TYPE_USERALERT, 
fs.toString().getBytes("UTF-8"));
@@ -154,6 +157,7 @@
                                                        sendStatusShort = 
"Queued";
                                                        sendStatusLong = 
"Queued: Peer not connected, so message queued for when it connects";
                                                        sendStatusClass = 
"n2ntm-send-queued";
+                                                       
fs.removeValue("sentTime");
                                                        pn.queueN2NTM(fs);
                                                        Logger.normal(this, 
"Queued N2NTM to '"+pn.getName()+"': "+message);
                                                } else 
if(pn.getPeerNodeStatus() == Node.PEER_NODE_STATUS_ROUTING_BACKED_OFF) {

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-11-30 02:20:06 UTC (rev 
11131)
+++ trunk/freenet/src/freenet/node/Node.java    2006-11-30 02:36:03 UTC (rev 
11132)
@@ -2838,6 +2838,14 @@
                        fs.removeValue("type");
                }
                fs.put("type", Integer.toString(type));
+               if(fs.get("receivedTime") != null) {
+                       fs.removeValue("receivedTime");
+               }
+               fs.put("receivedTime", 
Long.toString(System.currentTimeMillis()));
+               if(fs.get("receivedAs") != null) {
+                       fs.removeValue("receivedAs");
+               }
+               fs.put("receivedAs", "nodeToNodeMessage");
                int fileNumber = source.writeNewExtraPeerDataFile( fs, 
EXTRA_PEER_DATA_TYPE_N2NTM);
                if( fileNumber == -1 ) {
                        Logger.error( this, "Failed to write N2NTM to extra 
peer data file for peer "+source.getPeer());
@@ -2870,6 +2878,8 @@
                fs.put("source_nodename", 
Base64.encode(source_nodename.getBytes()));
                fs.put("target_nodename", 
Base64.encode(target_nodename.getBytes()));
                fs.put("text", Base64.encode(text.getBytes()));
+               fs.put("receivedTime", 
Long.toString(System.currentTimeMillis()));
+               fs.put("receivedAs", "nodeToNodeTextMessage");
                int fileNumber = source.writeNewExtraPeerDataFile( fs, 
EXTRA_PEER_DATA_TYPE_N2NTM);
                if( fileNumber == -1 ) {
                        Logger.error( this, "Failed to write N2NTM to extra 
peer data file for peer "+source.getPeer());

Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java        2006-11-30 02:20:06 UTC 
(rev 11131)
+++ trunk/freenet/src/freenet/node/PeerNode.java        2006-11-30 02:36:03 UTC 
(rev 11132)
@@ -2698,7 +2698,28 @@
                                        Logger.error(this, "Bad Base64 encoding 
when decoding a N2NTM SimpleFieldSet", e);
                                        return false;
                                }
-                               Message n2ntm = 
DMT.createNodeToNodeTextMessage(Node.N2N_TEXT_MESSAGE_TYPE_USERALERT, 
source_nodename, target_nodename, text);
+                               Message n2ntm;
+                               if(fs.get("extraPeerDataType") != null) {
+                                       fs.removeValue("extraPeerDataType");
+                               }
+                               if(fs.get("senderFileNumber") != null) {
+                                       fs.removeValue("senderFileNumber");
+                               }
+                               fs.put("senderFileNumber", 
Integer.toString(fileNumber));
+                               if(fs.get("sentTime") != null) {
+                                       fs.removeValue("sentTime");
+                               }
+                               fs.put("sentTime", 
Long.toString(System.currentTimeMillis()));
+                               if(Version.buildNumber() < 1000) {  // 
FIXME/TODO: This test shouldn't be needed eventually
+                                       n2ntm = 
DMT.createNodeToNodeTextMessage(Node.N2N_TEXT_MESSAGE_TYPE_USERALERT, 
node.getMyName(), getName(), text);
+                               } else {
+                                       try {
+                                               n2ntm = 
DMT.createNodeToNodeMessage(Node.N2N_TEXT_MESSAGE_TYPE_USERALERT, 
fs.toString().getBytes("UTF-8"));
+                                       } catch (UnsupportedEncodingException 
e) {
+                                               Logger.error(this, 
"UnsupportedEncodingException processing extraPeerDataType 
("+extraPeerDataTypeString+") in file "+extraPeerDataFile.getPath(), e);
+                                               return false;
+                                       }
+                               }
                                try {
                                        node.usm.send(this, n2ntm, null);
                                        Logger.normal(this, "Sent queued 
("+fileNumber+") N2NTM to '"+getName()+"': "+text);
@@ -2712,6 +2733,8 @@
                                }
                        }
                        if(!sendSuccess) {
+                               fs.put("extraPeerDataType", 
Integer.toString(extraPeerDataType));
+                               fs.removeValue("sentTime");
                                
synchronized(queuedToSendN2NTMExtraPeerDataFileNumbers) {
                                        
queuedToSendN2NTMExtraPeerDataFileNumbers.add(new Integer(fileNumber));
                                }


Reply via email to