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

Separate P2P and Resend clients #982

Merged
merged 26 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
45d5c5a
Allow partyinfo to update existing key with new url. This was the beh…
namtruong Dec 31, 2019
97bc8b6
Update unit test for partyinfo service
namtruong Dec 31, 2019
cde9377
Merge remote-tracking branch 'origin/master'
namtruong Dec 31, 2019
fd55e8a
Make partyinfo requests asynchronous
namtruong Jan 2, 2020
a59dfb0
Fix race condition in unit test
namtruong Jan 3, 2020
878d23c
Fix race condition in unit test
namtruong Jan 6, 2020
9c4a152
Switch to using an executor and fix unit test
namtruong Jan 6, 2020
348c1c6
Merge remote-tracking branch 'origin/master'
namtruong Jan 7, 2020
233fe42
Switch to using newCachedThreadPool for more flexibility in terms of …
namtruong Jan 7, 2020
cfe944b
make partyinfo polling interval configurable
namtruong Jan 13, 2020
9b1c315
set p2p client connectTimeout and readTimeout based on polling interval
namtruong Jan 13, 2020
7f99179
remove unused imports
namtruong Jan 13, 2020
5ad4e43
set default value to 5000 milliseconds
namtruong Jan 13, 2020
82ea6e6
Merge remote-tracking branch 'origin/master'
namtruong Jan 14, 2020
6b4e9c1
Merge remote-tracking branch 'origin/master'
namtruong Jan 17, 2020
444df62
enforce whitelist filtering if peer auto-discovery is being disabled
namtruong Jan 17, 2020
9377afb
Merge remote-tracking branch 'origin/master'
namtruong Jan 17, 2020
19b0d12
Merge remote-tracking branch 'origin/master'
namtruong Jan 20, 2020
802e7e2
Merge remote-tracking branch 'origin/master'
namtruong Jan 22, 2020
d699ae7
Merge remote-tracking branch 'origin/master'
namtruong Jan 22, 2020
d383e5d
Separate p2pclient and resend client. Add factory and unit tests
namtruong Jan 22, 2020
f96969c
Add RestResendClient, Factory and unit test
namtruong Jan 22, 2020
233d082
Merge branches 'master' and 'separate-p2p-and-resend-client' of https…
prd-fox Jan 23, 2020
8f7a488
Add finals and Javadocs
prd-fox Jan 24, 2020
c13fc44
Add a configurable timeout for "resend"
prd-fox Jan 24, 2020
0e1fe00
Merge branch 'master' of https://github.com/jpmorganchase/tessera int…
prd-fox Jan 24, 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 @@ -11,15 +11,14 @@ public class IntervalPropertyHelper {

private final Map<String, String> properties;

public IntervalPropertyHelper(Map<String, String> properties) {
public IntervalPropertyHelper(final Map<String, String> properties) {
this.properties = properties;
}

public long partyInfoInterval() {
try {
return Long.parseLong(properties.getOrDefault("partyInfoInterval", "5000"));
}
catch (NumberFormatException ex) {
} catch (NumberFormatException ex) {
LOGGER.warn("Not able to parse configured property. Will use default value instead");
return 5000L;
}
Expand All @@ -28,8 +27,7 @@ public long partyInfoInterval() {
public long enclaveKeySyncInterval() {
try {
return Long.parseLong(properties.getOrDefault("enclaveKeySyncInterval", "2000"));
}
catch (NumberFormatException ex) {
} catch (NumberFormatException ex) {
LOGGER.warn("Not able to parse configured property. Will use default value instead");
return 2000L;
}
Expand All @@ -38,10 +36,18 @@ public long enclaveKeySyncInterval() {
public long syncInterval() {
try {
return Long.parseLong(properties.getOrDefault("syncInterval", "60000"));
}
catch (NumberFormatException ex) {
} catch (NumberFormatException ex) {
LOGGER.warn("Not able to parse configured property. Will use default value instead");
return 60000L;
}
}

public String resendWaitTime() {
try {
return Long.toString(Long.parseLong(properties.getOrDefault("resendWaitTime", "7200000"))); // 2 hours
} catch (NumberFormatException ex) {
LOGGER.warn("Not able to parse configured property. Will use default value instead");
return "7200000";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
package com.quorum.tessera.config.util;

import org.assertj.core.api.Assertions;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

public class IntervalPropertyHelperTest {

@Test
public void testDefaultValues() {
IntervalPropertyHelper util = new IntervalPropertyHelper(Collections.emptyMap());
Assertions.assertThat(util.partyInfoInterval()).isEqualTo(5000);
Assertions.assertThat(util.enclaveKeySyncInterval()).isEqualTo(2000);
Assertions.assertThat(util.syncInterval()).isEqualTo(60000);
final IntervalPropertyHelper util = new IntervalPropertyHelper(Collections.emptyMap());

assertThat(util.partyInfoInterval()).isEqualTo(5000);
assertThat(util.enclaveKeySyncInterval()).isEqualTo(2000);
assertThat(util.syncInterval()).isEqualTo(60000);
assertThat(util.resendWaitTime()).isEqualTo("7200000");
}

@Test
public void getValues() {
Map<String, String> props = new HashMap<>();
final Map<String, String> props = new HashMap<>();
props.put("partyInfoInterval", "2000");
props.put("enclaveKeySyncInterval", "3000");
props.put("syncInterval", "4000");
IntervalPropertyHelper util = new IntervalPropertyHelper(props);
Assertions.assertThat(util.partyInfoInterval()).isEqualTo(2000);
Assertions.assertThat(util.enclaveKeySyncInterval()).isEqualTo(3000);
Assertions.assertThat(util.syncInterval()).isEqualTo(4000);
props.put("resendWaitTime", "4000");

final IntervalPropertyHelper util = new IntervalPropertyHelper(props);

assertThat(util.partyInfoInterval()).isEqualTo(2000);
assertThat(util.enclaveKeySyncInterval()).isEqualTo(3000);
assertThat(util.syncInterval()).isEqualTo(4000);
assertThat(util.resendWaitTime()).isEqualTo("4000");
}

@Test
public void testExceptions() {
Map<String, String> props = new HashMap<>();
final Map<String, String> props = new HashMap<>();
props.put("partyInfoInterval", null);
props.put("enclaveKeySyncInterval", "abc");
props.put("syncInterval", "4000L");
IntervalPropertyHelper util = new IntervalPropertyHelper(props);
Assertions.assertThat(util.partyInfoInterval()).isEqualTo(5000);
Assertions.assertThat(util.enclaveKeySyncInterval()).isEqualTo(2000);
Assertions.assertThat(util.syncInterval()).isEqualTo(60000);
}
props.put("resendWaitTime", "4000L");

final IntervalPropertyHelper util = new IntervalPropertyHelper(props);

assertThat(util.partyInfoInterval()).isEqualTo(5000);
assertThat(util.enclaveKeySyncInterval()).isEqualTo(2000);
assertThat(util.syncInterval()).isEqualTo(60000);
assertThat(util.resendWaitTime()).isEqualTo("7200000");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.quorum.tessera.p2p;

import com.quorum.tessera.partyinfo.P2pClient;
import com.quorum.tessera.partyinfo.ResendRequest;
import java.util.Objects;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
Expand Down Expand Up @@ -50,16 +49,4 @@ public boolean sendPartyInfo(String targetUrl, byte[] data) {
return Objects.nonNull(response.readEntity(byte[].class));
}
}

@Override
public boolean makeResendRequest(String targetUrl, ResendRequest request) {
try (Response response =
client.target(targetUrl)
.path("/resend")
.request()
.post(Entity.entity(request, MediaType.APPLICATION_JSON))) {

return Response.Status.OK.getStatusCode() == response.getStatus();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.quorum.tessera.p2p;

import com.quorum.tessera.partyinfo.ResendRequest;
import com.quorum.tessera.sync.ResendClient;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Objects;

public class RestResendClient implements ResendClient {

private final Client client;

public RestResendClient(final Client client) {
this.client = Objects.requireNonNull(client);
}

@Override
public boolean makeResendRequest(final String targetUrl, final ResendRequest request) {
final Entity<ResendRequest> outboundEntity = Entity.entity(request, MediaType.APPLICATION_JSON);

try (Response response = client.target(targetUrl).path("/resend").request().post(outboundEntity)) {
return Response.Status.OK.getStatusCode() == response.getStatus();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.quorum.tessera.p2p;

import com.quorum.tessera.config.CommunicationType;
import com.quorum.tessera.config.Config;
import com.quorum.tessera.config.util.IntervalPropertyHelper;
import com.quorum.tessera.jaxrs.client.ClientFactory;
import com.quorum.tessera.ssl.context.ClientSSLContextFactory;
import com.quorum.tessera.ssl.context.SSLContextFactory;
import com.quorum.tessera.sync.ResendClient;
import com.quorum.tessera.sync.ResendClientFactory;

import javax.ws.rs.client.Client;

public class RestResendClientFactory implements ResendClientFactory {

public ResendClient create(final Config config) {
final String resendWaitTime =
new IntervalPropertyHelper(config.getP2PServerConfig().getProperties()).resendWaitTime();

final SSLContextFactory clientSSLContextFactory = ClientSSLContextFactory.create();

final ClientFactory clientFactory = new ClientFactory(clientSSLContextFactory);
final Client client = clientFactory.buildFrom(config.getP2PServerConfig());

client.property("jersey.config.client.readTimeout", resendWaitTime);
return new RestResendClient(client);
}

@Override
public CommunicationType communicationType() {
return CommunicationType.REST;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.quorum.tessera.p2p.RestResendClientFactory
Loading