forked from Qortal/qortal
Added "qdnEnabled" setting (default: true) to allow users to opt out of QDN functionality.
This commit is contained in:
parent
1f8a618dcc
commit
f153c7bb80
@ -164,6 +164,7 @@ public class ArbitraryDataReader {
|
||||
|
||||
private void preExecute() throws DataException {
|
||||
ArbitraryDataBuildManager.getInstance().setBuildInProgress(true);
|
||||
this.checkEnabled();
|
||||
this.createWorkingDirectory();
|
||||
this.createUncompressedDirectory();
|
||||
}
|
||||
@ -172,6 +173,12 @@ public class ArbitraryDataReader {
|
||||
ArbitraryDataBuildManager.getInstance().setBuildInProgress(false);
|
||||
}
|
||||
|
||||
private void checkEnabled() throws DataException {
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
throw new DataException("QDN is disabled in settings");
|
||||
}
|
||||
}
|
||||
|
||||
private void createWorkingDirectory() throws DataException {
|
||||
try {
|
||||
Files.createDirectories(this.workingPath);
|
||||
|
@ -9,6 +9,8 @@ import org.qortal.arbitrary.ArbitraryDataFile.*;
|
||||
import org.qortal.arbitrary.exception.MissingDataException;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -64,6 +66,11 @@ public class ArbitraryDataRenderer {
|
||||
inPath = File.separator + inPath;
|
||||
}
|
||||
|
||||
// Don't render data if QDN is disabled
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
return ArbitraryDataRenderer.getResponse(response, 500, "QDN is disabled in settings");
|
||||
}
|
||||
|
||||
ArbitraryDataReader arbitraryDataReader = new ArbitraryDataReader(resourceId, resourceIdType, service, null);
|
||||
arbitraryDataReader.setSecret58(secret58); // Optional, used for loading encrypted file hashes only
|
||||
try {
|
||||
|
@ -81,6 +81,8 @@ public class ArbitraryDataWriter {
|
||||
}
|
||||
|
||||
private void preExecute() throws DataException {
|
||||
this.checkEnabled();
|
||||
|
||||
// Enforce compression when uploading a directory
|
||||
File file = new File(this.filePath.toString());
|
||||
if (file.isDirectory() && compression == Compression.NONE) {
|
||||
@ -95,6 +97,12 @@ public class ArbitraryDataWriter {
|
||||
this.cleanupFilesystem();
|
||||
}
|
||||
|
||||
private void checkEnabled() throws DataException {
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
throw new DataException("QDN is disabled in settings");
|
||||
}
|
||||
}
|
||||
|
||||
private void createWorkingDirectory() throws DataException {
|
||||
// Use the user-specified temp dir, as it is deterministic, and is more likely to be located on reusable storage hardware
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
|
@ -6,6 +6,7 @@ import java.util.*;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.api.resource.TransactionsResource.ConfirmationStatus;
|
||||
import org.qortal.arbitrary.ArbitraryDataRenderer;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.data.network.ArbitraryPeerData;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData;
|
||||
@ -793,6 +794,11 @@ public class ArbitraryDataManager extends Thread {
|
||||
// Network handlers
|
||||
|
||||
public void onNetworkArbitraryDataFileListMessage(Peer peer, Message message) {
|
||||
// Don't process if QDN is disabled
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArbitraryDataFileListMessage arbitraryDataFileListMessage = (ArbitraryDataFileListMessage) message;
|
||||
LOGGER.info("Received hash list from peer {} with {} hashes", peer, arbitraryDataFileListMessage.getHashes().size());
|
||||
|
||||
@ -880,6 +886,11 @@ public class ArbitraryDataManager extends Thread {
|
||||
}
|
||||
|
||||
public void onNetworkGetArbitraryDataFileMessage(Peer peer, Message message) {
|
||||
// Don't respond if QDN is disabled
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GetArbitraryDataFileMessage getArbitraryDataFileMessage = (GetArbitraryDataFileMessage) message;
|
||||
byte[] hash = getArbitraryDataFileMessage.getHash();
|
||||
String hash58 = Base58.encode(hash);
|
||||
@ -949,6 +960,11 @@ public class ArbitraryDataManager extends Thread {
|
||||
}
|
||||
|
||||
public void onNetworkGetArbitraryDataFileListMessage(Peer peer, Message message) {
|
||||
// Don't respond if QDN is disabled
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Controller.getInstance().stats.getArbitraryDataFileListMessageStats.requests.incrementAndGet();
|
||||
|
||||
GetArbitraryDataFileListMessage getArbitraryDataFileListMessage = (GetArbitraryDataFileListMessage) message;
|
||||
@ -1040,6 +1056,11 @@ public class ArbitraryDataManager extends Thread {
|
||||
}
|
||||
|
||||
public void onNetworkArbitrarySignaturesMessage(Peer peer, Message message) {
|
||||
// Don't process if QDN is disabled
|
||||
if (!Settings.getInstance().isQdnEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Received arbitrary signature list from peer {}", peer);
|
||||
|
||||
ArbitrarySignaturesMessage arbitrarySignaturesMessage = (ArbitrarySignaturesMessage) message;
|
||||
|
@ -274,11 +274,13 @@ public class Settings {
|
||||
private Long testNtpOffset = null;
|
||||
|
||||
|
||||
// Data storage
|
||||
// Data storage (QDN)
|
||||
|
||||
/** Data storage enabled/disabled*/
|
||||
private boolean qdnEnabled = true;
|
||||
/** Data storage path. */
|
||||
private String dataPath = "data";
|
||||
/** Data storage path (for temporary data). */
|
||||
/** Data storage path (for temporary data). Defaults to {dataPath}/_temp */
|
||||
private String tempDataPath = null;
|
||||
|
||||
/** Storage policy to indicate which data should be hosted */
|
||||
@ -831,6 +833,10 @@ public class Settings {
|
||||
}
|
||||
|
||||
|
||||
public boolean isQdnEnabled() {
|
||||
return this.qdnEnabled;
|
||||
}
|
||||
|
||||
public String getDataPath() {
|
||||
return this.dataPath;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user