Search in sources :

Example 21 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class PartyInfoResourceTest method partyInfoGet.

@Test
public void partyInfoGet() {
    final String partyInfoJson = "{\"url\":\"http://localhost:9001/\",\"peers\":[{\"url\":\"http://localhost:9006/\"},{\"url\":\"http://localhost:9005/\"}],\"keys\":[{\"key\":\"BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=\",\"url\":\"http://localhost:9001/\"},{\"key\":\"QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=\",\"url\":\"http://localhost:9002/\"}]}";
    NodeInfo partyInfo = NodeInfo.Builder.create().withUrl("http://localhost:9001/").withRecipients(List.of(com.quorum.tessera.partyinfo.node.Recipient.of(PublicKey.from(Base64.getDecoder().decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")), "http://localhost:9001/"), com.quorum.tessera.partyinfo.node.Recipient.of(PublicKey.from(Base64.getDecoder().decode("QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=")), "http://localhost:9002/"))).build();
    when(discovery.getCurrent()).thenReturn(partyInfo);
    when(partyStore.getParties()).thenReturn(Set.of(URI.create("http://localhost:9006/"), URI.create("http://localhost:9005/")));
    final Response response = partyInfoResource.getPartyInfo();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
    final String output = response.getEntity().toString();
    final JsonReader expected = Json.createReader(new StringReader(partyInfoJson));
    final JsonReader actual = Json.createReader(new StringReader(output));
    JsonObject expectedJsonObject = expected.readObject();
    JsonObject actualJsonObject = actual.readObject();
    assertThat(actualJsonObject.getJsonArray("keys")).containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("keys"));
    assertThat(actualJsonObject.getJsonArray("peers")).containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("peers"));
    assertThat(actualJsonObject.getString("url")).isEqualTo(expectedJsonObject.getString("url"));
    verify(discovery).getCurrent();
}
Also used : Response(jakarta.ws.rs.core.Response) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) StringReader(java.io.StringReader) JsonReader(jakarta.json.JsonReader) JsonObject(jakarta.json.JsonObject) Test(org.junit.Test)

Example 22 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class PartyInfoBroadcasterTest method testWhenURLIsOwn.

@Test
public void testWhenURLIsOwn() {
    final NodeInfo partyInfo = NodeInfo.Builder.create().withUrl(OWN_URL).build();
    when(partyStore.getParties()).thenReturn(Set.of(URI.create(OWN_URL)));
    when(discovery.getCurrent()).thenReturn(partyInfo);
    when(partyInfoParser.to(any(PartyInfo.class))).thenReturn(DATA);
    when(p2pClient.sendPartyInfo(OWN_URL, DATA)).thenReturn(true);
    partyInfoBroadcaster.run();
    verify(partyStore).loadFromConfigIfEmpty();
    verify(partyStore).getParties();
    verify(partyInfoParser).to(any(PartyInfo.class));
    verify(discovery).getCurrent();
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Test(org.junit.Test)

Example 23 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class PartyInfoBroadcasterTest method run.

@Test
public void run() {
    final NodeInfo partyInfo = NodeInfo.Builder.create().withUrl(OWN_URL).build();
    when(partyStore.getParties()).thenReturn(Set.of(URI.create(OWN_URL), URI.create(TARGET_URL)));
    when(discovery.getCurrent()).thenReturn(partyInfo);
    when(p2pClient.sendPartyInfo(TARGET_URL, DATA)).thenReturn(true);
    partyInfoBroadcaster.run();
    verify(partyStore).loadFromConfigIfEmpty();
    verify(partyStore).getParties();
    verify(discovery).getCurrent();
    verify(partyInfoParser).to(any(PartyInfo.class));
    verify(p2pClient).sendPartyInfo(TARGET_URL, DATA);
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Test(org.junit.Test)

Example 24 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class PartyInfoResource method getPartyInfo.

@Operation(summary = "/partyinfo", description = "fetch network/peer information")
@ApiResponse(responseCode = "200", description = "server's partyinfo data", content = @Content(schema = @Schema(implementation = GetPartyInfoResponse.class)))
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPartyInfo() {
    final NodeInfo current = this.discovery.getCurrent();
    final JsonArrayBuilder peersBuilder = Json.createArrayBuilder();
    partyStore.getParties().stream().map(party -> Json.createObjectBuilder().add("url", party.toString()).build()).forEach(peersBuilder::add);
    final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder();
    current.getRecipients().stream().map(recipient -> Json.createObjectBuilder().add("key", recipient.getKey().encodeToBase64()).add("url", recipient.getUrl()).build()).forEach(recipientBuilder::add);
    final String output = Json.createObjectBuilder().add("url", current.getUrl()).add("peers", peersBuilder.build()).add("keys", recipientBuilder.build()).build().toString();
    LOGGER.debug("Sending json {} from {}", output, current);
    return Response.status(Response.Status.OK).entity(output).build();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) NodeInfoUtil(com.quorum.tessera.partyinfo.model.NodeInfoUtil) LoggerFactory(org.slf4j.LoggerFactory) Party(com.quorum.tessera.partyinfo.model.Party) GetPartyInfoResponse(com.quorum.tessera.p2p.model.GetPartyInfoResponse) Content(io.swagger.v3.oas.annotations.media.Content) Discovery(com.quorum.tessera.discovery.Discovery) Operation(io.swagger.v3.oas.annotations.Operation) Response(jakarta.ws.rs.core.Response) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) Constants(com.quorum.tessera.shared.Constants) Schema(io.swagger.v3.oas.annotations.media.Schema) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) Client(jakarta.ws.rs.client.Client) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) com.quorum.tessera.enclave(com.quorum.tessera.enclave) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) NodeUri(com.quorum.tessera.discovery.NodeUri) jakarta.ws.rs(jakarta.ws.rs) Collectors(java.util.stream.Collectors) PartyStore(com.quorum.tessera.p2p.partyinfo.PartyStore) Json(jakarta.json.Json) Entity(jakarta.ws.rs.client.Entity) Parameter(io.swagger.v3.oas.annotations.Parameter) ArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) MediaType(jakarta.ws.rs.core.MediaType) Tag(io.swagger.v3.oas.annotations.tags.Tag) Recipient(com.quorum.tessera.partyinfo.model.Recipient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 25 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.

the class SyncPollerTest method localUrlIsExcludedFromPoll.

@Test
public void localUrlIsExcludedFromPoll() {
    final String targetUrl = "localurl.com";
    final String syncableUrl = "syncable.com";
    final com.quorum.tessera.partyinfo.node.Recipient localKey = com.quorum.tessera.partyinfo.node.Recipient.of(mock(PublicKey.class), targetUrl);
    final com.quorum.tessera.partyinfo.node.Recipient anotherKey = com.quorum.tessera.partyinfo.node.Recipient.of(mock(PublicKey.class), syncableUrl);
    final Party syncableParty = new Party(syncableUrl);
    final Set<Recipient> recipients = Set.of(localKey, anotherKey);
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("localurl.com").withRecipients(recipients).build();
    // partyStore.store(URI.create(syncableUrl));
    when(partyInfoService.getCurrent()).thenReturn(nodeInfo);
    doReturn(Optional.empty()).when(resendPartyStore).getNextParty();
    syncPoller.run();
    verify(resendPartyStore, times(1)).addUnseenParties(Set.of(syncableParty));
    verify(resendPartyStore, times(1)).getNextParty();
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Aggregations

NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)49 Test (org.junit.Test)37 PublicKey (com.quorum.tessera.encryption.PublicKey)31 Recipient (com.quorum.tessera.partyinfo.node.Recipient)19 ActiveNode (com.quorum.tessera.discovery.ActiveNode)12 Response (jakarta.ws.rs.core.Response)11 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)10 NodeUri (com.quorum.tessera.discovery.NodeUri)8 URI (java.net.URI)8 Collectors (java.util.stream.Collectors)8 RuntimeContext (com.quorum.tessera.context.RuntimeContext)7 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)7 Set (java.util.Set)7 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)6 Logger (org.slf4j.Logger)6 Discovery (com.quorum.tessera.discovery.Discovery)5 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)5 Enclave (com.quorum.tessera.enclave.Enclave)5 Entity (jakarta.ws.rs.client.Entity)5