Remove excuded keys when requesting the account witness data

This commit is contained in:
Manfred Karrer 2017-11-03 11:22:19 -05:00
parent f1a3c6e7b2
commit 00d868dd9d
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
6 changed files with 22 additions and 60 deletions

View file

@ -71,7 +71,6 @@ message PreliminaryGetDataRequest {
int32 nonce = 21;
repeated bytes excluded_keys = 2;
repeated int32 supported_capabilities = 3;
repeated bytes excluded_pnp_keys = 4;
}
message GetDataResponse {
@ -86,7 +85,6 @@ message GetUpdatedDataRequest {
NodeAddress sender_node_address = 1;
int32 nonce = 2;
repeated bytes excluded_keys = 3;
repeated bytes excluded_pnp_keys = 4;
}

View file

@ -83,7 +83,7 @@ public class GetDataRequestHandler {
.filter(e -> !excludedKeysAsByteArray.contains(e.getKey()))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
for (ProtectedStorageEntry protectedStorageEntry : filteredSet) {
final ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload();
boolean doAdd = false;
@ -113,9 +113,9 @@ public class GetDataRequestHandler {
doAdd = true;
}
if (doAdd) {
// We have TradeStatistic data of both traders but we only send 1 item,
// so we use lookupSet as for a fast lookup. Using filteredDataSet would require a loop as it stores
// protectedStorageEntry not storagePayload. protectedStorageEntry is different for both traders but storagePayload not,
// We have TradeStatistic data of both traders but we only send 1 item,
// so we use lookupSet as for a fast lookup. Using filteredDataSet would require a loop as it stores
// protectedStorageEntry not storagePayload. protectedStorageEntry is different for both traders but storagePayload not,
// as we ignore the pubKey and data there in the hashCode method.
boolean notContained = lookupSet.add(protectedStoragePayload.hashCode());
if (notContained)
@ -123,14 +123,13 @@ public class GetDataRequestHandler {
}
}
Set<P2PDataStorage.ByteArray> excludedPnpKeysAsByteArray = P2PDataStorage.ByteArray.convertBytesSetToByteArraySet(getDataRequest.getExcludedPnpKeys());
Set<PersistableNetworkPayload> filteredPnpSet = dataStorage.getPersistableNetworkPayloadCollection().getMap().entrySet().stream()
.filter(e -> !excludedPnpKeysAsByteArray.contains(e.getKey()))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
Set<PersistableNetworkPayload> pnpSet = dataStorage.getPersistableNetworkPayloadCollection().getMap().values()
.stream()
.collect(Collectors.toSet());
GetDataResponse getDataResponse = new GetDataResponse(filteredDataSet,
filteredPnpSet,
pnpSet,
getDataRequest.getNonce(),
getDataRequest instanceof GetUpdatedDataRequest);

View file

@ -105,14 +105,10 @@ class RequestDataHandler implements MessageListener {
.map(e -> e.getKey().bytes)
.collect(Collectors.toSet());
Set<byte[]> excludedPnpKeys = dataStorage.getPersistableNetworkPayloadCollection().getMap().entrySet().stream()
.map(e -> e.getKey().bytes)
.collect(Collectors.toSet());
if (isPreliminaryDataRequest)
getDataRequest = new PreliminaryGetDataRequest(nonce, excludedKeys, excludedPnpKeys);
getDataRequest = new PreliminaryGetDataRequest(nonce, excludedKeys);
else
getDataRequest = new GetUpdatedDataRequest(networkNode.getNodeAddress(), nonce, excludedKeys, excludedPnpKeys);
getDataRequest = new GetUpdatedDataRequest(networkNode.getNodeAddress(), nonce, excludedKeys);
if (timeoutTimer == null) {
timeoutTimer = UserThread.runAfter(() -> { // setup before sending to avoid race conditions

View file

@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import javax.annotation.Nullable;
import java.util.Set;
@EqualsAndHashCode(callSuper = true)
@ -16,18 +15,12 @@ public abstract class GetDataRequest extends NetworkEnvelope implements Extended
protected final int nonce;
// Keys for ProtectedStorageEntry items to be excluded from the request because the peer has them already
protected final Set<byte[]> excludedKeys;
// Keys for PersistableNetworkPayload items to be excluded from the request because the peer has them already
// We added that in v 0.6 and we would get a null object from older peers, so keep it annotated with @Nullable
@Nullable
protected final Set<byte[]> excludedPnpKeys;
public GetDataRequest(int messageVersion,
int nonce,
Set<byte[]> excludedKeys,
@Nullable Set<byte[]> excludedPnpKeys) {
Set<byte[]> excludedKeys) {
super(messageVersion);
this.nonce = nonce;
this.excludedKeys = excludedKeys;
this.excludedPnpKeys = excludedPnpKeys;
}
}

View file

@ -9,8 +9,6 @@ import io.bisq.network.p2p.SendersNodeAddressMessage;
import lombok.EqualsAndHashCode;
import lombok.Value;
import javax.annotation.Nullable;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@ -23,13 +21,11 @@ public final class GetUpdatedDataRequest extends GetDataRequest implements Sende
public GetUpdatedDataRequest(NodeAddress senderNodeAddress,
int nonce,
Set<byte[]> excludedKeys,
@Nullable Set<byte[]> excludedPnpKeys) {
Set<byte[]> excludedKeys) {
this(senderNodeAddress,
nonce,
excludedKeys,
Version.getP2PMessageVersion(),
excludedPnpKeys);
Version.getP2PMessageVersion());
}
@ -40,12 +36,10 @@ public final class GetUpdatedDataRequest extends GetDataRequest implements Sende
private GetUpdatedDataRequest(NodeAddress senderNodeAddress,
int nonce,
Set<byte[]> excludedKeys,
int messageVersion,
@Nullable Set<byte[]> excludedPnpKeys) {
int messageVersion) {
super(messageVersion,
nonce,
excludedKeys,
excludedPnpKeys);
excludedKeys);
checkNotNull(senderNodeAddress, "senderNodeAddress must not be null at GetUpdatedDataRequest");
this.senderNodeAddress = senderNodeAddress;
}
@ -58,10 +52,6 @@ public final class GetUpdatedDataRequest extends GetDataRequest implements Sende
.addAllExcludedKeys(excludedKeys.stream()
.map(ByteString::copyFrom)
.collect(Collectors.toList()));
Optional.ofNullable(excludedPnpKeys).ifPresent(excludedPnpKeys -> builder.addAllExcludedPnpKeys(excludedPnpKeys.stream()
.map(ByteString::copyFrom)
.collect(Collectors.toList())));
return getNetworkEnvelopeBuilder()
.setGetUpdatedDataRequest(builder)
@ -72,9 +62,6 @@ public final class GetUpdatedDataRequest extends GetDataRequest implements Sende
return new GetUpdatedDataRequest(NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getNonce(),
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()),
messageVersion,
proto.getExcludedPnpKeysList().isEmpty() ?
null :
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedPnpKeysList()));
messageVersion);
}
}

