Don't allow files or file lists to be relayed if they relate to a blocked name.

This gives relay operators some control over the content they are relaying.
This commit is contained in:
CalDescent 2021-12-22 09:21:08 +00:00
parent 8caec81d1e
commit 4799a8a68e

View File

@ -815,13 +815,15 @@ public class ArbitraryDataManager extends Thread {
return; return;
} }
ArbitraryTransactionData arbitraryTransactionData = null;
// Check transaction exists and hashes are correct // Check transaction exists and hashes are correct
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature); TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature);
if (!(transactionData instanceof ArbitraryTransactionData)) if (!(transactionData instanceof ArbitraryTransactionData))
return; return;
ArbitraryTransactionData arbitraryTransactionData = (ArbitraryTransactionData) transactionData; arbitraryTransactionData = (ArbitraryTransactionData) transactionData;
// Load data file(s) // Load data file(s)
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(arbitraryTransactionData.getData(), signature); ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(arbitraryTransactionData.getData(), signature);
@ -854,6 +856,8 @@ public class ArbitraryDataManager extends Thread {
// Forwarding // Forwarding
if (isRelayRequest && Settings.getInstance().isRelayModeEnabled()) { if (isRelayRequest && Settings.getInstance().isRelayModeEnabled()) {
boolean isBlocked = (arbitraryTransactionData == null || ArbitraryDataStorageManager.getInstance().isNameBlocked(arbitraryTransactionData.getName()));
if (!isBlocked) {
Peer requestingPeer = request.getB(); Peer requestingPeer = request.getB();
if (requestingPeer != null) { if (requestingPeer != null) {
// Add each hash to our local mapping so we know who to ask later // Add each hash to our local mapping so we know who to ask later
@ -873,6 +877,7 @@ public class ArbitraryDataManager extends Thread {
} }
} }
} }
}
public void onNetworkGetArbitraryDataFileMessage(Peer peer, Message message) { public void onNetworkGetArbitraryDataFileMessage(Peer peer, Message message) {
GetArbitraryDataFileMessage getArbitraryDataFileMessage = (GetArbitraryDataFileMessage) message; GetArbitraryDataFileMessage getArbitraryDataFileMessage = (GetArbitraryDataFileMessage) message;
@ -903,12 +908,12 @@ public class ArbitraryDataManager extends Thread {
LOGGER.info("We have relay info for hash {}", Base58.encode(hash)); LOGGER.info("We have relay info for hash {}", Base58.encode(hash));
// We need to ask this peer for the file // We need to ask this peer for the file
Peer peerToAsk = relayInfo.getB(); Peer peerToAsk = relayInfo.getB();
//Peer peerToAsk = Network.getInstance().getConnectedPeerWithAddress(peerAddress);
if (peerToAsk != null) { if (peerToAsk != null) {
// Forward the message to this peer // Forward the message to this peer
LOGGER.info("Asking peer {} for hash {}", peerToAsk, hash58); LOGGER.info("Asking peer {} for hash {}", peerToAsk, hash58);
this.fetchArbitraryDataFile(peerToAsk, peer, signature, hash, message);
ArbitraryDataFileMessage arbitraryDataFileMessage = this.fetchArbitraryDataFile(peerToAsk, peer, signature, hash, message);
// Remove from the map regardless of outcome, as the relay attempt is now considered complete // Remove from the map regardless of outcome, as the relay attempt is now considered complete
arbitraryRelayMap.remove(hash58); arbitraryRelayMap.remove(hash58);
} }
@ -960,11 +965,12 @@ public class ArbitraryDataManager extends Thread {
LOGGER.info("Received hash list request from peer {} for signature {}", peer, Base58.encode(signature)); LOGGER.info("Received hash list request from peer {} for signature {}", peer, Base58.encode(signature));
List<byte[]> hashes = new ArrayList<>(); List<byte[]> hashes = new ArrayList<>();
ArbitraryTransactionData transactionData = null;
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
// Firstly we need to lookup this file on chain to get a list of its hashes // Firstly we need to lookup this file on chain to get a list of its hashes
ArbitraryTransactionData transactionData = (ArbitraryTransactionData)repository.getTransactionRepository().fromSignature(signature); transactionData = (ArbitraryTransactionData)repository.getTransactionRepository().fromSignature(signature);
if (transactionData instanceof ArbitraryTransactionData) { if (transactionData instanceof ArbitraryTransactionData) {
// Check if we're even allowed to serve data for this transaction // Check if we're even allowed to serve data for this transaction
@ -1021,7 +1027,8 @@ public class ArbitraryDataManager extends Thread {
} }
else { else {
if (Settings.getInstance().isRelayModeEnabled()) { boolean isBlocked = (transactionData == null || ArbitraryDataStorageManager.getInstance().isNameBlocked(transactionData.getName()));
if (Settings.getInstance().isRelayModeEnabled() && !isBlocked) {
// In relay mode - so ask our other peers if they have it // In relay mode - so ask our other peers if they have it
LOGGER.info("Rebroadcasted hash list request from peer {} for signature {} to our other peers", peer, Base58.encode(signature)); LOGGER.info("Rebroadcasted hash list request from peer {} for signature {} to our other peers", peer, Base58.encode(signature));
Network.getInstance().broadcast( Network.getInstance().broadcast(