forked from Qortal/qortal
Maintain backwards support for pre-3.2.0 peers by only including new file list message params when sending to newer peers.
These params are optional and the process will function without them, just less efficiently.
This commit is contained in:
parent
3dadce4da4
commit
eac4b0d87b
@ -29,6 +29,7 @@ public class ArbitraryDataFileListManager {
|
||||
|
||||
private static ArbitraryDataFileListManager instance;
|
||||
|
||||
private static String MIN_PEER_VERSION_FOR_FILE_LIST_STATS = "3.2.0";
|
||||
|
||||
/**
|
||||
* Map of recent incoming requests for ARBITRARY transaction data file lists.
|
||||
@ -488,6 +489,12 @@ public class ArbitraryDataFileListManager {
|
||||
arbitraryDataFileListMessage.setRequestHops(++requestHops);
|
||||
}
|
||||
|
||||
// Remove optional parameters if the requesting peer doesn't support it yet
|
||||
// A message with less statistical data is better than no message at all
|
||||
if (!requestingPeer.isAtLeastVersion(MIN_PEER_VERSION_FOR_FILE_LIST_STATS)) {
|
||||
arbitraryDataFileListMessage.removeOptionalStats();
|
||||
}
|
||||
|
||||
// Forward to requesting peer
|
||||
LOGGER.debug("Forwarding file list with {} hashes to requesting peer: {}", hashes.size(), requestingPeer);
|
||||
if (!requestingPeer.sendMessage(arbitraryDataFileListMessage)) {
|
||||
@ -594,6 +601,13 @@ public class ArbitraryDataFileListManager {
|
||||
ArbitraryDataFileListMessage arbitraryDataFileListMessage = new ArbitraryDataFileListMessage(signature,
|
||||
hashes, NTP.getTime(), 0, ourAddress, true);
|
||||
arbitraryDataFileListMessage.setId(message.getId());
|
||||
|
||||
// Remove optional parameters if the requesting peer doesn't support it yet
|
||||
// A message with less statistical data is better than no message at all
|
||||
if (!peer.isAtLeastVersion(MIN_PEER_VERSION_FOR_FILE_LIST_STATS)) {
|
||||
arbitraryDataFileListMessage.removeOptionalStats();
|
||||
}
|
||||
|
||||
if (!peer.sendMessage(arbitraryDataFileListMessage)) {
|
||||
LOGGER.debug("Couldn't send list of hashes");
|
||||
peer.disconnect("failed to send list of hashes");
|
||||
|
@ -22,10 +22,10 @@ public class ArbitraryDataFileListMessage extends Message {
|
||||
|
||||
private final byte[] signature;
|
||||
private final List<byte[]> hashes;
|
||||
private final Long requestTime;
|
||||
private Long requestTime;
|
||||
private Integer requestHops;
|
||||
private final String peerAddress;
|
||||
private final boolean isRelayPossible;
|
||||
private String peerAddress;
|
||||
private Boolean isRelayPossible;
|
||||
|
||||
|
||||
public ArbitraryDataFileListMessage(byte[] signature, List<byte[]> hashes, Long requestTime,
|
||||
@ -109,7 +109,7 @@ public class ArbitraryDataFileListMessage extends Message {
|
||||
bytes.write(hash);
|
||||
}
|
||||
|
||||
if (this.requestTime == null) { // Just in case
|
||||
if (this.requestTime == null) { // To maintain backwards support
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
|
||||
@ -136,15 +136,26 @@ public class ArbitraryDataFileListMessage extends Message {
|
||||
return clone;
|
||||
}
|
||||
|
||||
public void removeOptionalStats() {
|
||||
this.requestTime = null;
|
||||
this.requestHops = null;
|
||||
this.peerAddress = null;
|
||||
this.isRelayPossible = null;
|
||||
}
|
||||
|
||||
public Long getRequestTime() {
|
||||
return this.requestTime;
|
||||
}
|
||||
|
||||
public void setRequestTime(Long requestTime) {
|
||||
this.requestTime = requestTime;
|
||||
}
|
||||
|
||||
public Integer getRequestHops() {
|
||||
return this.requestHops;
|
||||
}
|
||||
|
||||
public void setRequestHops(int requestHops) {
|
||||
public void setRequestHops(Integer requestHops) {
|
||||
this.requestHops = requestHops;
|
||||
}
|
||||
|
||||
@ -152,8 +163,16 @@ public class ArbitraryDataFileListMessage extends Message {
|
||||
return this.peerAddress;
|
||||
}
|
||||
|
||||
public boolean isRelayPossible() {
|
||||
public void setPeerAddress(String peerAddress) {
|
||||
this.peerAddress = peerAddress;
|
||||
}
|
||||
|
||||
public Boolean isRelayPossible() {
|
||||
return this.isRelayPossible;
|
||||
}
|
||||
|
||||
public void setIsRelayPossible(Boolean isRelayPossible) {
|
||||
this.isRelayPossible = isRelayPossible;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user