Search in sources :

Example 1 with PortUtil

use of config.PortUtil in project tessera by ConsenSys.

the class SendWithRemoteEnclaveReconnectIT method beforeTest.

@Before
public void beforeTest() throws IOException {
    EncryptorConfig encryptorConfig = new EncryptorConfig() {

        {
            setType(EncryptorType.NACL);
        }
    };
    ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EnclaveType.REMOTE).with(encryptorConfig.getType()).with(ClientMode.TESSERA).buildAndStoreContext();
    final PortUtil portGenerator = new PortUtil(50100);
    final String serverUriTemplate = "http://localhost:%d";
    KeyEncryptorFactory.newFactory().create(encryptorConfig);
    final Config nodeConfig = new Config();
    nodeConfig.setEncryptor(encryptorConfig);
    JdbcConfig jdbcConfig = new JdbcConfig();
    jdbcConfig.setUrl("jdbc:h2:mem:junit");
    jdbcConfig.setUsername("sa");
    jdbcConfig.setPassword("");
    jdbcConfig.setAutoCreateTables(true);
    nodeConfig.setJdbcConfig(jdbcConfig);
    ServerConfig p2pServerConfig = new ServerConfig();
    p2pServerConfig.setApp(AppType.P2P);
    p2pServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    p2pServerConfig.setCommunicationType(CommunicationType.REST);
    final ServerConfig q2tServerConfig = new ServerConfig();
    q2tServerConfig.setApp(AppType.Q2T);
    q2tServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    q2tServerConfig.setCommunicationType(CommunicationType.REST);
    final Config enclaveConfig = new Config();
    enclaveConfig.setEncryptor(nodeConfig.getEncryptor());
    final ServerConfig enclaveServerConfig = new ServerConfig();
    enclaveServerConfig.setApp(AppType.ENCLAVE);
    enclaveServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    enclaveServerConfig.setCommunicationType(CommunicationType.REST);
    nodeConfig.setServerConfigs(Arrays.asList(p2pServerConfig, q2tServerConfig, enclaveServerConfig));
    KeyData keyPair = new KeyData();
    keyPair.setPublicKey("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
    keyPair.setPrivateKey("yAWAJjwPqUtNVlqGjSrBmr1/iIkghuOh1803Yzx9jLM=");
    enclaveConfig.setKeys(new KeyConfiguration());
    enclaveConfig.getKeys().setKeyData(Arrays.asList(keyPair));
    nodeConfig.setPeers(Arrays.asList(new Peer(p2pServerConfig.getServerAddress())));
    enclaveConfig.setServerConfigs(Arrays.asList(enclaveServerConfig));
    Path configPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
    configPath.toFile().deleteOnExit();
    Path enclaveConfigPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
    enclaveConfigPath.toFile().deleteOnExit();
    try (OutputStream out = Files.newOutputStream(configPath)) {
        JaxbUtil.marshalWithNoValidation(nodeConfig, out);
        out.flush();
    }
    JaxbUtil.marshalWithNoValidation(enclaveConfig, System.out);
    try (OutputStream out = Files.newOutputStream(enclaveConfigPath)) {
        JaxbUtil.marshalWithNoValidation(enclaveConfig, out);
        out.flush();
    }
    ConfigDescriptor configDescriptor = new ConfigDescriptor(NodeAlias.A, configPath, nodeConfig, enclaveConfig, enclaveConfigPath);
    String key = configDescriptor.getKey().getPublicKey();
    URL file = Utils.toUrl(configDescriptor.getPath());
    String alias = configDescriptor.getAlias().name();
    this.party = new Party(key, file, alias);
    nodeExecManager = new NodeExecManager(configDescriptor);
    enclaveExecManager = new EnclaveExecManager(configDescriptor);
    enclaveExecManager.start();
    nodeExecManager.start();
    client = party.getRestClient();
}
Also used : Path(java.nio.file.Path) PortUtil(config.PortUtil) OutputStream(java.io.OutputStream) NodeExecManager(exec.NodeExecManager) EnclaveExecManager(exec.EnclaveExecManager) URL(java.net.URL) Party(com.quorum.tessera.test.Party) ConfigDescriptor(config.ConfigDescriptor) Before(org.junit.Before)

Aggregations

Party (com.quorum.tessera.test.Party)1 ConfigDescriptor (config.ConfigDescriptor)1 PortUtil (config.PortUtil)1 EnclaveExecManager (exec.EnclaveExecManager)1 NodeExecManager (exec.NodeExecManager)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Before (org.junit.Before)1