Renamed DataFileMessage to ArbitraryDataFileMessage and GetDataFileMessage to GetArbitraryDataFileMessage

This commit is contained in:
CalDescent 2021-08-14 13:52:41 +01:00
parent 172a37ec8c
commit e99ea41117
4 changed files with 24 additions and 24 deletions

View File

@ -38,8 +38,8 @@ import org.qortal.group.Group;
import org.qortal.network.Network;
import org.qortal.network.Peer;
import org.qortal.network.PeerAddress;
import org.qortal.network.message.DataFileMessage;
import org.qortal.network.message.GetDataFileMessage;
import org.qortal.network.message.ArbitraryDataFileMessage;
import org.qortal.network.message.GetArbitraryDataFileMessage;
import org.qortal.network.message.Message;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
@ -515,7 +515,7 @@ public class ArbitraryResource {
LOGGER.info("Invalid base58 encoded string");
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA);
}
Message getDataFileMessage = new GetDataFileMessage(digest);
Message getDataFileMessage = new GetArbitraryDataFileMessage(digest);
Message message = targetPeer.getResponse(getDataFileMessage);
if (message == null) {
@ -525,12 +525,12 @@ public class ArbitraryResource {
return false;
}
DataFileMessage dataFileMessage = (DataFileMessage) message;
arbitraryDataFile = dataFileMessage.getArbitraryDataFile();
ArbitraryDataFileMessage arbitraryDataFileMessage = (ArbitraryDataFileMessage) message;
arbitraryDataFile = arbitraryDataFileMessage.getArbitraryDataFile();
if (arbitraryDataFile == null || !arbitraryDataFile.exists()) {
return false;
}
LOGGER.info(String.format("Received file %s, size %d bytes", dataFileMessage.getArbitraryDataFile(), dataFileMessage.getArbitraryDataFile().size()));
LOGGER.info(String.format("Received file %s, size %d bytes", arbitraryDataFileMessage.getArbitraryDataFile(), arbitraryDataFileMessage.getArbitraryDataFile().size()));
return true;
} catch (ApiException e) {
throw e;

View File

@ -170,7 +170,7 @@ public class ArbitraryDataManager extends Thread {
String hash58 = Base58.encode(hash);
LOGGER.info(String.format("Fetching data file %.8s from peer %s", hash58, peer));
arbitraryDataFileRequests.put(hash58, NTP.getTime());
Message getDataFileMessage = new GetDataFileMessage(hash);
Message getDataFileMessage = new GetArbitraryDataFileMessage(hash);
Message message = peer.getResponse(getDataFileMessage);
arbitraryDataFileRequests.remove(hash58);
@ -180,8 +180,8 @@ public class ArbitraryDataManager extends Thread {
return null;
}
DataFileMessage dataFileMessage = (DataFileMessage) message;
return dataFileMessage.getArbitraryDataFile();
ArbitraryDataFileMessage arbitraryDataFileMessage = (ArbitraryDataFileMessage) message;
return arbitraryDataFileMessage.getArbitraryDataFile();
}
public void cleanupRequestCache(long now) {
@ -314,15 +314,15 @@ public class ArbitraryDataManager extends Thread {
}
public void onNetworkGetDataFileMessage(Peer peer, Message message) {
GetDataFileMessage getDataFileMessage = (GetDataFileMessage) message;
byte[] hash = getDataFileMessage.getHash();
GetArbitraryDataFileMessage getArbitraryDataFileMessage = (GetArbitraryDataFileMessage) message;
byte[] hash = getArbitraryDataFileMessage.getHash();
Controller.getInstance().stats.getDataFileMessageStats.requests.incrementAndGet();
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(hash);
if (arbitraryDataFile.exists()) {
DataFileMessage dataFileMessage = new DataFileMessage(arbitraryDataFile);
dataFileMessage.setId(message.getId());
if (!peer.sendMessage(dataFileMessage)) {
ArbitraryDataFileMessage arbitraryDataFileMessage = new ArbitraryDataFileMessage(arbitraryDataFile);
arbitraryDataFileMessage.setId(message.getId());
if (!peer.sendMessage(arbitraryDataFileMessage)) {
LOGGER.info("Couldn't sent file");
peer.disconnect("failed to send file");
}

View File

@ -8,17 +8,17 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class DataFileMessage extends Message {
public class ArbitraryDataFileMessage extends Message {
private final ArbitraryDataFile arbitraryDataFile;
public DataFileMessage(ArbitraryDataFile arbitraryDataFile) {
public ArbitraryDataFileMessage(ArbitraryDataFile arbitraryDataFile) {
super(MessageType.DATA_FILE);
this.arbitraryDataFile = arbitraryDataFile;
}
public DataFileMessage(int id, ArbitraryDataFile arbitraryDataFile) {
public ArbitraryDataFileMessage(int id, ArbitraryDataFile arbitraryDataFile) {
super(id, MessageType.DATA_FILE);
this.arbitraryDataFile = arbitraryDataFile;
@ -38,7 +38,7 @@ public class DataFileMessage extends Message {
byteBuffer.get(data);
ArbitraryDataFile arbitraryDataFile = new ArbitraryDataFile(data);
return new DataFileMessage(id, arbitraryDataFile);
return new ArbitraryDataFileMessage(id, arbitraryDataFile);
}
@Override
@ -65,8 +65,8 @@ public class DataFileMessage extends Message {
}
}
public DataFileMessage cloneWithNewId(int newId) {
DataFileMessage clone = new DataFileMessage(this.arbitraryDataFile);
public ArbitraryDataFileMessage cloneWithNewId(int newId) {
ArbitraryDataFileMessage clone = new ArbitraryDataFileMessage(this.arbitraryDataFile);
clone.setId(newId);
return clone;
}

View File

@ -7,17 +7,17 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class GetDataFileMessage extends Message {
public class GetArbitraryDataFileMessage extends Message {
private static final int HASH_LENGTH = TransactionTransformer.SHA256_LENGTH;
private final byte[] hash;
public GetDataFileMessage(byte[] hash) {
public GetArbitraryDataFileMessage(byte[] hash) {
this(-1, hash);
}
private GetDataFileMessage(int id, byte[] hash) {
private GetArbitraryDataFileMessage(int id, byte[] hash) {
super(id, MessageType.GET_DATA_FILE);
this.hash = hash;
@ -35,7 +35,7 @@ public class GetDataFileMessage extends Message {
bytes.get(hash);
return new GetDataFileMessage(id, hash);
return new GetArbitraryDataFileMessage(id, hash);
}
@Override