|
|
|
@ -170,8 +170,8 @@ public final class Protocol {
|
|
|
|
|
public static Map<String, String> hello(
|
|
|
|
|
final Seed mySeed,
|
|
|
|
|
final PeerActions peerActions,
|
|
|
|
|
final Seed otherSeed) {
|
|
|
|
|
final String address = otherSeed.getPublicAddress(otherSeed.getIP());
|
|
|
|
|
final String targetAddress,
|
|
|
|
|
final String targetHash) {
|
|
|
|
|
|
|
|
|
|
Map<String, String> result = null;
|
|
|
|
|
final String salt = crypt.randomSalt();
|
|
|
|
@ -190,8 +190,8 @@ public final class Protocol {
|
|
|
|
|
final HTTPClient httpClient = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent, 30000);
|
|
|
|
|
content =
|
|
|
|
|
httpClient.POSTbytes(
|
|
|
|
|
new MultiProtocolURL("http://" + address + "/yacy/hello.html"),
|
|
|
|
|
Seed.b64Hash2hexHash(otherSeed.hash) + ".yacyh",
|
|
|
|
|
new MultiProtocolURL("http://" + targetAddress + "/yacy/hello.html"),
|
|
|
|
|
Seed.b64Hash2hexHash(targetHash) + ".yacyh",
|
|
|
|
|
parts,
|
|
|
|
|
false, true);
|
|
|
|
|
responseTime = System.currentTimeMillis() - start;
|
|
|
|
@ -203,7 +203,7 @@ public final class Protocol {
|
|
|
|
|
+ "' interrupted.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
Network.log.info("yacyClient.hello thread '" + Thread.currentThread().getName() + "', peer " + address + "; exception: " + e.getMessage());
|
|
|
|
|
Network.log.info("yacyClient.hello thread '" + Thread.currentThread().getName() + "', peer " + targetAddress + "; exception: " + e.getMessage());
|
|
|
|
|
// try again (go into loop)
|
|
|
|
|
result = null;
|
|
|
|
|
}
|
|
|
|
@ -216,7 +216,7 @@ public final class Protocol {
|
|
|
|
|
Network.log.info("yacyClient.hello thread '"
|
|
|
|
|
+ Thread.currentThread().getName()
|
|
|
|
|
+ "' contacted peer at "
|
|
|
|
|
+ address
|
|
|
|
|
+ targetAddress
|
|
|
|
|
+ ", received "
|
|
|
|
|
+ ((content == null) ? "null" : content.length)
|
|
|
|
|
+ " bytes, time = "
|
|
|
|
@ -226,21 +226,21 @@ public final class Protocol {
|
|
|
|
|
// check consistency with expectation
|
|
|
|
|
Seed otherPeer = null;
|
|
|
|
|
String seed;
|
|
|
|
|
if ( (otherSeed.hash != null) && (otherSeed.hash.length() > 0) && ((seed = result.get("seed0")) != null) ) {
|
|
|
|
|
if ( (targetHash != null) && (targetHash.length() > 0) && ((seed = result.get("seed0")) != null) ) {
|
|
|
|
|
if ( seed.length() > Seed.maxsize ) {
|
|
|
|
|
Network.log.info("hello/client 0: rejected contacting seed; too large (" + seed.length() + " > " + Seed.maxsize + ")");
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
// patch the remote peer address to avoid that remote peers spoof the network with wrong addresses
|
|
|
|
|
final int p = address.lastIndexOf(':');
|
|
|
|
|
final int p = targetAddress.lastIndexOf(':');
|
|
|
|
|
if ( p < 0 ) return null;
|
|
|
|
|
String h = address.substring(0, p);
|
|
|
|
|
String h = targetAddress.substring(0, p);
|
|
|
|
|
if (h.charAt(0) == '[') h = h.substring(1);
|
|
|
|
|
if (h.charAt(h.length() - 1) == ']') h = h.substring(0, h.length() - 1);
|
|
|
|
|
InetAddress ie = Domains.dnsResolve(h);
|
|
|
|
|
otherPeer = Seed.genRemoteSeed(seed, false, ie.getHostAddress());
|
|
|
|
|
if ( !otherPeer.hash.equals(otherSeed.hash) ) {
|
|
|
|
|
Network.log.info("yacyClient.hello: consistency error: otherPeer.hash = " + otherPeer.hash + ", otherHash = " + otherSeed.hash);
|
|
|
|
|
if ( !otherPeer.hash.equals(targetHash) ) {
|
|
|
|
|
Network.log.info("yacyClient.hello: consistency error: otherPeer.hash = " + otherPeer.hash + ", otherHash = " + targetHash);
|
|
|
|
|
return null; // no success
|
|
|
|
|
}
|
|
|
|
|
} catch (final IOException e ) {
|
|
|
|
@ -285,7 +285,7 @@ public final class Protocol {
|
|
|
|
|
accessible.IWasAccessed = false;
|
|
|
|
|
}
|
|
|
|
|
accessible.lastUpdated = System.currentTimeMillis();
|
|
|
|
|
Network.amIAccessibleDB.put(otherSeed.hash, accessible);
|
|
|
|
|
Network.amIAccessibleDB.put(targetHash, accessible);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we were reported as junior we have to check if your port forwarding channel is broken
|
|
|
|
@ -329,7 +329,6 @@ public final class Protocol {
|
|
|
|
|
|
|
|
|
|
// read the seeds that the peer returned and integrate them into own database
|
|
|
|
|
int i = 0;
|
|
|
|
|
int count = 0;
|
|
|
|
|
String seedStr;
|
|
|
|
|
Seed s;
|
|
|
|
|
final int connectedBefore = peerActions.sizeConnected();
|
|
|
|
@ -337,39 +336,31 @@ public final class Protocol {
|
|
|
|
|
// integrate new seed into own database
|
|
|
|
|
// the first seed, "seed0" is the seed of the responding peer
|
|
|
|
|
if ( seedStr.length() > Seed.maxsize ) {
|
|
|
|
|
Network.log.info("hello/client: rejected contacting seed; too large ("
|
|
|
|
|
+ seedStr.length()
|
|
|
|
|
+ " > "
|
|
|
|
|
+ Seed.maxsize
|
|
|
|
|
+ ")");
|
|
|
|
|
Network.log.info("hello/client: rejected contacting seed; too large ("+ seedStr.length() + " > " + Seed.maxsize + ")");
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
if ( i == 1 ) {
|
|
|
|
|
final int p = address.indexOf(':');
|
|
|
|
|
final int p = targetAddress.lastIndexOf(':');
|
|
|
|
|
if ( p < 0 ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
InetAddress ia = Domains.dnsResolve(address.substring(0, p));
|
|
|
|
|
InetAddress ia = Domains.dnsResolve(targetAddress.substring(0, p));
|
|
|
|
|
if (ia == null) continue;
|
|
|
|
|
final String host = ia.getHostAddress();
|
|
|
|
|
final String host = ia.getHostAddress(); // the actual address of the target as we had been successful when contacting them is patched here
|
|
|
|
|
s = Seed.genRemoteSeed(seedStr, false, host);
|
|
|
|
|
} else {
|
|
|
|
|
s = Seed.genRemoteSeed(seedStr, false, null);
|
|
|
|
|
}
|
|
|
|
|
if ( peerActions.peerArrival(s, (i == 1)) ) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
peerActions.peerArrival(s, (i == 1));
|
|
|
|
|
} catch (final IOException e ) {
|
|
|
|
|
Network.log.info("hello/client: rejected contacting seed; bad ("
|
|
|
|
|
+ e.getMessage()
|
|
|
|
|
+ ")");
|
|
|
|
|
Network.log.info("hello/client: rejected contacting seed; bad (" + e.getMessage() + ")");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
final int connectedAfter = peerActions.sizeConnected();
|
|
|
|
|
|
|
|
|
|
// update event tracker
|
|
|
|
|
EventTracker.update(EventTracker.EClass.PEERPING, new ProfilingGraph.EventPing(mySeed.getName(), otherSeed.getName(), true, connectedAfter - connectedBefore), false);
|
|
|
|
|
EventTracker.update(EventTracker.EClass.PEERPING, new ProfilingGraph.EventPing(mySeed.getName(), targetHash, true, connectedAfter - connectedBefore), false);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|