some patches to prevent that empty or bad IP information is broadcasted

- on client-side: fix bad IP reports from remote Peers by replacing their reported IP with their server IP if the reported IP is bad, broken or disallowed
- on server-side: the same during a peer ping (here the ping'ed server acts also as client during the back-ping) and also when receiving a message or a search where the client sends also its seed. Here the IP is replaced by the client IP if the reported IP is broken or bad

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7687 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 361841df16
commit 3b578a28ef

@ -749,6 +749,7 @@
<delete dir="${release_mac}" failonerror="false" verbose="false" />
</target>
<!-- to use the deb command the following debian packages must be installed: dpkg-dev debhelper m4 -->
<target name="deb" depends="init" description="Creates a debian package">
<!-- replacing the old with the new revision number -->
<replaceregexp file="debian/changelog"

@ -94,8 +94,6 @@ public class Status {
}
redirect = true;
} else if (post.containsKey("ResetTraffic")) {
// ByteCountInputStream.resetCount();
// ByteCountOutputStream.resetCount();
ByteCount.resetCount();
redirect = true;
} else if (post.containsKey("popup")) {
@ -153,7 +151,6 @@ public class Status {
}
// version information
//final String versionstring = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1"));
final String versionstring = yacyBuildProperties.getVersion() + "/" + yacyBuildProperties.getSVNRevision();

@ -91,7 +91,7 @@ public final class hello {
}
yacySeed remoteSeed;
try {
remoteSeed = yacySeed.genRemoteSeed(seed, key, true);
remoteSeed = yacySeed.genRemoteSeed(seed, key, true, ias.getHostAddress());
} catch (IOException e) {
yacyCore.log.logInfo("hello/server: bad seed: " + e.getMessage() + ", time_dnsResolve=" + time_dnsResolve);
prop.put("message", "bad seed: " + e.getMessage());

@ -30,11 +30,13 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.logging.Log;
@ -67,7 +69,9 @@ public final class message {
final String process = post.get("process", "permission");
final String key = post.get("key", "");
final String clientip = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "<unknown>"); // read an artificial header addendum
final InetAddress ias = Domains.dnsResolve(clientip);
final int messagesize = 10240;
final int attachmentsize = 0;
@ -110,7 +114,7 @@ public final class message {
//Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time
yacySeed otherSeed;
try {
otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false);
otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false, ias.getHostAddress());
} catch (IOException e) {
prop.put("response", "-1"); // don't accept messages for bad seeds
return prop;

@ -180,7 +180,7 @@ public final class search {
// store accessing peer
yacySeed remoteSeed;
try {
remoteSeed = yacySeed.genRemoteSeed(oseed, key, false);
remoteSeed = yacySeed.genRemoteSeed(oseed, key, false, client);
} catch (IOException e) {
yacyCore.log.logInfo("yacy.search: access with bad seed: " + e.getMessage());
remoteSeed = null;

@ -2661,7 +2661,7 @@ public final class Switchboard extends serverSwitch {
lc = 0;
while (enu.hasNext()) {
try {
ys = yacySeed.genRemoteSeed(enu.next(), null, false);
ys = yacySeed.genRemoteSeed(enu.next(), null, false, null);
if ((ys != null) &&
(!peers.mySeedIsDefined() || !peers.mySeed().hash.equals(ys.hash))) {
final long lastseen = Math.abs((System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60);

@ -63,6 +63,7 @@ import net.yacy.cora.document.RSSMessage;
import net.yacy.cora.document.RSSReader;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.cora.services.federated.opensearch.SRURSSConnector;
import net.yacy.kelondro.data.meta.URIMetadataRow;
@ -174,7 +175,10 @@ public final class yacyClient {
yacyCore.log.logInfo("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + yacySeed.maxsize + ")");
} else {
try {
otherPeer = yacySeed.genRemoteSeed(seed, salt, false);
int p = address.indexOf(':');
if (p < 0) return -1;
String host = Domains.dnsResolve(address.substring(0, p)).getHostAddress();
otherPeer = yacySeed.genRemoteSeed(seed, salt, false, host);
if (!otherPeer.hash.equals(otherHash)) {
yacyCore.log.logInfo("yacyClient.hello: consistency error: otherPeer.hash = " + otherPeer.hash + ", otherHash = " + otherHash);
return -1; // no success
@ -248,7 +252,14 @@ public final class yacyClient {
yacyCore.log.logInfo("hello/client: rejected contacting seed; too large (" + seedStr.length() + " > " + yacySeed.maxsize + ")");
} else {
try {
s = yacySeed.genRemoteSeed(seedStr, salt, false);
if (i == 1) {
int p = address.indexOf(':');
if (p < 0) return -1;
String host = Domains.dnsResolve(address.substring(0, p)).getHostAddress();
s = yacySeed.genRemoteSeed(seedStr, salt, false, host);
} else {
s = yacySeed.genRemoteSeed(seedStr, salt, false, null);
}
if (peerActions.peerArrival(s, (i == 1))) count++;
} catch (IOException e) {
yacyCore.log.logInfo("hello/client: rejected contacting seed; bad (" + e.getMessage() + ")");
@ -272,7 +283,7 @@ public final class yacyClient {
if (result == null || result.isEmpty()) { return null; }
//final Date remoteTime = yacyCore.parseUniversalDate((String) result.get(yacySeed.MYTIME)); // read remote time
return yacySeed.genRemoteSeed(result.get("response"), salt, false);
return yacySeed.genRemoteSeed(result.get("response"), salt, false, target.getIP());
} catch (final Exception e) {
yacyCore.log.logWarning("yacyClient.querySeed error:" + e.getMessage());
return null;

@ -295,8 +295,8 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac
* @return the IP or null
*/
public final String getIP() {
String ip = get(yacySeed.IP, "localhost");
return (ip == null || ip.length() == 0) ? "localhost" : ip;
String ip = get(yacySeed.IP, "127.0.0.1");
return (ip == null || ip.length() == 0) ? "127.0.0.1" : ip;
}
/**
* try to get the peertype<br>
@ -475,7 +475,7 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac
*/
public final String getPublicAddress() {
String ip = this.getIP();
if (ip == null || ip.length() < 8 || ip.length() > 60) ip = "localhost";
if (ip == null || ip.length() < 8 || ip.length() > 60) ip = "127.0.0.1";
final String port = this.dna.get(yacySeed.PORT);
if (port == null || port.length() < 2 || port.length() > 5) return null;
@ -772,7 +772,7 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac
return UTF8.getBytes(hash);
}
public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed) throws IOException {
public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed, String patchIP) throws IOException {
// this method is used to convert the external representation of a seed into a seed object
// yacyCore.log.logFinest("genRemoteSeed: seedStr=" + seedStr + " key=" + key);
@ -790,7 +790,14 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac
final yacySeed resultSeed = new yacySeed(hash, dna);
// check semantics of content
final String testResult = resultSeed.isProper(ownSeed);
String testResult = resultSeed.isProper(ownSeed);
if (testResult != null && patchIP != null) {
// in case that this proper-Test fails and a patchIP is given
// then replace the given IP in the resultSeed with given patchIP
// this is done if a remote peer reports its IP in a wrong way (maybe fraud attempt)
resultSeed.setIP(patchIP);
testResult = resultSeed.isProper(ownSeed);
}
if (testResult != null) throw new IOException("seed is not proper (" + testResult + "): " + resultSeed);
// seed ok
@ -883,7 +890,7 @@ public class yacySeed implements Cloneable, Comparable<yacySeed>, Comparator<yac
final char[] b = new char[(int) f.length()];
fr.read(b, 0, b.length);
fr.close();
final yacySeed mySeed = genRemoteSeed(new String(b), null, true);
final yacySeed mySeed = genRemoteSeed(new String(b), null, true, null);
assert mySeed != null; // in case of an error, an IOException is thrown
mySeed.dna.put(yacySeed.IP, ""); // set own IP as unknown
return mySeed;

@ -260,6 +260,10 @@ public final class yacySeedDB implements AlternativeDomainNames {
if (this.mySeed == null) {
if (this.sizeConnected() == 0) try {Thread.sleep(5000);} catch (final InterruptedException e) {} // wait for init
initMySeed();
// check if my seed has an IP assigned
if (this.myIP() == null || this.myIP().length() == 0) {
this.mySeed.setIP(Domains.myPublicLocalIP().getHostAddress());
}
}
return this.mySeed;
}

Loading…
Cancel
Save