only count locally generated lookup messages for detecting local DoS (duh)

This commit is contained in:
jrandom
2004-08-13 02:52:17 +00:00
committed by zzz
parent 5122f9989c
commit 3c9b0273d4
4 changed files with 15 additions and 9 deletions

View File

@ -43,6 +43,9 @@ public class DatabaseLookupMessage extends I2NPMessageImpl {
private static final long LOOKUP_THROTTLE_MAX = 50; private static final long LOOKUP_THROTTLE_MAX = 50;
public DatabaseLookupMessage(I2PAppContext context) { public DatabaseLookupMessage(I2PAppContext context) {
this(context, false);
}
public DatabaseLookupMessage(I2PAppContext context, boolean locallyCreated) {
super(context); super(context);
setSearchKey(null); setSearchKey(null);
setFrom(null); setFrom(null);
@ -50,12 +53,15 @@ public class DatabaseLookupMessage extends I2NPMessageImpl {
context.statManager().createRateStat("router.throttleNetDbDoSSend", "How many netDb lookup messages we are sending during a period with a DoS detected", "Throttle", new long[] { 60*1000, 10*60*1000, 60*60*1000, 24*60*60*1000 }); context.statManager().createRateStat("router.throttleNetDbDoSSend", "How many netDb lookup messages we are sending during a period with a DoS detected", "Throttle", new long[] { 60*1000, 10*60*1000, 60*60*1000, 24*60*60*1000 });
// only check DoS generation if we are creating the message...
if (locallyCreated) {
// we do this in the writeMessage so we know that we have all the data // we do this in the writeMessage so we know that we have all the data
int dosCount = detectDoS(context); int dosCount = detectDoS(context);
if (dosCount > 0) { if (dosCount > 0) {
_log.log(Log.CRIT, "Are we flooding the network with NetDb messages? (" + dosCount + " messages so far)", new Exception("Flood cause")); _log.log(Log.CRIT, "Are we flooding the network with NetDb messages? (" + dosCount + " messages so far)", new Exception("Flood cause"));
} }
} }
}
/** /**
* Return number of netDb messages in this period, if flood, else 0 * Return number of netDb messages in this period, if flood, else 0

View File

@ -68,7 +68,7 @@ class ExploreJob extends SearchJob {
* @param expiration when the search should stop * @param expiration when the search should stop
*/ */
protected DatabaseLookupMessage buildMessage(TunnelId replyTunnelId, RouterInfo replyGateway, long expiration) { protected DatabaseLookupMessage buildMessage(TunnelId replyTunnelId, RouterInfo replyGateway, long expiration) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext()); DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(getState().getTarget()); msg.setSearchKey(getState().getTarget());
msg.setFrom(replyGateway.getIdentity().getHash()); msg.setFrom(replyGateway.getIdentity().getHash());
msg.setDontIncludePeers(getState().getAttempted()); msg.setDontIncludePeers(getState().getAttempted());

View File

@ -108,7 +108,7 @@ class HarvesterJob extends JobImpl {
*/ */
private void harvest(Hash peer) { private void harvest(Hash peer) {
long now = getContext().clock().now(); long now = getContext().clock().now();
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext()); DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setFrom(getContext().routerHash()); msg.setFrom(getContext().routerHash());
msg.setMessageExpiration(new Date(10*1000+now)); msg.setMessageExpiration(new Date(10*1000+now));
msg.setSearchKey(peer); msg.setSearchKey(peer);

View File

@ -355,7 +355,7 @@ class SearchJob extends JobImpl {
* @param expiration when the search should stop * @param expiration when the search should stop
*/ */
protected DatabaseLookupMessage buildMessage(TunnelId replyTunnelId, RouterInfo replyGateway, long expiration) { protected DatabaseLookupMessage buildMessage(TunnelId replyTunnelId, RouterInfo replyGateway, long expiration) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext()); DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(_state.getTarget()); msg.setSearchKey(_state.getTarget());
msg.setFrom(replyGateway.getIdentity().getHash()); msg.setFrom(replyGateway.getIdentity().getHash());
msg.setDontIncludePeers(_state.getAttempted()); msg.setDontIncludePeers(_state.getAttempted());
@ -370,7 +370,7 @@ class SearchJob extends JobImpl {
* *
*/ */
protected DatabaseLookupMessage buildMessage(long expiration) { protected DatabaseLookupMessage buildMessage(long expiration) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext()); DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(_state.getTarget()); msg.setSearchKey(_state.getTarget());
msg.setFrom(getContext().routerHash()); msg.setFrom(getContext().routerHash());
msg.setDontIncludePeers(_state.getAttempted()); msg.setDontIncludePeers(_state.getAttempted());