forked from Qortal/qortal
Merge remote-tracking branch 'qortal-data/master' into qdn
This commit is contained in:
commit
f9749cd82c
@ -137,10 +137,7 @@ public class AdminResource {
|
||||
)
|
||||
}
|
||||
)
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public NodeStatus status() {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
NodeStatus nodeStatus = new NodeStatus();
|
||||
|
||||
return nodeStatus;
|
||||
@ -252,9 +249,7 @@ public class AdminResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public List<MintingAccountData> getMintingAccounts() {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
List<MintingAccountData> mintingAccounts = repository.getAccountRepository().getMintingAccounts();
|
||||
@ -751,4 +746,22 @@ public class AdminResource {
|
||||
return apiKey.toString();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/apikey/test")
|
||||
@Operation(
|
||||
summary = "Test an API key",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "true if authenticated",
|
||||
content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "boolean"))
|
||||
)
|
||||
}
|
||||
)
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public String testApiKey() {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
return "true";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -352,10 +352,7 @@ public class PeersResource {
|
||||
)
|
||||
}
|
||||
)
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public PeersSummary peersSummary() {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
PeersSummary peersSummary = new PeersSummary();
|
||||
|
||||
List<Peer> connectedPeers = Network.getInstance().getConnectedPeers().stream().collect(Collectors.toList());
|
||||
|
@ -159,7 +159,7 @@ public class ArbitraryDataFileManager {
|
||||
// but only if these files are in accordance with our storage policy
|
||||
if (ArbitraryDataStorageManager.getInstance().canStoreData(arbitraryTransactionData)) {
|
||||
// Use a null peer address to indicate our own
|
||||
Message newArbitrarySignatureMessage = new ArbitrarySignaturesMessage(null, Arrays.asList(signature));
|
||||
Message newArbitrarySignatureMessage = new ArbitrarySignaturesMessage(null, 0, Arrays.asList(signature));
|
||||
Network.getInstance().broadcast(broadcastPeer -> newArbitrarySignatureMessage);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ public class ArbitraryDataManager extends Thread {
|
||||
/** Maximum time to hold information about an in-progress relay */
|
||||
public static final long ARBITRARY_RELAY_TIMEOUT = 30 * 1000L; // ms
|
||||
|
||||
/** Maximum number of hops that an arbitrary signatures request is allowed to make */
|
||||
private static int ARBITRARY_SIGNATURES_REQUEST_MAX_HOPS = 3;
|
||||
|
||||
private static ArbitraryDataManager instance;
|
||||
private final Object peerDataLock = new Object();
|
||||
|
||||
@ -99,7 +102,7 @@ public class ArbitraryDataManager extends Thread {
|
||||
// Fetch data according to storage policy
|
||||
switch (Settings.getInstance().getStoragePolicy()) {
|
||||
case FOLLOWED:
|
||||
case FOLLOWED_AND_VIEWED:
|
||||
case FOLLOWED_OR_VIEWED:
|
||||
this.processNames();
|
||||
break;
|
||||
|
||||
@ -369,7 +372,7 @@ public class ArbitraryDataManager extends Thread {
|
||||
|
||||
// Broadcast the list, using null to represent our peer address
|
||||
LOGGER.info("Broadcasting list of hosted signatures...");
|
||||
Message arbitrarySignatureMessage = new ArbitrarySignaturesMessage(null, hostedSignatures);
|
||||
Message arbitrarySignatureMessage = new ArbitrarySignaturesMessage(null, 0, hostedSignatures);
|
||||
Network.getInstance().broadcast(broadcastPeer -> arbitrarySignatureMessage);
|
||||
|
||||
} catch (DataException e) {
|
||||
@ -429,8 +432,12 @@ public class ArbitraryDataManager extends Thread {
|
||||
// If at least one signature in this batch was new to us, we should rebroadcast the message to the
|
||||
// network in case some peers haven't received it yet
|
||||
if (containsNewEntry) {
|
||||
LOGGER.debug("Rebroadcasting arbitrary signature list for peer {}", peerAddress);
|
||||
Network.getInstance().broadcast(broadcastPeer -> broadcastPeer == peer ? null : arbitrarySignaturesMessage);
|
||||
int requestHops = arbitrarySignaturesMessage.getRequestHops();
|
||||
arbitrarySignaturesMessage.setRequestHops(++requestHops);
|
||||
if (requestHops < ARBITRARY_SIGNATURES_REQUEST_MAX_HOPS) {
|
||||
LOGGER.debug("Rebroadcasting arbitrary signature list for peer {}", peerAddress);
|
||||
Network.getInstance().broadcast(broadcastPeer -> broadcastPeer == peer ? null : arbitrarySignaturesMessage);
|
||||
}
|
||||
} else {
|
||||
// Don't rebroadcast as otherwise we could get into a loop
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
public class ArbitraryDataStorageManager extends Thread {
|
||||
|
||||
public enum StoragePolicy {
|
||||
FOLLOWED_AND_VIEWED,
|
||||
FOLLOWED_OR_VIEWED,
|
||||
FOLLOWED,
|
||||
VIEWED,
|
||||
ALL,
|
||||
@ -126,7 +126,7 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
|
||||
// Check if our storage policy and and lists allow us to host data for this name
|
||||
switch (Settings.getInstance().getStoragePolicy()) {
|
||||
case FOLLOWED_AND_VIEWED:
|
||||
case FOLLOWED_OR_VIEWED:
|
||||
case ALL:
|
||||
case VIEWED:
|
||||
// If the policy includes viewed data, we can host it as long as it's not blocked
|
||||
@ -189,7 +189,7 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
|
||||
switch (Settings.getInstance().getStoragePolicy()) {
|
||||
case FOLLOWED:
|
||||
case FOLLOWED_AND_VIEWED:
|
||||
case FOLLOWED_OR_VIEWED:
|
||||
return this.isFollowingName(name);
|
||||
|
||||
case ALL:
|
||||
@ -217,7 +217,7 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
case NONE:
|
||||
case VIEWED:
|
||||
case FOLLOWED:
|
||||
case FOLLOWED_AND_VIEWED:
|
||||
case FOLLOWED_OR_VIEWED:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.qortal.network.message;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import org.qortal.data.network.PeerData;
|
||||
import org.qortal.transaction.DeployAtTransaction;
|
||||
import org.qortal.transform.TransformationException;
|
||||
import org.qortal.transform.Transformer;
|
||||
import org.qortal.utils.Serialization;
|
||||
@ -19,16 +18,18 @@ public class ArbitrarySignaturesMessage extends Message {
|
||||
private static final int SIGNATURE_LENGTH = Transformer.SIGNATURE_LENGTH;
|
||||
|
||||
private String peerAddress;
|
||||
private int requestHops;
|
||||
private List<byte[]> signatures;
|
||||
|
||||
public ArbitrarySignaturesMessage(String peerAddress, List<byte[]> signatures) {
|
||||
this(-1, peerAddress, signatures);
|
||||
public ArbitrarySignaturesMessage(String peerAddress, int requestHops, List<byte[]> signatures) {
|
||||
this(-1, peerAddress, requestHops, signatures);
|
||||
}
|
||||
|
||||
private ArbitrarySignaturesMessage(int id, String peerAddress, List<byte[]> signatures) {
|
||||
private ArbitrarySignaturesMessage(int id, String peerAddress, int requestHops, List<byte[]> signatures) {
|
||||
super(id, MessageType.ARBITRARY_SIGNATURES);
|
||||
|
||||
this.peerAddress = peerAddress;
|
||||
this.requestHops = requestHops;
|
||||
this.signatures = signatures;
|
||||
}
|
||||
|
||||
@ -40,9 +41,19 @@ public class ArbitrarySignaturesMessage extends Message {
|
||||
return this.signatures;
|
||||
}
|
||||
|
||||
public int getRequestHops() {
|
||||
return this.requestHops;
|
||||
}
|
||||
|
||||
public void setRequestHops(int requestHops) {
|
||||
this.requestHops = requestHops;
|
||||
}
|
||||
|
||||
public static Message fromByteBuffer(int id, ByteBuffer bytes) throws UnsupportedEncodingException, TransformationException {
|
||||
String peerAddress = Serialization.deserializeSizedString(bytes, PeerData.MAX_PEER_ADDRESS_SIZE);
|
||||
|
||||
int requestHops = bytes.getInt();
|
||||
|
||||
int signatureCount = bytes.getInt();
|
||||
|
||||
if (bytes.remaining() != signatureCount * SIGNATURE_LENGTH)
|
||||
@ -55,7 +66,7 @@ public class ArbitrarySignaturesMessage extends Message {
|
||||
signatures.add(signature);
|
||||
}
|
||||
|
||||
return new ArbitrarySignaturesMessage(id, peerAddress, signatures);
|
||||
return new ArbitrarySignaturesMessage(id, peerAddress, requestHops, signatures);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,6 +76,8 @@ public class ArbitrarySignaturesMessage extends Message {
|
||||
|
||||
Serialization.serializeSizedString(bytes, this.peerAddress);
|
||||
|
||||
bytes.write(Ints.toByteArray(this.requestHops));
|
||||
|
||||
bytes.write(Ints.toByteArray(this.signatures.size()));
|
||||
|
||||
for (byte[] signature : this.signatures)
|
||||
|
@ -214,8 +214,6 @@ public class Settings {
|
||||
private int maxBlocksPerRequest = 100;
|
||||
/** Maximum number of blocks this node will serve in a single response */
|
||||
private int maxBlocksPerResponse = 200;
|
||||
/** Maximum number of untrimmed blocks this node will serve in a single response */
|
||||
private int maxUntrimmedBlocksPerResponse = 10;
|
||||
|
||||
// Which blockchains this node is running
|
||||
private String blockchainConfig = null; // use default from resources
|
||||
@ -284,7 +282,7 @@ public class Settings {
|
||||
private String tempDataPath = null;
|
||||
|
||||
/** Storage policy to indicate which data should be hosted */
|
||||
private String storagePolicy = "FOLLOWED_AND_VIEWED";
|
||||
private String storagePolicy = "FOLLOWED_OR_VIEWED";
|
||||
|
||||
/** Whether to allow data outside of the storage policy to be relayed between other peers */
|
||||
private boolean relayModeEnabled = true;
|
||||
@ -709,8 +707,6 @@ public class Settings {
|
||||
|
||||
public int getMaxBlocksPerResponse() { return this.maxBlocksPerResponse; }
|
||||
|
||||
public int getMaxUntrimmedBlocksPerResponse() { return this.maxUntrimmedBlocksPerResponse; }
|
||||
|
||||
public boolean isAutoUpdateEnabled() {
|
||||
return this.autoUpdateEnabled;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ public class ArbitraryTransaction extends Transaction {
|
||||
if (ArbitraryDataStorageManager.getInstance().canStoreData(arbitraryTransactionData)) {
|
||||
// Use a null peer address to indicate our own
|
||||
byte[] signature = arbitraryTransactionData.getSignature();
|
||||
Message arbitrarySignatureMessage = new ArbitrarySignaturesMessage(null, Arrays.asList(signature));
|
||||
Message arbitrarySignatureMessage = new ArbitrarySignaturesMessage(null, 0, Arrays.asList(signature));
|
||||
Network.getInstance().broadcast(broadcastPeer -> arbitrarySignatureMessage);
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class ArbitraryDataStoragePolicyTests extends Common {
|
||||
assertTrue(ResourceListManager.getInstance().addToList("followedNames", name, false));
|
||||
|
||||
// We should store and pre-fetch data for this transaction
|
||||
assertEquals(StoragePolicy.FOLLOWED_AND_VIEWED, Settings.getInstance().getStoragePolicy());
|
||||
assertEquals(StoragePolicy.FOLLOWED_OR_VIEWED, Settings.getInstance().getStoragePolicy());
|
||||
assertTrue(storageManager.canStoreData(transactionData));
|
||||
assertTrue(storageManager.shouldPreFetchData(repository, transactionData));
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
"dataPath": "data-test",
|
||||
"tempDataPath": "data-test/_temp",
|
||||
"listsPath": "lists-test",
|
||||
"storagePolicy": "FOLLOWED_AND_VIEWED",
|
||||
"storagePolicy": "FOLLOWED_OR_VIEWED",
|
||||
"maxStorageCapacity": 104857600,
|
||||
"localAuthBypassEnabled": true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user