Search in sources :

Example 21 with PartyInfo

use of com.quorum.tessera.partyinfo.model.PartyInfo in project tessera by ConsenSys.

the class SyncPoller method run.

/**
 * Retrieves all of the outstanding parties and makes an attempt to make the resend request
 * asynchronously. If the request fails then the party is submitted back to the store for a later
 * attempt.
 */
@Override
public void run() {
    NodeInfo currentNodeInfo = discovery.getCurrent();
    final PartyInfo partyInfo = PartyInfoBuilder.create().withUri(currentNodeInfo.getUrl()).withRecipients(currentNodeInfo.getRecipientsAsMap()).build();
    final Set<Party> unseenParties = partyInfo.getParties().stream().filter(p -> !p.getUrl().equals(partyInfo.getUrl())).collect(Collectors.toSet());
    LOGGER.debug("Unseen parties {}", unseenParties);
    this.resendPartyStore.addUnseenParties(unseenParties);
    Optional<SyncableParty> nextPartyToSend = this.resendPartyStore.getNextParty();
    while (nextPartyToSend.isPresent()) {
        final SyncableParty requestDetails = nextPartyToSend.get();
        final String url = requestDetails.getParty().getUrl();
        final Runnable action = () -> {
            // perform a sendPartyInfo in order to ensure that the target tessera has the current
            // tessera as
            // a recipient
            boolean allSucceeded = updatePartyInfo(url);
            if (allSucceeded) {
                allSucceeded = this.transactionRequester.requestAllTransactionsFromNode(url);
            }
            if (!allSucceeded) {
                this.resendPartyStore.incrementFailedAttempt(requestDetails);
            }
        };
        this.executorService.submit(action);
        nextPartyToSend = this.resendPartyStore.getNextParty();
    }
}
Also used : PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Party(com.quorum.tessera.partyinfo.model.Party) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Discovery(com.quorum.tessera.discovery.Discovery) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Optional(java.util.Optional) P2pClient(com.quorum.tessera.partyinfo.P2pClient) PartyInfoBuilder(com.quorum.tessera.partyinfo.model.PartyInfoBuilder) ExecutorService(java.util.concurrent.ExecutorService) Party(com.quorum.tessera.partyinfo.model.Party) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo)

Example 22 with PartyInfo

use of com.quorum.tessera.partyinfo.model.PartyInfo in project tessera by ConsenSys.

the class PeerToPeerIT method validatePartyInfoContentsOnNodeA.

/*
  Assume that not of the tests should have managed to change the initial party info
   */
private void validatePartyInfoContentsOnNodeA() {
    Party someParty = partyHelper.getParties().filter(p -> !p.getAlias().equals("A")).findAny().get();
    ServerConfig serverContext = someParty.getConfig().getP2PServerConfig();
    Client client = clientFactory.buildFrom(serverContext);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().get();
    assertThat(response.getStatus()).isEqualTo(200);
    JsonObject result = response.readEntity(JsonObject.class);
    Map<String, String> actual = result.getJsonArray("keys").stream().map(o -> o.asJsonObject()).collect(Collectors.toMap(o -> o.getString("key"), o -> removeTrailingSlash(o.getString("url"))));
    EncryptorConfig encryptorConfig = partyHelper.getParties().findFirst().map(Party::getConfig).map(Config::getEncryptor).get();
    KeyEncryptor keyEncryptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);
    List<String> keyz = partyHelper.getParties().map(Party::getConfig).map(Config::getKeys).flatMap(k -> k.getKeyData().stream()).map(kd -> KeyDataUtil.unmarshal(kd, keyEncryptor)).map(ConfigKeyPair::getPublicKey).collect(Collectors.toList());
    List<String> urls = partyHelper.getParties().map(Party::getConfig).map(Config::getP2PServerConfig).map(ServerConfig::getServerAddress).map(s -> removeTrailingSlash(s)).collect(Collectors.toList());
    assertThat(actual).containsKeys(keyz.toArray(new String[0]));
    assertThat(actual).containsValues(urls.toArray(new String[0]));
}
Also used : Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Config(com.quorum.tessera.config.Config) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) JsonObject(jakarta.json.JsonObject) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Client(jakarta.ws.rs.client.Client)

