use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.
the class Main method main.
public static void main(final String... args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
LOGGER.debug("args [{}]", String.join(",", args));
try {
PicoCliDelegate picoCliDelegate = new PicoCliDelegate();
LOGGER.debug("Execute PicoCliDelegate with args [{}]", String.join(",", args));
final CliResult cliResult = picoCliDelegate.execute(args);
LOGGER.debug("Executed PicoCliDelegate with args [{}].", String.join(",", args));
if (cliResult.isSuppressStartup()) {
System.exit(0);
}
if (cliResult.getStatus() != 0) {
System.exit(cliResult.getStatus());
}
final Config config = cliResult.getConfig().orElseThrow(() -> new NoSuchElementException("No config found. Tessera will not run."));
// Start legacy spring profile stuff
final String springProfileWarning = "Warn: Spring profiles will not be supported in future. To start in recover mode use 'tessera recover'";
if (System.getProperties().containsKey("spring.profiles.active")) {
System.out.println(springProfileWarning);
config.setRecoveryMode(System.getProperty("spring.profiles.active").contains("enable-sync-poller"));
} else if (System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {
System.out.println(springProfileWarning);
config.setRecoveryMode(System.getenv("SPRING_PROFILES_ACTIVE").contains("enable-sync-poller"));
}
// end spring profile stuff
LOGGER.debug("Storing config {}", config);
ConfigFactory.create().store(config);
LOGGER.debug("Stored config {}", config);
LOGGER.debug("Creating enclave");
final Enclave enclave = Enclave.create();
LOGGER.debug("Created enclave {}", enclave);
LOGGER.debug("Creating RuntimeContext");
final RuntimeContext runtimeContext = RuntimeContext.getInstance();
LOGGER.debug("Created RuntimeContext {}", runtimeContext);
LOGGER.debug("Creating Discovery");
Discovery discovery = Discovery.create();
discovery.onCreate();
LOGGER.debug("Created Discovery {}", discovery);
if (runtimeContext.isMultiplePrivateStates()) {
LOGGER.debug("Creating ResidentGroupHandler");
ResidentGroupHandler residentGroupHandler = ResidentGroupHandler.create();
residentGroupHandler.onCreate(config);
LOGGER.debug("Created ResidentGroupHandler {}", residentGroupHandler);
}
LOGGER.debug("Creating EncodedPayloadManager");
EncodedPayloadManager.create();
LOGGER.debug("Created EncodedPayloadManager");
LOGGER.debug("Creating BatchResendManager");
BatchResendManager.create();
LOGGER.debug("Created BatchResendManager");
LOGGER.debug("Creating txn manager");
TransactionManager transactionManager = TransactionManager.create();
LOGGER.debug("Created txn manager");
LOGGER.debug("Validating if transaction table exists");
if (!transactionManager.upcheck()) {
throw new RuntimeException("The database has not been setup correctly. Please ensure transaction tables " + "are present and correct");
}
LOGGER.debug("Creating ScheduledServiceFactory");
ScheduledServiceFactory scheduledServiceFactory = ScheduledServiceFactory.fromConfig(config);
scheduledServiceFactory.build();
LOGGER.debug("Created ScheduledServiceFactory");
LOGGER.debug("Creating Launcher");
final List<TesseraServer> tesseraServers = Launcher.create(runtimeContext.isRecoveryMode()).launchServer(config);
LOGGER.debug("Created Launcher");
if (config.getOutputServerURIPath() != null) {
ServerURIFileWriter.writeURIFile(config.getOutputServerURIPath(), tesseraServers);
}
} catch (final ConstraintViolationException ex) {
for (final ConstraintViolation<?> violation : ex.getConstraintViolations()) {
System.err.println("ERROR: Config validation issue: " + violation.getPropertyPath() + " " + violation.getMessage());
}
System.exit(1);
} catch (final ConfigException ex) {
LOGGER.debug("", ex);
final Throwable cause = ExceptionUtils.getRootCause(ex);
if (JsonException.class.isInstance(cause)) {
System.err.println("ERROR: Invalid json, cause is " + cause.getMessage());
} else {
System.err.println("ERROR: Configuration exception, cause is " + Objects.toString(cause));
}
System.exit(3);
} catch (final CliException ex) {
LOGGER.debug("", ex);
System.err.println("ERROR: CLI exception, cause is " + ex.getMessage());
System.exit(4);
} catch (final ServiceConfigurationError ex) {
LOGGER.debug("", ex);
Optional<Throwable> e = Optional.of(ex);
e.map(Throwable::getMessage).ifPresent(System.err::println);
// get root cause
while (e.map(Throwable::getCause).isPresent()) {
e = e.map(Throwable::getCause);
}
e.map(Throwable::toString).ifPresent(System.err::println);
System.exit(5);
} catch (final Throwable ex) {
LOGGER.debug(null, ex);
if (Arrays.asList(args).contains("--debug")) {
ex.printStackTrace();
} else {
if (Optional.ofNullable(ex.getMessage()).isPresent()) {
System.err.println("ERROR: Cause is " + ex.getMessage());
} else {
System.err.println("ERROR: In class " + ex.getClass().getSimpleName());
}
}
System.exit(2);
}
}
use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.
the class PayloadPublisherProviderTest method provider.
@Test
public void provider() {
ConfigFactory configFactory = mock(ConfigFactory.class);
Config config = mock(Config.class);
ServerConfig serverConfig = mock(ServerConfig.class);
when(config.getP2PServerConfig()).thenReturn(serverConfig);
when(configFactory.getConfig()).thenReturn(config);
try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class);
var discoveryMockedStatic = mockStatic(Discovery.class)) {
configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
discoveryMockedStatic.when(Discovery::create).thenReturn(mock(Discovery.class));
PayloadPublisher payloadPublisher = PayloadPublisherProvider.provider();
assertThat(payloadPublisher).isNotNull();
configFactoryMockedStatic.verify(ConfigFactory::create);
configFactoryMockedStatic.verifyNoMoreInteractions();
discoveryMockedStatic.verify(Discovery::create);
discoveryMockedStatic.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.
the class P2PRestApp method getSingletons.
@Override
public Set<Object> getSingletons() {
RuntimeContext runtimeContext = RuntimeContext.getInstance();
List<URI> peers = runtimeContext.getPeers();
LOGGER.debug("Found configured peers {}", peers);
peers.stream().map(NodeUri::create).map(NodeUri::asURI).peek(u -> LOGGER.debug("Adding {} to party store", u)).forEach(partyStore::store);
final PartyInfoResource partyInfoResource = new PartyInfoResource(discovery, partyInfoParser, runtimeContext.getP2pClient(), enclave, runtimeContext.isRemoteKeyValidation());
final IPWhitelistFilter iPWhitelistFilter = new IPWhitelistFilter();
final TransactionResource transactionResource = new TransactionResource(transactionManager, batchResendManager, legacyResendManager);
final UpCheckResource upCheckResource = new UpCheckResource();
final PrivacyGroupResource privacyGroupResource = new PrivacyGroupResource(privacyGroupManager);
if (runtimeContext.isRecoveryMode()) {
final RecoveryResource recoveryResource = new RecoveryResource(transactionManager, batchResendManager);
return Set.of(partyInfoResource, iPWhitelistFilter, recoveryResource, upCheckResource);
}
return Set.of(partyInfoResource, iPWhitelistFilter, transactionResource, privacyGroupResource, upCheckResource);
}
use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.
the class P2PRestAppTest method setUp.
@Before
public void setUp() {
runtimeContext = mock(RuntimeContext.class);
enclave = mock(Enclave.class);
discovery = mock(Discovery.class);
partyStore = mock(PartyStore.class);
transactionManager = mock(TransactionManager.class);
batchResendManager = mock(BatchResendManager.class);
legacyResendManager = mock(LegacyResendManager.class);
privacyGroupManager = mock(PrivacyGroupManager.class);
p2PRestApp = new P2PRestApp(discovery, enclave, partyStore, transactionManager, batchResendManager, legacyResendManager, privacyGroupManager);
Client client = mock(Client.class);
when(runtimeContext.getP2pClient()).thenReturn(client);
when(runtimeContext.isRemoteKeyValidation()).thenReturn(true);
when(runtimeContext.getPeers()).thenReturn(List.of(peerUri));
}
use of com.quorum.tessera.discovery.Discovery 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");
}
Aggregations