}
@Override
public void set(Integer val) throws InvalidConfigValueException,
NodeNeedRestartException {
if(val < 1) throw new InvalidConfigValueException(l10n("memoryLimitedJobThreadLimitMustBe1Plus"));
memoryLimitedJobRunner.setMaxThreads(val);
}
}, false);
long defaultMemoryLimitedJobMemoryLimit = FECCodec.MIN_MEMORY_ALLOCATION;
long overallMemoryLimit = NodeStarter.getMemoryLimitBytes();
if(overallMemoryLimit > 512*1024*1024) {
// FIXME review default memory limits
defaultMemoryLimitedJobMemoryLimit += (overallMemoryLimit - 512*1024*1024) / 20;
}
nodeConfig.register("memoryLimitedJobMemoryLimit", defaultMemoryLimitedJobMemoryLimit, sortOrder++, true, false,
"NodeClientCore.memoryLimitedJobMemoryLimit", "NodeClientCore.memoryLimitedJobMemoryLimitLong", new LongCallback() {
@Override
public Long get() {
return memoryLimitedJobRunner.getCapacity();
}
@Override
public void set(Long val) throws InvalidConfigValueException,
NodeNeedRestartException {
if(val < FECCodec.MIN_MEMORY_ALLOCATION) throw new InvalidConfigValueException(l10n("memoryLimitedJobMemoryLimitMustBeAtLeast", "min", SizeUtil.formatSize(FECCodec.MIN_MEMORY_ALLOCATION)));
memoryLimitedJobRunner.setCapacity(val);
}
}, true);
memoryLimitedJobRunner = new MemoryLimitedJobRunner(nodeConfig.getLong("memoryLimitedJobMemoryLimit"), nodeConfig.getInt("memoryLimitedJobThreadLimit"), node.executor);
shutdownHook.addEarlyJob(new NativeThread("Shutdown FEC", NativeThread.HIGH_PRIORITY, true) {
public void realRun() {
System.out.println("Stopping FEC decode threads...");
memoryLimitedJobRunner.shutdown();
}
});
shutdownHook.addLateJob(new NativeThread("Shutdown FEC", NativeThread.HIGH_PRIORITY, true) {
public void realRun() {
memoryLimitedJobRunner.waitForShutdown();
System.out.println("FEC decoding threads finished.");
}
});
clientContext = new ClientContext(node.bootID, clientLayerPersister, node.executor,
archiveManager, persistentTempBucketFactory, tempBucketFactory,
persistentTempBucketFactory, healingQueue, uskManager, random, node.fastWeakRandom,
node.getTicker(), memoryLimitedJobRunner, tempFilenameGenerator, persistentFilenameGenerator, tempBucketFactory,
persistentRAFFactory, tempBucketFactory.getUnderlyingRAFFactory(), persistentDiskChecker,
compressor, storeChecker, fcpPersistentRoot, cryptoSecretTransient, toadlets, defaultFetchContext, defaultInsertContext);
compressor.setClientContext(clientContext);
storeChecker.setContext(clientContext);
clientLayerPersister.start(clientContext);
try {
requestStarters = new RequestStarterGroup(node, this, portNumber, random, config, throttleFS, clientContext, nodeDBHandle);
} catch (InvalidConfigValueException e1) {
throw new NodeInitException(NodeInitException.EXIT_BAD_CONFIG, e1.toString());
}
clientContext.init(requestStarters, alerts);
if(persistentSecret != null) {
setupMasterSecret(persistentSecret);
}
try {
initStorage(databaseKey);
} catch (MasterKeysWrongPasswordException e) {
System.err.println("Cannot load persistent requests, awaiting password ...");
node.setDatabaseAwaitingPassword();
}
node.securityLevels.addPhysicalThreatLevelListener(new SecurityLevelListener<PHYSICAL_THREAT_LEVEL>() {
@Override
public void onChange(PHYSICAL_THREAT_LEVEL oldLevel, PHYSICAL_THREAT_LEVEL newLevel) {
if(newLevel == PHYSICAL_THREAT_LEVEL.LOW) {
if(tempBucketFactory.isEncrypting()) {
tempBucketFactory.setEncryption(false);
}
if(persistentTempBucketFactory != null) {
if(persistentTempBucketFactory.isEncrypting()) {
persistentTempBucketFactory.setEncryption(false);
}
}
persistentRAFFactory.setEncryption(false);
} else { // newLevel >= PHYSICAL_THREAT_LEVEL.NORMAL
if(!tempBucketFactory.isEncrypting()) {
tempBucketFactory.setEncryption(true);
}
if(persistentTempBucketFactory != null) {
if(!persistentTempBucketFactory.isEncrypting()) {
persistentTempBucketFactory.setEncryption(true);
}
}
persistentRAFFactory.setEncryption(true);
}
if(clientLayerPersister.hasLoaded()) {
// May need to change filenames for client.dat* or even create them.
try {
initStorage(NodeClientCore.this.node.getDatabaseKey());
} catch (MasterKeysWrongPasswordException e) {
NodeClientCore.this.node.setDatabaseAwaitingPassword();
}
}
}
});
// Downloads directory
this.downloadsDir = node.setupProgramDir(nodeConfig, "downloadsDir", node.userDir().file("downloads").getPath(),
"NodeClientCore.downloadsDir", "NodeClientCore.downloadsDirLong", l10n("couldNotFindOrCreateDir"), (SubConfig)null);
// Downloads allowed, uploads allowed
nodeConfig.register("downloadAllowedDirs", new String[]{"all"}, sortOrder++, true, true, "NodeClientCore.downloadAllowedDirs",
"NodeClientCore.downloadAllowedDirsLong",
new StringArrCallback() {
@Override
public String[] get() {
synchronized(NodeClientCore.this) {
if(downloadAllowedEverywhere)
return new String[]{"all"};
String[] dirs = new String[downloadAllowedDirs.length + (includeDownloadDir ? 1 : 0)];
for(int i = 0; i < downloadAllowedDirs.length; i++)
dirs[i] = downloadAllowedDirs[i].getPath();
if(includeDownloadDir)
dirs[downloadAllowedDirs.length] = "downloads";
return dirs;
}
}
@Override
public void set(String[] val) throws InvalidConfigValueException {
setDownloadAllowedDirs(val);
}
});
setDownloadAllowedDirs(nodeConfig.getStringArr("downloadAllowedDirs"));
nodeConfig.register("uploadAllowedDirs", new String[]{"all"}, sortOrder++, true, true, "NodeClientCore.uploadAllowedDirs",
"NodeClientCore.uploadAllowedDirsLong",
new StringArrCallback() {
@Override
public String[] get() {
synchronized(NodeClientCore.this) {
if(uploadAllowedEverywhere)
return new String[]{"all"};
String[] dirs = new String[uploadAllowedDirs.length];
for(int i = 0; i < uploadAllowedDirs.length; i++)
dirs[i] = uploadAllowedDirs[i].getPath();
return dirs;
}
}
@Override
public void set(String[] val) throws InvalidConfigValueException {
setUploadAllowedDirs(val);
}
});
setUploadAllowedDirs(nodeConfig.getStringArr("uploadAllowedDirs"));
Logger.normal(this, "Initializing USK Manager");
System.out.println("Initializing USK Manager");
uskManager.init(clientContext);
nodeConfig.register("maxBackgroundUSKFetchers", "64", sortOrder++, true, false, "NodeClientCore.maxUSKFetchers",
"NodeClientCore.maxUSKFetchersLong", new IntCallback() {
@Override
public Integer get() {
return maxBackgroundUSKFetchers;
}
@Override
public void set(Integer uskFetch) throws InvalidConfigValueException {
if(uskFetch <= 0)
throw new InvalidConfigValueException(l10n("maxUSKFetchersMustBeGreaterThanZero"));
maxBackgroundUSKFetchers = uskFetch;
}
}, false);
maxBackgroundUSKFetchers = nodeConfig.getInt("maxBackgroundUSKFetchers");