Example 23 with PartyInfo

use of com.quorum.tessera.partyinfo.model.PartyInfo in project tessera by ConsenSys.

the class PeerToPeerIT method happyCase.

/*
   * Send a valid party info from B to A
   */
@Test
public void happyCase() {
    Party partyB = partyHelper.findByAlias(NodeAlias.B);
    ServerConfig serverContext = Optional.of(partyB.getConfig()).map(Config::getP2PServerConfig).get();
    Client client = clientFactory.buildFrom(serverContext);
    PublicKey partyBKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    String partyBServerAddress = partyB.getConfig().getP2PServerConfig().getServerAddress();
    Recipient recipient = Recipient.of(partyBKey, partyBServerAddress);
    PartyInfo partyInfo = new PartyInfo(partyBServerAddress, Collections.singleton(recipient), Collections.emptySet());
    PartyInfoParser partyInfoParser = PartyInfoParser.create();
    byte[] data = partyInfoParser.to(partyInfo);
    StreamingOutput output = out -> out.write(data);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Client(jakarta.ws.rs.client.Client) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Test(org.junit.Test)

Example 24 with PartyInfo

use of com.quorum.tessera.partyinfo.model.PartyInfo in project tessera by ConsenSys.

the class PeerToPeerIT method benevolentNodeBecomesPossessedAndTriesToSendInvalidUrlAndKeyCombo.

@Test
public void benevolentNodeBecomesPossessedAndTriesToSendInvalidUrlAndKeyCombo() throws Exception {
    Party partyB = partyHelper.findByAlias(NodeAlias.B);
    ServerConfig serverConfig = partyB.getConfig().getP2PServerConfig();
    PublicKey publicKey = Optional.of(partyB).map(Party::getPublicKey).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    Recipient itself = Recipient.of(publicKey, serverConfig.getServerUri().toString());
    String validKeyFromOtherNode = partyHelper.findByAlias(NodeAlias.C).getPublicKey();
    PublicKey validButIncorrectKey = Optional.of(validKeyFromOtherNode).map(Base64.getDecoder()::decode).map(PublicKey::from).get();
    String workingUrlFromSomeOtherNode = partyHelper.findByAlias(NodeAlias.D).getConfig().getP2PServerConfig().getServerAddress();
    Recipient badRecipient = Recipient.of(validButIncorrectKey, workingUrlFromSomeOtherNode);
    Set<Recipient> recipients = Stream.of(itself, badRecipient).collect(Collectors.toSet());
    assertThat(recipients).containsExactlyInAnyOrder(itself, badRecipient);
    PartyInfo partyInfo = new PartyInfo(serverConfig.getServerUri().toString(), recipients, Collections.emptySet());
    Client client = new ClientFactory().buildFrom(serverConfig);
    PartyInfoParser partyInfoParser = PartyInfoParser.create();
    byte[] data = partyInfoParser.to(partyInfo);
    StreamingOutput output = out -> out.write(data);
    Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().post(Entity.entity(output, MediaType.APPLICATION_OCTET_STREAM));
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) PublicKey(com.quorum.tessera.encryption.PublicKey) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Recipient(com.quorum.tessera.partyinfo.model.Recipient) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)24 Test (org.junit.Test)18 Recipient (com.quorum.tessera.partyinfo.model.Recipient)16 PublicKey (com.quorum.tessera.encryption.PublicKey)14 Entity (jakarta.ws.rs.client.Entity)13 Response (jakarta.ws.rs.core.Response)13 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)11 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)9 Collectors (java.util.stream.Collectors)9 Client (jakarta.ws.rs.client.Client)8 MediaType (jakarta.ws.rs.core.MediaType)8 java.util (java.util)8 Party (com.quorum.tessera.partyinfo.model.Party)7 JsonObject (jakarta.json.JsonObject)7 Config (com.quorum.tessera.config.Config)6 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)6 ServerConfig (com.quorum.tessera.config.ServerConfig)6 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)6 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)6 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)6