Skip to content

Commit

Permalink
fixed some problems with network switching (was not completely 'clean')
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5200 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Sep 23, 2008
1 parent f0b42e5 commit 7b35d54
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 30 deletions.
4 changes: 2 additions & 2 deletions htroot/ConfigBasic.java
Expand Up @@ -154,8 +154,8 @@ public static serverObjects respond(final httpRequestHeader header, final server
// switch to intranet network
sb.switchNetwork("defaults/yacy.network.intranet.unit");
// switch to p2p mode: enable ad-hoc networks between intranet users
sb.setConfig(plasmaSwitchboardConstants.INDEX_DIST_ALLOW, true);
sb.setConfig(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, true);
sb.setConfig(plasmaSwitchboardConstants.INDEX_DIST_ALLOW, false);
sb.setConfig(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion htroot/CrawlStart_p.html
Expand Up @@ -31,7 +31,7 @@ <h2>Crawl Start</h2>
<td><label for="url"><nobr>From URL</nobr></label>:</td>
<td><input type="radio" name="crawlingMode" id="url" value="url" checked="checked" /></td>
<td>
<input name="crawlingURL" type="text" size="41" maxlength="256" value="http://" onkeypress="changed()" />
<input name="crawlingURL" type="text" size="41" maxlength="256" value="#[starturl]#" onkeypress="changed()" />
</td>
</tr>
<tr>
Expand Down
4 changes: 4 additions & 0 deletions htroot/CrawlStart_p.java
Expand Up @@ -25,6 +25,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import de.anomic.http.httpRequestHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaSwitchboardConstants;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
Expand All @@ -33,9 +34,12 @@ public class CrawlStart_p {

public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch<?> env) {
// return variable that accumulates replacements
final plasmaSwitchboard sb = (plasmaSwitchboard) env;
final serverObjects prop = new serverObjects();

// define visible variables
String a = sb.webIndex.seedDB.mySeed().getPublicAddress();
prop.put("starturl", (sb.getConfig("network.unit.name", "").equals("intranet")) ? "http://" + ((a == null) ? "localhost:" + sb.getConfig("port", "8080") : a) + "/repository/" : "http://");
prop.put("proxyPrefetchDepth", env.getConfig("proxyPrefetchDepth", "0"));
prop.put("crawlingDepth", env.getConfig("crawlingDepth", "0"));
prop.put("crawlingFilter", env.getConfig("crawlingFilter", "0"));
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/index/indexRAMRI.java
Expand Up @@ -157,7 +157,7 @@ public synchronized kelondroCloneableIterator<indexContainer> wordContainers(fin


public synchronized String maxScoreWordHash() {
if (heap.size() == 0) return null;
if (heap == null || heap.size() == 0) return null;
try {
return hashScore.getMaxObject();
} catch (final Exception e) {
Expand Down
74 changes: 48 additions & 26 deletions source/de/anomic/plasma/plasmaSwitchboard.java
Expand Up @@ -273,9 +273,6 @@ public plasmaSwitchboard(final File rootPath, final String initPath, final Strin
// remote proxy configuration
httpRemoteProxyConfig.init(this);

// load the network definition
overwriteNetworkDefinition(this);

// load values from configs
this.plasmaPath = getConfigPath(plasmaSwitchboardConstants.PLASMA_PATH, plasmaSwitchboardConstants.PLASMA_PATH_DEFAULT);
this.log.logConfig("Plasma DB Path: " + this.plasmaPath.toString());
Expand Down Expand Up @@ -315,6 +312,9 @@ public plasmaSwitchboard(final File rootPath, final String initPath, final Strin
serverInstantBusyThread.oneTimeJob(this, "loadSeedLists", yacyCore.log, 0);
final long startedSeedListAquisition = System.currentTimeMillis();

// load the network definition
overwriteNetworkDefinition();

// set up local robots.txt
this.robotstxtConfig = httpdRobotsTxtConfig.init(this);

Expand Down Expand Up @@ -648,27 +648,28 @@ private void initSystemTray() {
}


public static void overwriteNetworkDefinition(final plasmaSwitchboard sb) {
public void overwriteNetworkDefinition() {

// load network configuration into settings
String networkUnitDefinition = sb.getConfig("network.unit.definition", "defaults/yacy.network.freeworld.unit");
final String networkGroupDefinition = sb.getConfig("network.group.definition", "yacy.network.group");
String networkUnitDefinition = getConfig("network.unit.definition", "defaults/yacy.network.freeworld.unit");
final String networkGroupDefinition = getConfig("network.group.definition", "yacy.network.group");

// patch old values
if (networkUnitDefinition.equals("yacy.network.unit")) {
networkUnitDefinition = "defaults/yacy.network.freeworld.unit";
sb.setConfig("network.unit.definition", networkUnitDefinition);
setConfig("network.unit.definition", networkUnitDefinition);
}

// remove old release locations
int i = 0;
String location;
while (true) {
location = sb.getConfig("network.unit.update.location" + i, "");
if (location.length() == 0) break;
sb.removeConfig("network.unit.update.location" + i);
i++;
// remove old release and bootstrap locations
Iterator<String> ki = configKeys();
ArrayList<String> d = new ArrayList<String>();
String k;
while (ki.hasNext()) {
k = ki.next();
if (k.startsWith("network.unit.update.location")) d.add(k);
if (k.startsWith("network.unit.bootstrap")) d.add(k);
}
for (String s:d) this.removeConfig(s); // must be removed afterwards othervise a ki.remove() would not remove the property on file

// include additional network definition properties into our settings
// note that these properties cannot be set in the application because they are
Expand All @@ -678,30 +679,32 @@ public static void overwriteNetworkDefinition(final plasmaSwitchboard sb) {
Map<String, String> initProps;
if (networkUnitDefinition.startsWith("http://")) {
try {
sb.setConfig(plasmaSwitchboard.loadHashMap(new yacyURL(networkUnitDefinition, null)));
setConfig(plasmaSwitchboard.loadHashMap(new yacyURL(networkUnitDefinition, null)));
} catch (final MalformedURLException e) { }
} else {
final File networkUnitDefinitionFile = (networkUnitDefinition.startsWith("/")) ? new File(networkUnitDefinition) : new File(sb.getRootPath(), networkUnitDefinition);
final File networkUnitDefinitionFile = (networkUnitDefinition.startsWith("/")) ? new File(networkUnitDefinition) : new File(getRootPath(), networkUnitDefinition);
if (networkUnitDefinitionFile.exists()) {
initProps = serverFileUtils.loadHashMap(networkUnitDefinitionFile);
sb.setConfig(initProps);
setConfig(initProps);
}
}
if (networkGroupDefinition.startsWith("http://")) {
try {
sb.setConfig(plasmaSwitchboard.loadHashMap(new yacyURL(networkGroupDefinition, null)));
setConfig(plasmaSwitchboard.loadHashMap(new yacyURL(networkGroupDefinition, null)));
} catch (final MalformedURLException e) { }
} else {
final File networkGroupDefinitionFile = new File(sb.getRootPath(), networkGroupDefinition);
final File networkGroupDefinitionFile = new File(getRootPath(), networkGroupDefinition);
if (networkGroupDefinitionFile.exists()) {
initProps = serverFileUtils.loadHashMap(networkGroupDefinitionFile);
sb.setConfig(initProps);
setConfig(initProps);
}
}

// set release locations
int i = 0;
String location;
while (true) {
location = sb.getConfig("network.unit.update.location" + i, "");
location = getConfig("network.unit.update.location" + i, "");
if (location.length() == 0) break;
try {
yacyVersion.latestReleaseLocations.add(new yacyURL(location, null));
Expand All @@ -712,11 +715,30 @@ public static void overwriteNetworkDefinition(final plasmaSwitchboard sb) {
}

// initiate url license object
sb.licensedURLs = new URLLicense(8);
licensedURLs = new URLLicense(8);

// set URL domain acceptance
sb.acceptGlobalURLs = "global.any".indexOf(sb.getConfig("network.unit.domain", "global")) >= 0;
sb.acceptLocalURLs = "local.any".indexOf(sb.getConfig("network.unit.domain", "global")) >= 0;
acceptGlobalURLs = "global.any".indexOf(getConfig("network.unit.domain", "global")) >= 0;
acceptLocalURLs = "local.any".indexOf(getConfig("network.unit.domain", "global")) >= 0;

// in intranet and portal network set robinson mode
if (networkUnitDefinition.equals("defaults/yacy.network.webportal.unit") ||
networkUnitDefinition.equals("defaults/yacy.network.intranet.unit")) {
// switch to robinson mode
setConfig("crawlResponse", "false");
setConfig(plasmaSwitchboardConstants.INDEX_DIST_ALLOW, false);
setConfig(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false);
webIndex.seedDB.mySeed().setFlagAcceptRemoteIndex(false);
}

// in freeworld network set full p2p mode
if (networkUnitDefinition.equals("defaults/yacy.network.freeworld.unit")) {
// switch to robinson mode
setConfig("crawlResponse", "true");
setConfig(plasmaSwitchboardConstants.INDEX_DIST_ALLOW, true);
setConfig(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, true);
webIndex.seedDB.mySeed().setFlagAcceptRemoteIndex(true);
}

}

Expand All @@ -736,7 +758,7 @@ public void switchNetwork(final String networkDefinition) {
this.webIndex.close();
}
setConfig("network.unit.definition", networkDefinition);
overwriteNetworkDefinition(this);
overwriteNetworkDefinition();
final File indexPrimaryPath = getConfigPath(plasmaSwitchboardConstants.INDEX_PRIMARY_PATH, plasmaSwitchboardConstants.INDEX_PATH_DEFAULT);
final File indexSecondaryPath = (getConfig(plasmaSwitchboardConstants.INDEX_SECONDARY_PATH, "").length() == 0) ? indexPrimaryPath : new File(getConfig(plasmaSwitchboardConstants.INDEX_SECONDARY_PATH, ""));
final int wordCacheMaxCount = (int) getConfigLong(plasmaSwitchboardConstants.WORDCACHE_MAX_COUNT, 20000);
Expand Down

0 comments on commit 7b35d54

Please sign in to comment.