fix for stretched network image

pull/1/head
Michael Christen 14 years ago
parent 762e0ecfb6
commit 89dc04115f

@ -36,27 +36,39 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
/** draw a picture of the yacy network */ /** draw a picture of the yacy network */
public class NetworkPicture { public class NetworkPicture
{
private static final Semaphore sync = new Semaphore(1, true); private static final Semaphore sync = new Semaphore(1, true);
private static EncodedImage buffer = null; private static EncodedImage buffer = null;
private static long lastAccessSeconds = 0; private static long lastAccessSeconds = 0;
public static EncodedImage respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static EncodedImage respond(
final RequestHeader header,
final serverObjects post,
final serverSwitch env) {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
final boolean authorized = sb.adminAuthenticated(header) >= 2; final boolean authorized = sb.adminAuthenticated(header) >= 2;
final long timeSeconds = System.currentTimeMillis() / 1000; final long timeSeconds = System.currentTimeMillis() / 1000;
if ( buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2 ) { if ( buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2 ) {
Log.logInfo("NetworkPicture", "cache hit (1); authorized = " + authorized + ", timeSeconds - lastAccessSeconds = " + (timeSeconds - lastAccessSeconds)); Log.logInfo("NetworkPicture", "cache hit (1); authorized = "
+ authorized
+ ", timeSeconds - lastAccessSeconds = "
+ (timeSeconds - lastAccessSeconds));
return buffer; return buffer;
} }
if (buffer != null && sync.availablePermits() == 0) return buffer; if ( buffer != null && sync.availablePermits() == 0 ) {
return buffer;
}
sync.acquireUninterruptibly(); sync.acquireUninterruptibly();
if ( buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2 ) { if ( buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2 ) {
Log.logInfo("NetworkPicture", "cache hit (2); authorized = " + authorized + ", timeSeconds - lastAccessSeconds = " + (timeSeconds - lastAccessSeconds)); Log.logInfo("NetworkPicture", "cache hit (2); authorized = "
+ authorized
+ ", timeSeconds - lastAccessSeconds = "
+ (timeSeconds - lastAccessSeconds));
sync.release(); sync.release();
return buffer; return buffer;
} }
@ -86,18 +98,46 @@ public class NetworkPicture {
} }
//too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS. //too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS.
if (width < 320 ) width = 320; if ( width < 320 ) {
if (width > 1920) width = 1920; width = 320;
if (height < 240) height = 240; }
if (height > 1080) height = 1080; if ( width > 1920 ) {
width = 1920;
}
if ( height < 240 ) {
height = 240;
}
if ( height > 1080 ) {
height = 1080;
}
if ( !authorized ) { if ( !authorized ) {
width = Math.min(1024, width); width = Math.min(1024, width);
height = Math.min(576, height); height = Math.min(1024, height);
}
if ( passiveLimit > 1000000 ) {
passiveLimit = 1000000;
}
if ( potentialLimit > 1000000 ) {
potentialLimit = 1000000;
}
if ( maxCount > 10000 ) {
maxCount = 10000;
} }
if (passiveLimit > 1000000) passiveLimit = 1000000; buffer =
if (potentialLimit > 1000000) potentialLimit = 1000000; new EncodedImage(NetworkGraph.getNetworkPicture(
if (maxCount > 10000) maxCount = 10000; sb.peers,
buffer = new EncodedImage(NetworkGraph.getNetworkPicture(sb.peers, 10000, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, communicationTimeout, env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig("network.unit.description", "unspecified"), bgcolor, cyc).getImage(), "png"); 10000,
width,
height,
passiveLimit,
potentialLimit,
maxCount,
coronaangle,
communicationTimeout,
env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"),
env.getConfig("network.unit.description", "unspecified"),
bgcolor,
cyc).getImage(), "png");
lastAccessSeconds = System.currentTimeMillis() / 1000; lastAccessSeconds = System.currentTimeMillis() / 1000;
sync.release(); sync.release();

Loading…
Cancel
Save