Search in sources :

Example 46 with NodeInfo

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

the class PartyInfoBroadcaster method run.

/**
 * Iterates over all known parties and contacts them for the current state of their known node
 * discovery list
 *
 * <p>For Tessera 0.9 backwards, after contacting the known parties, this poller then updates this
 * nodes list of data with any new information collected.
 *
 * <p>This behaviour is now deprecated since the /partyinfo API call now has been made more strict
 * with node validation to prevent exploiting the API to attack the Tessera network.
 *
 * <p>This call is merely to let its parties know about this node existence, any recipients that
 * want to be added to this node's PartyInfo will need to make their own partyinfo call and
 * validation
 */
@Override
public void run() {
    LOGGER.info("Started PartyInfo polling round");
    partyStore.loadFromConfigIfEmpty();
    final NodeInfo nodeInfo = discovery.getCurrent();
    final NodeUri ourUrl = NodeUri.create(nodeInfo.getUrl());
    final PartyInfo partyInfo = PartyInfoBuilder.create().withUri(nodeInfo.getUrl()).withRecipients(nodeInfo.getRecipientsAsMap()).build();
    final byte[] encodedPartyInfo = partyInfoParser.to(partyInfo);
    LOGGER.debug("Contacting following peers with PartyInfo: {}", partyInfo.getParties());
    LOGGER.debug("Sending party info {}", nodeInfo);
    partyStore.getParties().stream().map(NodeUri::create).filter(url -> !ourUrl.equals(url)).forEach(url -> pollSingleParty(url.asString(), encodedPartyInfo));
    LOGGER.info("Finished PartyInfo polling round");
}
Also used : Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) NodeUri(com.quorum.tessera.discovery.NodeUri) 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) ProcessingException(jakarta.ws.rs.ProcessingException) Optional(java.util.Optional) P2pClient(com.quorum.tessera.partyinfo.P2pClient) URI(java.net.URI) PartyInfoBuilder(com.quorum.tessera.partyinfo.model.PartyInfoBuilder) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) NodeUri(com.quorum.tessera.discovery.NodeUri) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo)

Example 47 with NodeInfo

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

the class SyncPoller method updatePartyInfo.

private boolean updatePartyInfo(String url) {
    try {
        final NodeInfo nodeInfo = discovery.getCurrent();
        final PartyInfo partyInfo = PartyInfoBuilder.create().withUri(nodeInfo.getUrl()).withRecipients(nodeInfo.getRecipientsAsMap()).build();
        LOGGER.debug("Sending node info {} to {}", nodeInfo, url);
        final byte[] encodedPartyInfo = partyInfoParser.to(partyInfo);
        // we deliberately discard the response as we do not want to fully duplicate the
        // PartyInfoPoller
        boolean outcome = p2pClient.sendPartyInfo(url, encodedPartyInfo);
        LOGGER.debug("Sent node info {} to {}", nodeInfo, url);
        return outcome;
    } catch (final Exception ex) {
        LOGGER.warn("Failed to connect to node {} for partyinfo, due to {}", url, ex.getMessage());
        LOGGER.debug(null, ex);
        return false;
    }
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo)

Example 48 with NodeInfo

use of com.quorum.tessera.partyinfo.node.NodeInfo 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 49 with NodeInfo

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

the class PartyInfoTest method fromNodeInfo.

@Test
public void fromNodeInfo() {
    com.quorum.tessera.partyinfo.node.Recipient recipient = mock(com.quorum.tessera.partyinfo.node.Recipient.class);
    when(recipient.getUrl()).thenReturn("http://somedomain.com/");
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("url").withRecipients(List.of(recipient)).build();
    PartyInfo partyInfo = PartyInfo.from(nodeInfo);
    assertThat(partyInfo.getUrl()).isEqualTo("url");
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) 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