From 3c2bec681f3d6a16c16279b52471f4d4c63a317b Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 25 May 2012 15:33:02 +0200 Subject: [PATCH] added a root node flag: identifies peers with short ping time --- source/net/yacy/peers/Protocol.java | 15 ++++++++++----- source/net/yacy/peers/Seed.java | 7 ++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/source/net/yacy/peers/Protocol.java b/source/net/yacy/peers/Protocol.java index c9b6500a4..53c229c08 100644 --- a/source/net/yacy/peers/Protocol.java +++ b/source/net/yacy/peers/Protocol.java @@ -171,6 +171,7 @@ public final class Protocol Map result = null; final String salt = crypt.randomSalt(); + long responseTime = Long.MAX_VALUE; try { // generate request final Map parts = @@ -188,6 +189,7 @@ public final class Protocol Seed.b64Hash2hexHash(otherHash) + ".yacyh", parts, false); + responseTime = System.currentTimeMillis() - start; Network.log.logInfo("yacyClient.hello thread '" + Thread.currentThread().getName() + "' contacted peer at " @@ -195,7 +197,7 @@ public final class Protocol + ", received " + ((content == null) ? "null" : content.length) + " bytes, time = " - + (System.currentTimeMillis() - start) + + responseTime + " milliseconds"); result = FileUtils.table(content); } catch ( final Exception e ) { @@ -256,6 +258,12 @@ public final class Protocol } } + // get access type response + String mytype = result.get(Seed.YOURTYPE); + if ( mytype == null ) { + mytype = ""; + } + // set my own seed according to new information // we overwrite our own IP number only if ( serverCore.useStaticIP ) { @@ -263,16 +271,13 @@ public final class Protocol } else { final String myIP = result.get("yourip"); final String properIP = Seed.isProperIP(myIP); + mySeed.setFlagRootNode(mytype.equals(Seed.PEERTYPE_SENIOR) && responseTime < 1000 && Domains.isThisHostIP(myIP)); if ( properIP == null ) { mySeed.setIP(myIP); } } // change our seed-type - String mytype = result.get(Seed.YOURTYPE); - if ( mytype == null ) { - mytype = ""; - } final Accessible accessible = new Accessible(); if ( mytype.equals(Seed.PEERTYPE_SENIOR) || mytype.equals(Seed.PEERTYPE_PRINCIPAL) ) { accessible.IWasAccessed = true; diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.java index d04c6eae6..928a89792 100644 --- a/source/net/yacy/peers/Seed.java +++ b/source/net/yacy/peers/Seed.java @@ -167,6 +167,7 @@ public class Seed implements Cloneable, Comparable, Comparator private static final int FLAG_DIRECT_CONNECT = 0; private static final int FLAG_ACCEPT_REMOTE_CRAWL = 1; private static final int FLAG_ACCEPT_REMOTE_INDEX = 2; + private static final int FLAG_ROOT_NODE = 3; public static final String DFLT_NETWORK_UNIT = "freeworld"; public static final String DFLT_NETWORK_GROUP = ""; @@ -764,7 +765,11 @@ public class Seed implements Cloneable, Comparable, Comparator public final void setFlagAcceptRemoteIndex(final boolean value) { setFlag(FLAG_ACCEPT_REMOTE_INDEX, value); } - + + public final void setFlagRootNode(final boolean value) { + setFlag(FLAG_ROOT_NODE, value); + } + public final boolean getFlagDirectConnect() { return getFlag(0); }