Skip to content

Commit

Permalink
another performance hack: re-use of known host addresses for isLocal …
Browse files Browse the repository at this point in the history
…property; avoids look-up in local hash

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7983 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Sep 30, 2011
1 parent 035ebfb commit 813f297
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 97 deletions.
31 changes: 15 additions & 16 deletions htroot/Collage.java
@@ -1,4 +1,4 @@
// Collage.java
// Collage.java
// -----------------------
// part of YaCy
// (C) by Detlef Reichl; detlef!reichl()gmx!org
Expand Down Expand Up @@ -28,26 +28,25 @@
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.search.Switchboard;

import de.anomic.crawler.ResultImages;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;

public class Collage {
private static int fifoMax = 20;

private static int fifoPos = -1;
private static int fifoSize = 0;
private static long zIndex = 0;

private static ResultImages.OriginEntry origins[] = new ResultImages.OriginEntry[fifoMax];
private static Integer imgWidth[] = new Integer[fifoMax];
private static Integer imgHeight[] = new Integer[fifoMax];
private static Integer imgPosX[] = new Integer[fifoMax];
private static Integer imgPosY[] = new Integer[fifoMax];
private static long imgZIndex[] = new long[fifoMax];
private static final Random rand = new Random();

public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final serverObjects prop = new serverObjects();
final Switchboard sb = (Switchboard) env;
Expand All @@ -56,48 +55,48 @@ public static serverObjects respond(final RequestHeader header, final serverObje
int posXMax = 800;
int posYMax = 500;
boolean embed = false;

if (post != null) {
embed = post.containsKey("emb");
posXMax = post.getInt("width", posXMax);
posYMax = post.getInt("height", posYMax);
if (post.containsKey("max")) fifoMax = post.getInt("max", fifoMax);
}
prop.put("emb", (embed) ? "0" : "1");

if (nextOrigin != null) {
System.out.println("NEXTORIGIN=" + nextOrigin.imageEntry.url().toNormalform(true, false));
if (fifoSize == 0 || origins[fifoPos] != nextOrigin) {
fifoPos = fifoPos + 1 >= fifoMax ? 0 : fifoPos + 1;
fifoSize = fifoSize + 1 > fifoMax ? fifoMax : fifoSize + 1;
origins[fifoPos] = nextOrigin;

final float scale = rand.nextFloat() * 1.5f + 1;
imgWidth[fifoPos] = (int) ((nextOrigin.imageEntry.width()) / scale);
imgHeight[fifoPos] = (int) ((nextOrigin.imageEntry.height()) / scale);

imgPosX[fifoPos] = rand.nextInt((imgWidth[fifoPos] == 0) ? posXMax / 2 : Math.max(1, posXMax - imgWidth[fifoPos]));
imgPosY[fifoPos] = rand.nextInt((imgHeight[fifoPos] == 0) ? posYMax / 2 : Math.max(1, posYMax - imgHeight[fifoPos]));

imgZIndex[fifoPos] = zIndex;
zIndex += 1;
}
}

if (fifoSize > 0) {
prop.put("imgurl", "1");
prop.put("imgurl", "1");
int c = 0;
final int yOffset = embed ? 0 : 70;
for (int i = 0; i < fifoSize; i++) {

final MultiProtocolURI baseURL = origins[i].baseURL;
final MultiProtocolURI imageURL = origins[i].imageEntry.url();

// check if this loads a page from localhost, which must be prevented to protect the server
// against attacks to the administration interface when localhost access is granted
if ((Domains.isLocal(baseURL.getHost()) || Domains.isLocal(imageURL.getHost())) &&
if ((Domains.isLocal(baseURL.getHost(), null) || Domains.isLocal(imageURL.getHost(), null)) &&
sb.getConfigBool("adminAccountForLocalhost", false)) continue;

final long z = imgZIndex[i];
prop.put("imgurl_list_" + c + "_url",
"<a href=\"" + baseURL.toNormalform(true, false) + "\">"
Expand All @@ -118,7 +117,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
} else {
prop.put("imgurl", "0");
}

prop.putNum("refresh", Math.max(2, Math.min(5, 500 / (1 + ResultImages.queueSize(!authenticated)))));
prop.put("emb_privateQueueSize", ResultImages.privateQueueHighSize() + "+" + ResultImages.privateQueueLowSize());
prop.put("emb_publicQueueSize", ResultImages.publicQueueHighSize() + "+" + ResultImages.publicQueueLowSize());
Expand Down
2 changes: 1 addition & 1 deletion htroot/yacy/search.java
Expand Up @@ -167,7 +167,7 @@ public static serverObjects respond(final RequestHeader header, final serverObje
block = true;
}
}
if (block && Domains.isLocal(client)) block = false;
if (block && Domains.isLocal(client, null)) block = false;
if (block) {
prop.put("links", "");
prop.put("linkcount", "0");
Expand Down

0 comments on commit 813f297

Please sign in to comment.