From b9b446bca6ec750472b8fb2f1b34f1da2585aa44 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 10 May 2013 17:32:21 +0200 Subject: [PATCH] - added ssl configuration sign (a lock) to network statistic/table - fixed a bug in bitfield --- htroot/Network.html | 4 +- htroot/Network.java | 2 + source/net/yacy/cora/document/ASCII.java | 2 +- source/net/yacy/peers/Seed.java | 54 ++++++++++++++++-------- source/net/yacy/search/Switchboard.java | 34 ++++++++------- source/net/yacy/utils/bitfield.java | 44 ++++++++++++------- 6 files changed, 87 insertions(+), 53 deletions(-) diff --git a/htroot/Network.html b/htroot/Network.html index 939c893d6..8c3ac7924 100644 --- a/htroot/Network.html +++ b/htroot/Network.html @@ -146,7 +146,7 @@ To see a list of all APIs, please visit the Blog updated#(/updatedBlog)# #(isCrawling)#::Crawl#(/isCrawling)# - #[shortname]# + #[shortname]##(ssl)#::https supported#(/ssl)# #(type)##(direct)#Junior passive::Junior direct::Junior offline#(/direct)#::#(direct)#senior passive::Senior direct::Senior offline#(/direct)#::#(direct)#Principal passive::Principal active::Principal offline#(/direct)##(/type)##(acceptcrawl)#no crawl::crawl possible::crawl possible#(/acceptcrawl)##(dhtreceive)#no DHT receive::DHT receive enabled::DHT receive enabled#(/dhtreceive)##(nodestate)#no node candidate::node candidate#(/nodestate)# #[version]# @@ -258,7 +258,7 @@ To see a list of all APIs, please visit the - #[my-name]# + #[my-name]##(my-ssl)#::https supported#(/my-ssl)# #(my-info)#Virgin::Junior::Senior::Principal#(/my-info)##(my-acceptcrawl)#no crawl::Crawl enabled#(/my-acceptcrawl)##(my-dhtreceive)#no DHT receive::DHT Receive enabled#(/my-dhtreceive)##(my-nodestate)#no node candidate::node candidate#(/my-nodestate)# #[my-version]# #[my-utc]# diff --git a/htroot/Network.java b/htroot/Network.java index f73938259..c01456bfd 100644 --- a/htroot/Network.java +++ b/htroot/Network.java @@ -108,6 +108,7 @@ public class Network { // my-info prop.putHTML("table_my-name", seed.get(Seed.NAME, "-") ); prop.put("table_my-hash", seed.hash ); + prop.put("table_my-ssl", sb.peers.mySeed().getFlagSSLAvailable() ? 1 : 0); if (sb.peers.mySeed().isVirgin()) { prop.put("table_my-info", 0); } else if(sb.peers.mySeed().isJunior()) { @@ -378,6 +379,7 @@ public class Network { prop.putHTML(STR_TABLE_LIST + conCount + "_shortname", shortname); prop.putHTML(STR_TABLE_LIST + conCount + "_fullname", seed.get(Seed.NAME, "deadlink")); prop.put(STR_TABLE_LIST + conCount + "_special", (seed.getFlagRootNode() && !seed.getFlagAcceptRemoteIndex()) ? 1 : 0); + prop.put(STR_TABLE_LIST + conCount + "_ssl", (seed.getFlagSSLAvailable()) ? 1 : 0); userAgent = null; if (seed.hash != null && seed.hash.equals(sb.peers.mySeed().hash)) { userAgent = ClientIdentification.getUserAgent(); diff --git a/source/net/yacy/cora/document/ASCII.java b/source/net/yacy/cora/document/ASCII.java index 570ef829f..5b0cd36b6 100644 --- a/source/net/yacy/cora/document/ASCII.java +++ b/source/net/yacy/cora/document/ASCII.java @@ -125,7 +125,7 @@ public class ASCII implements Comparator { public final static byte[] getBytes(final String s) { assert s != null; - assert s.length() < 3 || s.charAt(2) != '@'; + //assert s.length() < 3 || s.charAt(2) != '@'; int count = s.length(); final byte[] b = new byte[count]; for (int i = 0; i < count; i++) { diff --git a/source/net/yacy/peers/Seed.java b/source/net/yacy/peers/Seed.java index 04291049f..3cd0cb411 100644 --- a/source/net/yacy/peers/Seed.java +++ b/source/net/yacy/peers/Seed.java @@ -100,19 +100,27 @@ public class Seed implements Cloneable, Comparable, Comparator */ public static final String URL_IN = "rU"; /** - * substance "virgin" + * substance "virgin", a peer which cannot reach any other peers */ public static final String PEERTYPE_VIRGIN = "virgin"; /** - * substance "junior" + * substance "junior", this is a peer which cannot be reached from the outside */ public static final String PEERTYPE_JUNIOR = "junior"; /** - * substance "senior" + * substance "mentee", this is a junior peer with an mentor peer attached as 'remote' server port + */ + public static final String PEERTYPE_MENTEE = "mentee"; + /** + * substance "senior", this is a peer with an open port to the public */ public static final String PEERTYPE_SENIOR = "senior"; /** - * substance "principal" + * substance "mentor", this is a senior peer which hosts server ports for mentee peers + */ + public static final String PEERTYPE_MENTOR = "mentor"; + /** + * substance "principal", a senior peer which distributes the seed list to an outside hoster (i.e. using ftp upload to a web server) */ public static final String PEERTYPE_PRINCIPAL = "principal"; /** @@ -123,7 +131,7 @@ public class Seed implements Cloneable, Comparable, Comparator /** static/dynamic (if the IP changes often for any reason) */ private static final String IPTYPE = "IPType"; private static final String FLAGS = "Flags"; - private static final String FLAGSZERO = "____"; + public static final String FLAGSZERO = " "; /** the applications version */ public static final String VERSION = "Version"; @@ -168,6 +176,7 @@ public class Seed implements Cloneable, Comparable, Comparator 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; + private static final int FLAG_SSL_AVAILABLE = 4; public static final String DFLT_NETWORK_UNIT = "freeworld"; public static final String DFLT_NETWORK_GROUP = ""; @@ -758,41 +767,50 @@ public class Seed implements Cloneable, Comparable, Comparator setFlag(FLAG_DIRECT_CONNECT, value); } - public final void setFlagAcceptRemoteCrawl(final boolean value) { - setFlag(FLAG_ACCEPT_REMOTE_CRAWL, value); - } - - 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(FLAG_DIRECT_CONNECT); } + public final void setFlagAcceptRemoteCrawl(final boolean value) { + setFlag(FLAG_ACCEPT_REMOTE_CRAWL, value); + } + public final boolean getFlagAcceptRemoteCrawl() { //if (getVersion() < 0.300) return false; //if (getVersion() < 0.334) return true; return getFlag(FLAG_ACCEPT_REMOTE_CRAWL); } + public final void setFlagAcceptRemoteIndex(final boolean value) { + setFlag(FLAG_ACCEPT_REMOTE_INDEX, value); + } + public final boolean getFlagAcceptRemoteIndex() { //if (getVersion() < 0.335) return false; return getFlag(FLAG_ACCEPT_REMOTE_INDEX); } + public final void setFlagRootNode(final boolean value) { + setFlag(FLAG_ROOT_NODE, value); + } + public final boolean getFlagRootNode() { double v = getVersion(); if (v < 1.02009142d) return false; return getFlag(FLAG_ROOT_NODE); } + public final void setFlagSSLAvailable(final boolean value) { + setFlag(FLAG_SSL_AVAILABLE, value); + } + + public final boolean getFlagSSLAvailable() { + if (getVersion() < 1.5) return false; + return getFlag(FLAG_SSL_AVAILABLE); + } + public final void setUnusedFlags() { - for ( int i = 4; i < 24; i++ ) { + for ( int i = 4; i < 20; i++ ) { setFlag(i, false); } } diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java index 693b7b362..9b5c72607 100644 --- a/source/net/yacy/search/Switchboard.java +++ b/source/net/yacy/search/Switchboard.java @@ -3524,33 +3524,35 @@ public final class Switchboard extends serverSwitch { //the speed of indexing (pages/minute) of the peer final long uptime = (System.currentTimeMillis() - serverCore.startupTime) / 1000; - this.peers.mySeed().put(Seed.ISPEED, Integer.toString(currentPPM())); - this.peers.mySeed().put(Seed.RSPEED, Float.toString(averageQPM())); - this.peers.mySeed().put(Seed.UPTIME, Long.toString(uptime / 60)); // the number of minutes that the peer is up in minutes/day (moving average MA30) + Seed mySeed = this.peers.mySeed(); + + mySeed.put(Seed.ISPEED, Integer.toString(currentPPM())); + mySeed.put(Seed.RSPEED, Float.toString(averageQPM())); + mySeed.put(Seed.UPTIME, Long.toString(uptime / 60)); // the number of minutes that the peer is up in minutes/day (moving average MA30) long t = System.currentTimeMillis(); if (t - indexSizeTime > 60000) { indeSizeCache = sb.index.fulltext().collectionSize(); indexSizeTime = t; } - this.peers.mySeed().put(Seed.LCOUNT, Long.toString(indeSizeCache)); // the number of links that the peer has stored (LURL's) - this.peers.mySeed().put(Seed.NCOUNT, Integer.toString(this.crawlQueues.noticeURL.size())); // the number of links that the peer has noticed, but not loaded (NURL's) - this.peers.mySeed().put( + mySeed.put(Seed.LCOUNT, Long.toString(indeSizeCache)); // the number of links that the peer has stored (LURL's) + mySeed.put(Seed.NCOUNT, Integer.toString(this.crawlQueues.noticeURL.size())); // the number of links that the peer has noticed, but not loaded (NURL's) + mySeed.put( Seed.RCOUNT, Integer.toString(this.crawlQueues.noticeURL.stackSize(NoticedURL.StackType.GLOBAL))); // the number of links that the peer provides for remote crawling (ZURL's) - this.peers.mySeed().put(Seed.ICOUNT, Long.toString(this.index.RWICount())); // the minimum number of words that the peer has indexed (as it says) - this.peers.mySeed().put(Seed.SCOUNT, Integer.toString(this.peers.sizeConnected())); // the number of seeds that the peer has stored - this.peers.mySeed().put( + mySeed.put(Seed.ICOUNT, Long.toString(this.index.RWICount())); // the minimum number of words that the peer has indexed (as it says) + mySeed.put(Seed.SCOUNT, Integer.toString(this.peers.sizeConnected())); // the number of seeds that the peer has stored + mySeed.put( Seed.CCOUNT, Float.toString(((int) ((this.peers.sizeConnected() + this.peers.sizeDisconnected() + this.peers .sizePotential()) * 60.0f / (uptime + 1.01f)) * 100.0f) / 100.0f)); // the number of clients that the peer connects (as connects/hour) - this.peers.mySeed().put(Seed.VERSION, yacyBuildProperties.getLongVersion()); - this.peers.mySeed().setFlagDirectConnect(true); - this.peers.mySeed().setLastSeenUTC(); - this.peers.mySeed().put(Seed.UTC, GenericFormatter.UTCDiffString()); - this.peers.mySeed().setFlagAcceptRemoteCrawl(getConfigBool("crawlResponse", true)); - this.peers.mySeed().setFlagAcceptRemoteIndex(getConfigBool("allowReceiveIndex", true)); - //mySeed.setFlagAcceptRemoteIndex(true); + mySeed.put(Seed.VERSION, yacyBuildProperties.getLongVersion()); + mySeed.setFlagDirectConnect(true); + mySeed.setLastSeenUTC(); + mySeed.put(Seed.UTC, GenericFormatter.UTCDiffString()); + mySeed.setFlagAcceptRemoteCrawl(getConfigBool("crawlResponse", true)); + mySeed.setFlagAcceptRemoteIndex(getConfigBool("allowReceiveIndex", true)); + mySeed.setFlagSSLAvailable(getConfigBool("server.https", false)); } public void loadSeedLists() { diff --git a/source/net/yacy/utils/bitfield.java b/source/net/yacy/utils/bitfield.java index fe7aebd55..81c1478ce 100644 --- a/source/net/yacy/utils/bitfield.java +++ b/source/net/yacy/utils/bitfield.java @@ -4,10 +4,6 @@ // first published on http://www.anomic.de // Frankfurt, Germany, 2004 // -// $LastChangedDate$ -// $LastChangedRevision$ -// $LastChangedBy$ -// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or @@ -24,6 +20,9 @@ package net.yacy.utils; +import net.yacy.cora.document.ASCII; + + public class bitfield { private byte[] bb; @@ -34,7 +33,7 @@ public class bitfield { public bitfield(final int bytelength) { this.bb= new byte[bytelength]; - for (int i = 0 ; i < bytelength; i++) bb[i] = 0; + for (int i = 0 ; i < bytelength; i++) bb[i] = ' '; } public bitfield(final byte[] field) { @@ -43,16 +42,18 @@ public class bitfield { private static byte setAtom(final byte a, final int pos) { if ((pos > 5) || (pos < 0)) throw new RuntimeException("atom position out of bounds: " + pos); - return (byte) ((64 | ((a + 16) | (1< 5) || (pos < 0)) throw new RuntimeException("atom position out of bounds: " + pos); - return (byte) (((a + 16) & (0xff ^ (1< bb.length) { // extend capacity @@ -61,18 +62,19 @@ public class bitfield { for (int i = bb.length; i < nb.length; i++) nb[i] = 0; bb = nb; } - bb[slot] = (value) ? setAtom(bb[slot], pos % 6) : unsetAtom(bb[slot], pos % 6); + bb[slot] = (value) ? setAtom(bb[slot], pos % 5) : unsetAtom(bb[slot], pos % 5); } public boolean get(final int pos) { - final int slot = pos / 6; + final int slot = pos / 5; if (pos < 0) throw new RuntimeException("position out of bounds: " + pos); if (slot > bb.length) return false; - return (bb[slot] & (1<<(pos%6))) > 0; + boolean b = ((bb[slot] - 32) & (1 << (pos % 5))) > 0; + return b; } public int length() { - return bb.length * 6; + return bb.length * 5; } public byte[] getBytes() { @@ -81,15 +83,25 @@ public class bitfield { @Override public String toString() { - throw new UnsupportedOperationException("testing"); - /* + //throw new UnsupportedOperationException("testing"); + StringBuilder sb = new StringBuilder(length()); for (int i = length() - 1; i >= 0; i--) sb.append((get(i)) ? '1' : '0'); - return sb.toString(); - */ + return ASCII.String(bb) + " " + sb.toString(); + } public static void main(final String[] args) { + //final bitfield f = new bitfield(ASCII.getBytes(Seed.FLAGSZERO)); + final bitfield f = new bitfield(4); + for (int i = 0; i < 20; i++) { + f.set(i, false); + if (f.get(i)) System.out.println("i = " + i); + f.set(i, true); + if (!f.get(i)) System.out.println("!i = " + i); + System.out.println(i + ":" + f.toString()); + } + final bitfield test = new bitfield(4); final int l = test.length(); System.out.println("available: " + l);