Add ability to do unused reads from CDSv2 to test server load.

This commit is contained in:
Greyson Parrelli
2022-08-17 18:23:40 -04:00
committed by Cody Henthorne
parent 84717b95f7
commit 15e52a8b88
7 changed files with 144 additions and 46 deletions

View File

@@ -52,13 +52,15 @@ public final class CdsiV2Service {
.map(CdsiV2Service::parseEntries)
.collect(Collectors.toList())
.flatMap(pages -> {
Map<String, ResponseItem> all = new HashMap<>();
Map<String, ResponseItem> all = new HashMap<>();
int quotaUsed = 0;
for (Response page : pages) {
all.putAll(page.getResults());
quotaUsed += page.getQuotaUsedDebugOnly();
}
return Single.just(new Response(all));
return Single.just(new Response(all, quotaUsed));
})
.map(result -> ServiceResponse.forResult(result, 200, null))
.onErrorReturn(error -> {
@@ -87,7 +89,7 @@ public final class CdsiV2Service {
}
}
return new Response(results);
return new Response(results, clientResponse.getDebugPermitsUsed());
}
private static ClientRequest buildClientRequest(Request request) {
@@ -146,13 +148,13 @@ public final class CdsiV2Service {
}
public static final class Request {
private final Set<String> previousE164s;
private final Set<String> newE164s;
private final Set<String> removedE164s;
final Set<String> previousE164s;
final Set<String> newE164s;
final Set<String> removedE164s;
private final Map<ServiceId, ProfileKey> serviceIds;
final Map<ServiceId, ProfileKey> serviceIds;
private final byte[] token;
final byte[] token;
public Request(Set<String> previousE164s, Set<String> newE164s, Map<ServiceId, ProfileKey> serviceIds, Optional<byte[]> token) {
if (previousE164s.size() > 0 && !token.isPresent()) {
@@ -166,10 +168,6 @@ public final class CdsiV2Service {
this.token = token.orElse(null);
}
public int totalE164s() {
return previousE164s.size() + newE164s.size() - removedE164s.size();
}
public int serviceIdSize() {
return previousE164s.size() + newE164s.size() + removedE164s.size() + serviceIds.size();
}
@@ -177,14 +175,24 @@ public final class CdsiV2Service {
public static final class Response {
private final Map<String, ResponseItem> results;
private final int quotaUsed;
public Response(Map<String, ResponseItem> results) {
this.results = results;
public Response(Map<String, ResponseItem> results, int quoteUsed) {
this.results = results;
this.quotaUsed = quoteUsed;
}
public Map<String, ResponseItem> getResults() {
return results;
}
/**
* Tells you how much quota you used in the request. This should only be used for debugging/logging purposed, and should never be relied upon for making
* actual decisions.
*/
public int getQuotaUsedDebugOnly() {
return quotaUsed;
}
}
public static final class ResponseItem {

View File

@@ -15,7 +15,10 @@ message ClientRequest {
bytes new_e164s = 3;
bytes discard_e164s = 4;
reserved /*bool has_more*/ 5;
// If true, the client has more pairs or e164s to send. If false or unset,
// this is the client's last request, and processing should commence.
// NOT NECESSARY FOR CDSI
// bool has_more = 5;
// If set, a token which allows rate limiting to discount the e164s in
// the request's prev_e164s, only counting new_e164s. If not set, then
@@ -53,6 +56,11 @@ message ClientResponse {
// e164s sent up in this request, only counting those in the next
// request's new_e164s.
bytes token = 3;
// On a successful response to a token_ack request, the number of permits
// that were deducted from the user's rate-limit in order to process the
// request
int32 debug_permits_used = 4;
}
message EnclaveLoad {
@@ -71,12 +79,13 @@ message EnclaveLoad {
}
message ClientHandshakeStart {
// Public key associated with this server's enclave
bytes pubkey = 1;
// Public key associated with this server's enclave. For use in test-only
// contexts where attestation is not available
bytes test_only_pubkey = 1;
// Remote-attestation evidence associated with the public key
bytes evidence = 2;
// Endorsements of remote-attestation evidence.
bytes endorsement = 3;
}
}