mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Add ExcludeForHashAwareProto interface to DataAndSeqNrPair
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
b3288e3839
commit
cb565bdbb2
@ -55,6 +55,7 @@ import bisq.network.p2p.storage.persistence.RemovedPayloadsService;
|
||||
import bisq.network.p2p.storage.persistence.ResourceDataStoreService;
|
||||
import bisq.network.p2p.storage.persistence.SequenceNumberMap;
|
||||
|
||||
import bisq.common.ExcludeForHashAwareProto;
|
||||
import bisq.common.Timer;
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.app.Capabilities;
|
||||
@ -71,6 +72,8 @@ import bisq.common.util.Hex;
|
||||
import bisq.common.util.Tuple2;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import protobuf.StoragePayload;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import com.google.inject.name.Named;
|
||||
@ -1253,8 +1256,8 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public static final class DataAndSeqNrPair implements NetworkPayload {
|
||||
// data are only used for calculating cryptographic hash from both values so they are kept private
|
||||
public static final class DataAndSeqNrPair implements NetworkPayload, ExcludeForHashAwareProto {
|
||||
// data are only used for calculating cryptographic hash from both values, so they are kept private
|
||||
private final ProtectedStoragePayload protectedStoragePayload;
|
||||
private final int sequenceNumber;
|
||||
|
||||
@ -1263,13 +1266,31 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
this.sequenceNumber = sequenceNumber;
|
||||
}
|
||||
|
||||
// Used only for calculating hash of byte array from PB object
|
||||
@Override
|
||||
public com.google.protobuf.Message toProtoMessage() {
|
||||
public protobuf.DataAndSeqNrPair toProtoMessage() {
|
||||
return toProto(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public protobuf.DataAndSeqNrPair toProto(boolean serializeForHash) {
|
||||
return resolveProto(serializeForHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public protobuf.DataAndSeqNrPair.Builder getBuilder(boolean serializeForHash) {
|
||||
return protobuf.DataAndSeqNrPair.newBuilder()
|
||||
.setPayload((protobuf.StoragePayload) protectedStoragePayload.toProtoMessage())
|
||||
.setSequenceNumber(sequenceNumber)
|
||||
.build();
|
||||
.setPayload(toStoragePayloadProto(serializeForHash))
|
||||
.setSequenceNumber(sequenceNumber);
|
||||
}
|
||||
|
||||
private protobuf.StoragePayload toStoragePayloadProto(boolean serializeForHash) {
|
||||
if (protectedStoragePayload instanceof ExcludeForHashAwareProto) {
|
||||
ExcludeForHashAwareProto proto = (ExcludeForHashAwareProto) protectedStoragePayload;
|
||||
StoragePayload.Builder builder = (StoragePayload.Builder) proto.getBuilder(serializeForHash);
|
||||
return resolveBuilder(builder, serializeForHash).build();
|
||||
} else {
|
||||
return (StoragePayload) protectedStoragePayload.toProtoMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user