Author: zothar
Date: 2006-11-19 17:15:50 +0000 (Sun, 19 Nov 2006)
New Revision: 11009

Modified:
   trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
Log:
Bug 899: Drop messages in the _unclaimed FIFO if they're still around an hour 
later after local instantiation.

Modified: trunk/freenet/src/freenet/io/comm/UdpSocketManager.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/UdpSocketManager.java     2006-11-19 
15:37:53 UTC (rev 11008)
+++ trunk/freenet/src/freenet/io/comm/UdpSocketManager.java     2006-11-19 
17:15:50 UTC (rev 11009)
@@ -51,6 +51,7 @@
        private boolean _isDone;
        private static UdpSocketManager _usm;
        private static final int MAX_UNMATCHED_FIFO_SIZE = 50000;
+       private static final long MAX_UNCLAIMED_FIFO_ITEM_LIFETIME = 
60*60*1000;  // 1 hour
        private volatile int lastTimeInSeconds;
        private final InetAddress _bindTo;

@@ -401,9 +402,9 @@
                                        Message removed = 
(Message)_unclaimed.removeFirst();
                                        long messageLifeTime = 
System.currentTimeMillis() - removed.localInstantiationTime;
                                        if ((removed.getSource()) instanceof 
PeerNode) {
-                                           Logger.normal(this, "Dropping 
unclaimed from "+removed.getSource().getPeer()+", lived 
"+TimeUtil.formatTime(messageLifeTime, 2, true)+" : "+removed);
+                                           Logger.normal(this, "Dropping 
unclaimed from "+removed.getSource().getPeer()+", lived 
"+TimeUtil.formatTime(messageLifeTime, 2, true)+" (quantity)"+": "+removed);
                                        } else {
-                                           Logger.normal(this, "Dropping 
unclaimed, lived "+TimeUtil.formatTime(messageLifeTime, 2, true)+" : "+removed);
+                                           Logger.normal(this, "Dropping 
unclaimed, lived "+TimeUtil.formatTime(messageLifeTime, 2, true)+" 
(quantity)"+": "+removed);
                                        }
                                    }
                                    _unclaimed.addLast(m);
@@ -441,6 +442,10 @@
                        lowLevelFilter.isDisconnected(filter._source))
                    throw new DisconnectedException();
                // Check to see whether the filter matches any of the recently 
_unclaimed messages
+               // Drop any _unclaimed messages that the filter doesn't match 
that are also older than MAX_UNCLAIMED_FIFO_ITEM_LIFETIME
+               long now = System.currentTimeMillis();
+               long messageDropTime = now - MAX_UNCLAIMED_FIFO_ITEM_LIFETIME;
+               long messageLifeTime = 0;
                synchronized (_filters) {
                        if(logMINOR) Logger.minor(this, "Checking _unclaimed");
                        for (ListIterator i = _unclaimed.listIterator(); 
i.hasNext();) {
@@ -450,6 +455,14 @@
                                        ret = m;
                                        if(logMINOR) Logger.debug(this, 
"Matching from _unclaimed");
                                        break;
+                               } else if (m.localInstantiationTime < 
messageDropTime) {
+                                       i.remove();
+                                       messageLifeTime = now - 
m.localInstantiationTime;
+                                       if ((m.getSource()) instanceof 
PeerNode) {
+                                               Logger.normal(this, "Dropping 
unclaimed from "+m.getSource().getPeer()+", lived 
"+TimeUtil.formatTime(messageLifeTime, 2, true)+" (age)"+": "+m);
+                                       } else {
+                                               Logger.normal(this, "Dropping 
unclaimed, lived "+TimeUtil.formatTime(messageLifeTime, 2, true)+" (age)"+": 
"+m);
+                                       }
                                }
                        }
                        if (ret == null) {


Reply via email to