From 59fc55ea1e6b91cb8939a31ab936ec22033ef5fa Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 20 Mar 2006 20:31:51 +0000 Subject: [PATCH] added checks to protect peers from wrong seeds see also: http://www.yacy-forum.de/viewtopic.php?p=19249#19249 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1939 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/net/natLib.java | 27 +++++++++++----------- source/de/anomic/yacy/yacyPeerActions.java | 3 +++ source/de/anomic/yacy/yacySeed.java | 4 +++- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/source/de/anomic/net/natLib.java b/source/de/anomic/net/natLib.java index 95008ac92..7a72dceff 100644 --- a/source/de/anomic/net/natLib.java +++ b/source/de/anomic/net/natLib.java @@ -125,19 +125,20 @@ public class natLib { //TODO: This is not IPv6 compatible public static boolean isProper(String ip) { - plasmaSwitchboard sb=plasmaSwitchboard.getSwitchboard(); - if (sb == null) return false; - String yacyDebugMode = sb.getConfig("yacyDebugMode", "false"); - if(yacyDebugMode.equals("true")){ - return true; - } - //support for staticIP - if(sb.getConfig("staticIP", "").equals(ip)){ - return true; - } - if (ip == null) return false; - if (ip.indexOf(":") >= 0) return false; // ipv6... - return ( isNotLocal(ip)) && (isIP(ip) ); + plasmaSwitchboard sb=plasmaSwitchboard.getSwitchboard(); + if (sb != null) { + String yacyDebugMode = sb.getConfig("yacyDebugMode", "false"); + if (yacyDebugMode.equals("true")) { + return true; + } + // support for staticIP + if (sb.getConfig("staticIP", "").equals(ip)) { + return true; + } + } + if (ip == null) return false; + if (ip.indexOf(":") >= 0) return false; // ipv6... + return (isNotLocal(ip)) && (isIP(ip)); } private static int retrieveOptions() { diff --git a/source/de/anomic/yacy/yacyPeerActions.java b/source/de/anomic/yacy/yacyPeerActions.java index 2fb5a6b91..b486f6d52 100644 --- a/source/de/anomic/yacy/yacyPeerActions.java +++ b/source/de/anomic/yacy/yacyPeerActions.java @@ -400,6 +400,7 @@ public class yacyPeerActions { } public boolean peerArrival(yacySeed peer, boolean direct) { + if (peer == null) return false; boolean res = connectPeer(peer, direct); // perform all actions if peer is effective new if (res) { @@ -410,6 +411,7 @@ public class yacyPeerActions { } public void peerDeparture(yacySeed peer) { + if (peer == null) return; //System.out.println("PEER DEPARTURE:" + peer.toString()); disconnectPeer(peer); // perform all actions @@ -418,6 +420,7 @@ public class yacyPeerActions { } public void peerPing(yacySeed peer) { + if (peer == null) return; // this is called only if the peer has junior status seedDB.addPotential(peer); // perform all actions diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java index 8e61c5835..81f24e0c9 100644 --- a/source/de/anomic/yacy/yacySeed.java +++ b/source/de/anomic/yacy/yacySeed.java @@ -605,7 +605,9 @@ public class yacySeed { if (seed == null) { return null; } final HashMap dna = serverCodings.string2map(seed); final String hash = (String) dna.remove("Hash"); - return new yacySeed(hash, dna); + yacySeed resultSeed = new yacySeed(hash, dna); + if (resultSeed.isProper() == null) return resultSeed; + return null; } public String toString() {