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");
}
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;
}
}
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();
}
}
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");
}
Aggregations