View file

@ -11,9 +11,7 @@ import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@ -25,9 +23,8 @@ public final class PreliminaryGetDataRequest extends GetDataRequest implements A
private final ArrayList<Integer> supportedCapabilities = Capabilities.getCapabilities();
public PreliminaryGetDataRequest(int nonce,
Set<byte[]> excludedKeys,
@Nullable Set<byte[]> excludedPnpKeys) {
this(nonce, excludedKeys, Version.getP2PMessageVersion(), excludedPnpKeys);
Set<byte[]> excludedKeys) {
this(nonce, excludedKeys, Version.getP2PMessageVersion());
}
@ -37,9 +34,8 @@ public final class PreliminaryGetDataRequest extends GetDataRequest implements A
private PreliminaryGetDataRequest(int nonce,
Set<byte[]> excludedKeys,
int messageVersion,
@Nullable Set<byte[]> excludedPnpKeys) {
super(messageVersion, nonce, excludedKeys, excludedPnpKeys);
int messageVersion) {
super(messageVersion, nonce, excludedKeys);
}
@Override
@ -51,10 +47,6 @@ public final class PreliminaryGetDataRequest extends GetDataRequest implements A
.collect(Collectors.toList()))
.addAllSupportedCapabilities(supportedCapabilities);
Optional.ofNullable(excludedPnpKeys).ifPresent(excludedPnpKeys -> builder.addAllExcludedPnpKeys(excludedPnpKeys.stream()
.map(ByteString::copyFrom)
.collect(Collectors.toList())));
return getNetworkEnvelopeBuilder()
.setPreliminaryGetDataRequest(builder)
.build();
@ -63,9 +55,6 @@ public final class PreliminaryGetDataRequest extends GetDataRequest implements A
public static PreliminaryGetDataRequest fromProto(PB.PreliminaryGetDataRequest proto, int messageVersion) {
return new PreliminaryGetDataRequest(proto.getNonce(),
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()),
messageVersion,
proto.getExcludedPnpKeysList().isEmpty() ?
null :
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedPnpKeysList()));
messageVersion);
}
}