Author: toad
Date: 2007-12-03 21:26:58 +0000 (Mon, 03 Dec 2007)
New Revision: 16243
Modified:
trunk/freenet/src/freenet/node/NodeDispatcher.java
trunk/freenet/src/freenet/node/NodeStats.java
trunk/freenet/src/freenet/node/RequestStarter.java
Log:
We can take the source into account in NodeStats.shouldRejectRequest()
Modified: trunk/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeDispatcher.java 2007-12-03 21:22:02 UTC
(rev 16242)
+++ trunk/freenet/src/freenet/node/NodeDispatcher.java 2007-12-03 21:26:58 UTC
(rev 16243)
@@ -118,13 +118,13 @@
} else if(spec == DMT.FNPSwapComplete) {
return node.lm.handleSwapComplete(m);
} else if(spec == DMT.FNPCHKDataRequest) {
- return handleDataRequest(m, false);
+ return handleDataRequest(m, source, false);
} else if(spec == DMT.FNPSSKDataRequest) {
- return handleDataRequest(m, true);
+ return handleDataRequest(m, source, true);
} else if(spec == DMT.FNPInsertRequest) {
- return handleInsertRequest(m, false);
+ return handleInsertRequest(m, source, false);
} else if(spec == DMT.FNPSSKInsertRequest) {
- return handleInsertRequest(m, true);
+ return handleInsertRequest(m, source, true);
} else if(spec == DMT.FNPRoutedPing) {
return handleRouted(m);
} else if(spec == DMT.FNPRoutedPong) {
@@ -179,7 +179,7 @@
/**
* Handle an incoming FNPDataRequest.
*/
- private boolean handleDataRequest(Message m, boolean isSSK) {
+ private boolean handleDataRequest(Message m, PeerNode source, boolean
isSSK) {
long id = m.getLong(DMT.UID);
if(node.recentlyCompleted(id)) {
Message rejected = DMT.createFNPRejectedLoop(id);
@@ -202,7 +202,7 @@
} else {
if(logMINOR) Logger.minor(this, "Locked "+id);
}
- String rejectReason = nodeStats.shouldRejectRequest(!isSSK,
false, isSSK, false);
+ String rejectReason = nodeStats.shouldRejectRequest(!isSSK,
false, isSSK, false, source);
if(rejectReason != null) {
// can accept 1 CHK request every so often, but not
with SSKs because they aren't throttled so won't sort out bwlimitDelayTime,
which was the whole reason for accepting them when overloaded...
Logger.normal(this, "Rejecting request from
"+m.getSource().getPeer()+" preemptively because "+rejectReason);
@@ -221,7 +221,7 @@
return true;
}
- private boolean handleInsertRequest(Message m, boolean isSSK) {
+ private boolean handleInsertRequest(Message m, PeerNode source, boolean
isSSK) {
long id = m.getLong(DMT.UID);
if(node.recentlyCompleted(id)) {
Message rejected = DMT.createFNPRejectedLoop(id);
@@ -243,7 +243,7 @@
return true;
}
// SSKs don't fix bwlimitDelayTime so shouldn't be accepted
when overloaded.
- String rejectReason = nodeStats.shouldRejectRequest(!isSSK,
true, isSSK, false);
+ String rejectReason = nodeStats.shouldRejectRequest(!isSSK,
true, isSSK, false, source);
if(rejectReason != null) {
Logger.normal(this, "Rejecting insert from
"+m.getSource().getPeer()+" preemptively because "+rejectReason);
Message rejected = DMT.createFNPRejectedOverload(id,
true);
Modified: trunk/freenet/src/freenet/node/NodeStats.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStats.java 2007-12-03 21:22:02 UTC
(rev 16242)
+++ trunk/freenet/src/freenet/node/NodeStats.java 2007-12-03 21:26:58 UTC
(rev 16243)
@@ -365,7 +365,7 @@
};
/* return reject reason as string if should reject, otherwise return
null */
- public String shouldRejectRequest(boolean canAcceptAnyway, boolean
isInsert, boolean isSSK, boolean isLocal) {
+ public String shouldRejectRequest(boolean canAcceptAnyway, boolean
isInsert, boolean isSSK, boolean isLocal, PeerNode source) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR) dumpByteCostAverages();
Modified: trunk/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/RequestStarter.java 2007-12-03 21:22:02 UTC
(rev 16242)
+++ trunk/freenet/src/freenet/node/RequestStarter.java 2007-12-03 21:26:58 UTC
(rev 16243)
@@ -117,7 +117,7 @@
} while(now < sleepUntil);
String reason;
if(LOCAL_REQUESTS_COMPETE_FAIRLY) {
- if((reason =
stats.shouldRejectRequest(true, isInsert, isSSK, true)) != null) {
+ if((reason =
stats.shouldRejectRequest(true, isInsert, isSSK, true, null)) != null) {
if(logMINOR)
Logger.minor(this, "Not
sending local request: "+reason);
// Wait one throttle-delay
before trying again