@ -487,8 +487,14 @@ public final class Protocol {
SearchResult result = null ;
SearchResult result = null ;
for ( String ip : target . getIPs ( ) ) {
for ( String ip : target . getIPs ( ) ) {
//if (ip.indexOf(':') >= 0) System.out.println("Search target: IPv6: " + ip);
//if (ip.indexOf(':') >= 0) System.out.println("Search target: IPv6: " + ip);
String clusteraddress = target . getPublicAddress ( ip ) ;
final String targetBaseURL ;
if ( target . clash ( event . peers . mySeed ( ) . getIPs ( ) ) ) clusteraddress = "localhost:" + event . peers . mySeed ( ) . getPort ( ) ;
if ( target . clash ( event . peers . mySeed ( ) . getIPs ( ) ) ) {
targetBaseURL = "http://localhost:" + event . peers . mySeed ( ) . getPort ( ) ;
} else {
targetBaseURL = target . getPublicURL ( ip ,
Switchboard . getSwitchboard ( ) . getConfigBool ( SwitchboardConstants . REMOTESEARCH_HTTPS_PREFERRED ,
SwitchboardConstants . REMOTESEARCH_HTTPS_PREFERRED_DEFAULT ) ) ;
}
try {
try {
result =
result =
new SearchResult (
new SearchResult (
@ -504,13 +510,18 @@ public final class Protocol {
maxDistance ,
maxDistance ,
partitions ,
partitions ,
target . getHexHash ( ) + ".yacyh" ,
target . getHexHash ( ) + ".yacyh" ,
clusteraddress ,
targetBaseURL ,
secondarySearchSuperviser
secondarySearchSuperviser
) ;
) ;
break ;
break ;
} catch ( final IOException e ) {
} catch ( final IOException e ) {
Network . log . info ( "SEARCH failed, Peer: " + target . hash + ":" + target . getName ( ) + " (" + e . getMessage ( ) + ")" ) ;
Network . log . info ( "SEARCH failed, Peer: " + target . hash + ":" + target . getName ( ) + " (" + e . getMessage ( ) + ")" ) ;
if ( targetBaseURL . startsWith ( "https" ) ) {
/* First mark https unavailable on this peer before removing any interface */
target . setFlagSSLAvailable ( false ) ;
} else {
event . peers . peerActions . interfaceDeparture ( target , ip ) ;
event . peers . peerActions . interfaceDeparture ( target , ip ) ;
}
return - 1 ;
return - 1 ;
}
}
}
}
@ -571,6 +582,9 @@ public final class Protocol {
event . addExpectedRemoteReferences ( count ) ;
event . addExpectedRemoteReferences ( count ) ;
SearchResult result = null ;
SearchResult result = null ;
for ( String ip : target . getIPs ( ) ) {
for ( String ip : target . getIPs ( ) ) {
final String targetBaseURL = target . getPublicURL ( ip ,
Switchboard . getSwitchboard ( ) . getConfigBool ( SwitchboardConstants . REMOTESEARCH_HTTPS_PREFERRED ,
SwitchboardConstants . REMOTESEARCH_HTTPS_PREFERRED_DEFAULT ) ) ;
try {
try {
result =
result =
new SearchResult (
new SearchResult (
@ -586,13 +600,18 @@ public final class Protocol {
maxDistance ,
maxDistance ,
partitions ,
partitions ,
target . getHexHash ( ) + ".yacyh" ,
target . getHexHash ( ) + ".yacyh" ,
target . getPublicAddress ( ip ) ,
target BaseURL ,
null
null
) ;
) ;
break ;
break ;
} catch ( final IOException e ) {
} catch ( final IOException e ) {
Network . log . info ( "SEARCH failed, Peer: " + target . hash + ":" + target . getName ( ) + " (" + e . getMessage ( ) + ")" ) ;
Network . log . info ( "SEARCH failed, Peer: " + target . hash + ":" + target . getName ( ) + " (" + e . getMessage ( ) + ")" ) ;
if ( targetBaseURL . startsWith ( "https" ) ) {
/* First mark https unavailable on this peer before removing any interface */
target . setFlagSSLAvailable ( false ) ;
} else {
event . peers . peerActions . interfaceDeparture ( target , ip ) ;
event . peers . peerActions . interfaceDeparture ( target , ip ) ;
}
return - 1 ;
return - 1 ;
}
}
}
}
@ -845,7 +864,7 @@ public final class Protocol {
final int maxDistance ,
final int maxDistance ,
final int partitions ,
final int partitions ,
final String hostname ,
final String hostname ,
final String hostaddress ,
final String targetBaseURL ,
final SecondarySearchSuperviser secondarySearchSuperviser
final SecondarySearchSuperviser secondarySearchSuperviser
) throws IOException {
) throws IOException {
// send a search request to peer with remote Hash
// send a search request to peer with remote Hash
@ -902,8 +921,7 @@ public final class Protocol {
}
}
final HTTPClient httpClient = new HTTPClient ( ClientIdentification . yacyInternetCrawlerAgent , 8000 ) ;
final HTTPClient httpClient = new HTTPClient ( ClientIdentification . yacyInternetCrawlerAgent , 8000 ) ;
//System.out.println("Protocol: http://" + hostaddress + "/yacy/search.html" + requestPartsToString(parts)); // DEBUG
byte [ ] a = httpClient . POSTbytes ( new MultiProtocolURL ( targetBaseURL + "/yacy/search.html" ) , hostname , parts , false , true ) ;
byte [ ] a = httpClient . POSTbytes ( new MultiProtocolURL ( "http://" + hostaddress + "/yacy/search.html" ) , hostname , parts , false , true ) ;
if ( a ! = null & & a . length > 200000 ) {
if ( a ! = null & & a . length > 200000 ) {
// there is something wrong. This is too large, maybe a hack on the other side?
// there is something wrong. This is too large, maybe a hack on the other side?
a = null ;
a = null ;
@ -986,8 +1004,8 @@ public final class Protocol {
/** The solr query to run */
/** The solr query to run */
private final SolrQuery solrQuery ;
private final SolrQuery solrQuery ;
/** The instance address */
/** The instance base URL */
private final String address ;
private final String targetBaseURL ;
/** The target seed information */
/** The target seed information */
private final Seed target ;
private final Seed target ;
@ -1010,15 +1028,15 @@ public final class Protocol {
/ * *
/ * *
* Constructor . All parameters are required to not be null .
* Constructor . All parameters are required to not be null .
* @param solrQuery the Solr query to run
* @param solrQuery the Solr query to run
* @param address the instance address : host name or IP + the eventual port
* @param targetBaseURL the instance base URL : http ( s ) + host name or IP + the eventual port
* @param target the remote target seed information
* @param target the remote target seed information
* @param timeout the request timeout in milliseconds
* @param timeout the request timeout in milliseconds
* /
* /
protected SolrRequestTask ( final SolrQuery solrQuery , final String address , final Seed target ,
protected SolrRequestTask ( final SolrQuery solrQuery , final String targetBaseURL , final Seed target ,
final boolean mySeed , final int timeout , final QueryResponse [ ] rsp , final SolrDocumentList [ ] docList ) {
final boolean mySeed , final int timeout , final QueryResponse [ ] rsp , final SolrDocumentList [ ] docList ) {
super ( "Protocol.solrQuery(" + solrQuery . getQuery ( ) + " to " + target . hash + ")" ) ;
super ( "Protocol.solrQuery(" + solrQuery . getQuery ( ) + " to " + target . hash + ")" ) ;
this . solrQuery = solrQuery ;
this . solrQuery = solrQuery ;
this . address = address ;
this . targetBaseURL = targetBaseURL ;
this . target = target ;
this . target = target ;
this . mySeed = mySeed ;
this . mySeed = mySeed ;
this . timeout = timeout ;
this . timeout = timeout ;
@ -1040,13 +1058,13 @@ public final class Protocol {
/* Strip too large details to avoid polluting this log with complete remote stack traces */
/* Strip too large details to avoid polluting this log with complete remote stack traces */
message = message . substring ( 0 , MAX_ERROR_MESSAGE_LENGTH ) + "..." ;
message = message . substring ( 0 , MAX_ERROR_MESSAGE_LENGTH ) + "..." ;
}
}
log . fine ( messageBegin + " at " + this . address + " : " + message ) ;
log . fine ( messageBegin + " at " + this . targetBaseURL + " : " + message ) ;
}
}
@Override
@Override
public void run ( ) {
public void run ( ) {
try {
try {
this . instance = new RemoteInstance ( "http://" + this . address , null , "solr" , this . timeout ) ; // this is a 'patch configuration' which considers 'solr' as default collection
this . instance = new RemoteInstance ( this . targetBaseURL , null , "solr" , this . timeout ) ; // this is a 'patch configuration' which considers 'solr' as default collection
try {
try {
boolean useBinaryResponseWriter = SwitchboardConstants . REMOTE_SOLR_BINARY_RESPONSE_ENABLED_DEFAULT ;
boolean useBinaryResponseWriter = SwitchboardConstants . REMOTE_SOLR_BINARY_RESPONSE_ENABLED_DEFAULT ;
if ( Switchboard . getSwitchboard ( ) ! = null ) {
if ( Switchboard . getSwitchboard ( ) ! = null ) {
@ -1170,13 +1188,20 @@ public final class Protocol {
} else {
} else {
try {
try {
final boolean myseed = target = = event . peers . mySeed ( ) ;
final boolean myseed = target = = event . peers . mySeed ( ) ;
final String targetBaseURL ;
if ( myseed ) {
targetBaseURL = "http://localhost:" + target . getPort ( ) ;
} else {
targetBaseURL = target . getPublicURL ( ip ,
Switchboard . getSwitchboard ( ) . getConfigBool ( SwitchboardConstants . REMOTESEARCH_HTTPS_PREFERRED ,
SwitchboardConstants . REMOTESEARCH_HTTPS_PREFERRED_DEFAULT ) ) ;
}
if ( ! myseed & & ! target . getFlagSolrAvailable ( ) ) { // skip if peer.dna has flag that last try resulted in error
if ( ! myseed & & ! target . getFlagSolrAvailable ( ) ) { // skip if peer.dna has flag that last try resulted in error
Network . log . info ( "SEARCH skip (solr), remote Solr interface not accessible, peer=" + target . getName ( ) ) ;
Network . log . info ( "SEARCH skip (solr), remote Solr interface not accessible, peer=" + target . getName ( ) ) ;
return - 1 ;
return - 1 ;
}
}
final String address = myseed ? "localhost:" + target . getPort ( ) : target . getPublicAddress ( ip ) ;
final int solrtimeout = Switchboard . getSwitchboard ( ) . getConfigInt ( SwitchboardConstants . FEDERATED_SERVICE_SOLR_INDEXING_TIMEOUT , 6000 ) ;
final int solrtimeout = Switchboard . getSwitchboard ( ) . getConfigInt ( SwitchboardConstants . FEDERATED_SERVICE_SOLR_INDEXING_TIMEOUT , 6000 ) ;
SolrRequestTask remoteRequest = new SolrRequestTask ( solrQuery , address , target , myseed , solrtimeout , rsp , docList ) ;
SolrRequestTask remoteRequest = new SolrRequestTask ( solrQuery , targetBaseURL , target , myseed , solrtimeout , rsp , docList ) ;
remoteRequest . start ( ) ;
remoteRequest . start ( ) ;
remoteRequest . join ( solrtimeout ) ; // just wait until timeout appears
remoteRequest . join ( solrtimeout ) ; // just wait until timeout appears
if ( remoteRequest . isAlive ( ) ) {
if ( remoteRequest . isAlive ( ) ) {
@ -1190,6 +1215,20 @@ public final class Protocol {
target . setFlagSolrAvailable ( false | | myseed ) ;
target . setFlagSolrAvailable ( false | | myseed ) ;
return - 1 ; // give up, leave remoteRequest abandoned.
return - 1 ; // give up, leave remoteRequest abandoned.
}
}
if ( rsp [ 0 ] = = null | | docList [ 0 ] = = null ) {
Network . log . info ( "SEARCH failed (solr), remote Peer: " + target . getName ( ) + "/" + target . getPublicAddress ( ip ) + " returned null" ) ;
if ( ! myseed ) {
if ( targetBaseURL . startsWith ( "https" ) ) {
/* First mark https unavailable on this peer before removing anything else */
target . setFlagSSLAvailable ( false ) ;
} else {
target . setFlagSolrAvailable ( false ) ;
}
}
target . setFlagSolrAvailable ( false | | myseed ) ;
return - 1 ;
}
} catch ( InterruptedException e ) {
} catch ( InterruptedException e ) {
/ * Current thread might be interrupted by SearchEvent . cleanup ( ) :
/ * Current thread might be interrupted by SearchEvent . cleanup ( ) :
* we must not in that case mark the target as not available but rather transmit the exception to the caller ( likely RemoteSearch . solrRemoteSearch ) * /
* we must not in that case mark the target as not available but rather transmit the exception to the caller ( likely RemoteSearch . solrRemoteSearch ) * /
@ -1201,12 +1240,6 @@ public final class Protocol {
}
}
}
}
if ( rsp [ 0 ] = = null | | docList [ 0 ] = = null ) {
Network . log . info ( "SEARCH failed (solr), remote Peer: " + target . getName ( ) + "/" + target . getPublicAddress ( ip ) + " returned null" ) ;
target . setFlagSolrAvailable ( false | | localsearch ) ;
return - 1 ;
}
// evaluate facets
// evaluate facets
if ( useSolrFacets ) {
if ( useSolrFacets ) {
for ( String field : event . query . facetfields ) {
for ( String field : event . query . facetfields ) {