Replace deprecated getIP with getIPs in Protocol transferURL() and

getProfile().
Remember used ip for error handling and departInterface
pull/149/head
reger 8 years ago
parent ed36b47bec
commit 15d78b1064

@ -1611,7 +1611,8 @@ public final class Protocol {
String result = in.get("result");
if ( result == null ) {
String errorCause = "no result from transferRWI";
seeds.peerActions.peerDeparture(targetSeed, errorCause); // disconnect unavailable peer
String usedIP = in.get(Seed.IP);
seeds.peerActions.interfaceDeparture(targetSeed, usedIP); // disconnect unavailable peer
return errorCause;
}
@ -1647,7 +1648,8 @@ public final class Protocol {
result = in.get("result");
if ( result == null ) {
String errorCause = "no result from transferURL";
seeds.peerActions.peerDeparture(targetSeed, errorCause); // disconnect unavailable peer
String usedIP = in.get(Seed.IP);
seeds.peerActions.interfaceDeparture(targetSeed, usedIP); // disconnect unavailable peer ip
return errorCause;
}
@ -1738,6 +1740,7 @@ public final class Protocol {
final Map<String, String> result = FileUtils.table(v);
// return the transfered index data in bytes (for debugging only)
result.put("indexPayloadSize", Integer.toString(entrypost.length()));
result.put(Seed.IP, ip); // add used ip to result for error handling (in case no "result" key was received)
return result;
} catch (final Exception e ) {
Network.log.info("yacyClient.transferRWI to " + address + " error: " + e.getMessage());
@ -1748,6 +1751,17 @@ public final class Protocol {
return null;
}
/**
* Transfer URL entries to remote peer
*
* @param targetSeed
* @param uhs
* @param urlRefs
* @param segment
* @param gzipBody
* @param timeout
* @return remote peer response
*/
private static Map<String, String> transferURL(
final Seed targetSeed,
final String[] uhs,
@ -1756,7 +1770,7 @@ public final class Protocol {
boolean gzipBody,
final int timeout) {
// this post a message to the remote message board
String ip = targetSeed.getIP();
for (String ip : targetSeed.getIPs()) {
final String address = targetSeed.getPublicAddress(ip);
if ( address == null ) {
return null;
@ -1801,7 +1815,6 @@ public final class Protocol {
try {
parts.put("urlc", UTF8.StringBody(Integer.toString(urlc)));
// final byte[] content = HTTPConnector.getConnector(MultiProtocolURI.yacybotUserAgent).post(new MultiProtocolURI("http://" + address + "/yacy/transferURL.html"), timeout, targetSeed.getHexHash() + ".yacyh", parts, gzipBody);
final HTTPClient httpClient = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent, timeout);
final byte[] content =
httpClient.POSTbytes(
@ -1814,27 +1827,34 @@ public final class Protocol {
final Map<String, String> result = FileUtils.table(v);
// return the transfered url data in bytes (for debugging only)
result.put("urlPayloadSize", Integer.toString(urlPayloadSize));
result.put(Seed.IP, ip); // add used ip to result for error handling (in case no "result" key was received)
return result;
} catch (final Exception e ) {
Network.log.warn("yacyClient.transferURL to " + address + " error: " + e.getMessage());
return null;
}
}
return null;
}
/**
* Receive remote peers profile data
*
* @param targetSeed
* @return profile or null
*/
public static Map<String, String> getProfile(final Seed targetSeed) {
// ReferenceContainerCache<HostReference> ref = loadIDXHosts(targetSeed);
// this post a message to the remote message board
final String salt = crypt.randomSalt();
String address = targetSeed.getPublicAddress(targetSeed.getIP());
for (String ip : targetSeed.getIPs()) {
String address = targetSeed.getPublicAddress(ip);
if ( address == null ) {
address = "localhost:8090";
break;
}
try {
final Map<String, ContentBody> parts =
basicRequestParts(Switchboard.getSwitchboard(), targetSeed.hash, salt);
// final byte[] content = HTTPConnector.getConnector(MultiProtocolURI.yacybotUserAgent).post(new MultiProtocolURI("http://" + address + "/yacy/profile.html"), 5000, targetSeed.getHexHash() + ".yacyh", parts);
final HTTPClient httpclient = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent, 15000);
final byte[] content =
httpclient.POSTbytes(
@ -1845,9 +1865,10 @@ public final class Protocol {
return FileUtils.table(content);
} catch (final Exception e ) {
Network.log.warn("yacyClient.getProfile error:" + e.getMessage());
return null;
}
}
return null;
}
public static ReferenceContainerCache<HostReference> loadIDXHosts(final Seed target) {
final ReferenceContainerCache<HostReference> index =

Loading…
Cancel
Save