Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce initial data request #4586

Merged
merged 30 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e50e4c
Add PersistableNetworkPayloadStore
chimp1984 Oct 1, 2020
240f0b9
Use PersistableNetworkPayloadStore as base class for stores which had…
chimp1984 Oct 1, 2020
431debe
Unrelated to PR topic fix: Only log warnings if banned object is not …
chimp1984 Oct 1, 2020
b90fd39
Unrelated to PR topic: Improve logs for windows: \n is not recognized…
chimp1984 Oct 1, 2020
7122ef0
Refactoring: Rename variables
chimp1984 Oct 1, 2020
df90b24
Add new methods and refactor APIs. Needed later for new classes....
chimp1984 Oct 1, 2020
9446f28
Split read store and get store so it can be reused from new class (fu…
chimp1984 Oct 1, 2020
384152f
Add version field to data requests classes
chimp1984 Oct 1, 2020
c79504c
Add getter (needed later)
chimp1984 Oct 1, 2020
3fb73ac
Add HistoricalDataStoreService
chimp1984 Oct 1, 2020
3df2f7e
Add HISTORY field. Make isNewVersion public
chimp1984 Oct 1, 2020
e44fdbd
Refactoring: Rename variable
chimp1984 Oct 1, 2020
62836d7
Add support for HistoricalDataStoreService
chimp1984 Oct 1, 2020
58efb62
Refactoring: Rearrange method (moved method)
chimp1984 Oct 1, 2020
65de106
Use HistoricalDataStoreService for TradeStatistics2StorageService
chimp1984 Oct 1, 2020
8ea6da0
Apply changes to test classes
chimp1984 Oct 1, 2020
6f5bfde
Deactivate usage of HistoricalDataStoreService for now.
chimp1984 Oct 1, 2020
a1debd8
Fix grammar
chimp1984 Oct 1, 2020
5027c86
Fix proto field index
chimp1984 Oct 1, 2020
3ee60d5
Add license
chimp1984 Oct 1, 2020
c308791
Add license
chimp1984 Oct 1, 2020
25a7979
Merge branch 'master_upstream' into reduce-initial-date-request
chimp1984 Oct 2, 2020
ef7f5a7
Revert nonce index at PreliminaryGetDataRequest protobuf entry to 21 …
chimp1984 Oct 2, 2020
d3384e6
Update p2p/src/main/java/bisq/network/p2p/storage/persistence/Histori…
chimp1984 Oct 2, 2020
9d51714
Update p2p/src/main/java/bisq/network/p2p/storage/persistence/Histori…
chimp1984 Oct 2, 2020
35d13fb
Make putIfAbsent method more clear
chimp1984 Oct 2, 2020
611bcef
Update p2p/src/main/java/bisq/network/p2p/storage/persistence/Histori…
chimp1984 Oct 2, 2020
e9c57b1
Update p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java
chimp1984 Oct 2, 2020
308aa16
Update p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java
chimp1984 Oct 2, 2020
807b9fc
Remove unused method, fix typo, remove unneeded annotations
chimp1984 Oct 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import lombok.Getter;
import lombok.ToString;

import javax.annotation.Nullable;

@EqualsAndHashCode(callSuper = true)
@Getter
@ToString
Expand All @@ -35,11 +37,18 @@ public abstract class GetDataRequest extends NetworkEnvelope implements Extended
// Keys for ProtectedStorageEntry items to be excluded from the request because the peer has them already
protected final Set<byte[]> excludedKeys;

// Added at v1.4.0
// The version of the requester. Used for response to send potentially missing historical data
@Nullable
protected final String version;

public GetDataRequest(int messageVersion,
int nonce,
Set<byte[]> excludedKeys) {
Set<byte[]> excludedKeys,
@Nullable String version) {
super(messageVersion);
this.nonce = nonce;
this.excludedKeys = excludedKeys;
this.version = version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@

import com.google.protobuf.ByteString;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;

@Slf4j
@EqualsAndHashCode(callSuper = true)
Expand All @@ -48,6 +49,7 @@ public GetUpdatedDataRequest(NodeAddress senderNodeAddress,
this(senderNodeAddress,
nonce,
excludedKeys,
Version.VERSION,
Version.getP2PMessageVersion());
}

Expand All @@ -59,35 +61,41 @@ public GetUpdatedDataRequest(NodeAddress senderNodeAddress,
private GetUpdatedDataRequest(NodeAddress senderNodeAddress,
int nonce,
Set<byte[]> excludedKeys,
@Nullable String version,
int messageVersion) {
super(messageVersion,
nonce,
excludedKeys);
checkNotNull(senderNodeAddress, "senderNodeAddress must not be null at GetUpdatedDataRequest");
excludedKeys,
version);
this.senderNodeAddress = senderNodeAddress;
}

@Override
public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
final protobuf.GetUpdatedDataRequest.Builder builder = protobuf.GetUpdatedDataRequest.newBuilder()
protobuf.GetUpdatedDataRequest.Builder builder = protobuf.GetUpdatedDataRequest.newBuilder()
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setNonce(nonce)
.addAllExcludedKeys(excludedKeys.stream()
.map(ByteString::copyFrom)
.collect(Collectors.toList()));

Optional.ofNullable(version).ifPresent(builder::setVersion);
NetworkEnvelope proto = getNetworkEnvelopeBuilder()
.setGetUpdatedDataRequest(builder)
.build();
log.info("Sending a GetUpdatedDataRequest with {} kB", proto.getSerializedSize() / 1000d);
log.info("Sending a GetUpdatedDataRequest with {} kB and {} excluded key entries. Requesters version={}",
proto.getSerializedSize() / 1000d, excludedKeys.size(), version);
return proto;
}

public static GetUpdatedDataRequest fromProto(protobuf.GetUpdatedDataRequest proto, int messageVersion) {
log.info("Received a GetUpdatedDataRequest with {} kB", proto.getSerializedSize() / 1000d);
Set<byte[]> excludedKeys = ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList());
String requestersVersion = ProtoUtil.stringOrNullFromProto(proto.getVersion());
log.info("Received a GetUpdatedDataRequest with {} kB and {} excluded key entries. Requesters version={}",
proto.getSerializedSize() / 1000d, excludedKeys.size(), requestersVersion);
return new GetUpdatedDataRequest(NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getNonce(),
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()),
excludedKeys,
requestersVersion,
messageVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@

import com.google.protobuf.ByteString;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;

@Slf4j
@EqualsAndHashCode(callSuper = true)
@Value
public final class PreliminaryGetDataRequest extends GetDataRequest implements AnonymousMessage, SupportedCapabilitiesMessage {
private final Capabilities supportedCapabilities;

public PreliminaryGetDataRequest(int nonce,
@NotNull Set<byte[]> excludedKeys) {
this(nonce, excludedKeys, Capabilities.app, Version.getP2PMessageVersion());
public PreliminaryGetDataRequest(int nonce, Set<byte[]> excludedKeys) {
this(nonce,
excludedKeys,
Version.VERSION,
Capabilities.app,
Version.getP2PMessageVersion());
}


Expand All @@ -54,34 +58,40 @@ public PreliminaryGetDataRequest(int nonce,
///////////////////////////////////////////////////////////////////////////////////////////

private PreliminaryGetDataRequest(int nonce,
@NotNull Set<byte[]> excludedKeys,
@NotNull Capabilities supportedCapabilities,
Set<byte[]> excludedKeys,
@Nullable String version,
Capabilities supportedCapabilities,
int messageVersion) {
super(messageVersion, nonce, excludedKeys);
super(messageVersion, nonce, excludedKeys, version);

this.supportedCapabilities = supportedCapabilities;
}

@Override
public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
final protobuf.PreliminaryGetDataRequest.Builder builder = protobuf.PreliminaryGetDataRequest.newBuilder()
protobuf.PreliminaryGetDataRequest.Builder builder = protobuf.PreliminaryGetDataRequest.newBuilder()
.addAllSupportedCapabilities(Capabilities.toIntList(supportedCapabilities))
.setNonce(nonce)
.addAllExcludedKeys(excludedKeys.stream()
.map(ByteString::copyFrom)
.collect(Collectors.toList()));

Optional.ofNullable(version).ifPresent(builder::setVersion);
NetworkEnvelope proto = getNetworkEnvelopeBuilder()
.setPreliminaryGetDataRequest(builder)
.build();
log.info("Sending a PreliminaryGetDataRequest with {} kB", proto.getSerializedSize() / 1000d);
log.info("Sending a PreliminaryGetDataRequest with {} kB and {} excluded key entries. Requesters version={}",
proto.getSerializedSize() / 1000d, excludedKeys.size(), version);
return proto;
}

public static PreliminaryGetDataRequest fromProto(protobuf.PreliminaryGetDataRequest proto, int messageVersion) {
log.info("Received a PreliminaryGetDataRequest with {} kB", proto.getSerializedSize() / 1000d);
Set<byte[]> excludedKeys = ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList());
String requestersVersion = ProtoUtil.stringOrNullFromProto(proto.getVersion());
log.info("Received a PreliminaryGetDataRequest with {} kB and {} excluded key entries. Requesters version={}",
proto.getSerializedSize() / 1000d, excludedKeys.size(), requestersVersion);
return new PreliminaryGetDataRequest(proto.getNonce(),
ProtoUtil.byteSetFromProtoByteStringList(proto.getExcludedKeysList()),
excludedKeys,
requestersVersion,
Capabilities.fromIntList(proto.getSupportedCapabilitiesList()),
messageVersion);
}
Expand Down
2 changes: 2 additions & 0 deletions proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ message PreliminaryGetDataRequest {
int32 nonce = 21;
chimp1984 marked this conversation as resolved.
Show resolved Hide resolved
repeated bytes excluded_keys = 2;
repeated int32 supported_capabilities = 3;
string version = 4;
}

message GetDataResponse {
Expand All @@ -109,6 +110,7 @@ message GetUpdatedDataRequest {
NodeAddress sender_node_address = 1;
int32 nonce = 2;
repeated bytes excluded_keys = 3;
string version = 4;
}

// peers
Expand Down