Search in sources :

Example 1 with com.icodici.universa.node2.network

use of com.icodici.universa.node2.network in project universa by UniversaBlockchain.

the class CLIMain method getClientNetwork.

public static synchronized ClientNetwork getClientNetwork() throws IOException {
    if (clientNetwork == null) {
        reporter.verbose("ClientNetwork not exist, create one");
        BasicHttpClientSession s = null;
        reporter.verbose("ClientNetwork nodeUrl: " + nodeUrl);
        if (nodeUrl != null) {
            clientNetwork = new ClientNetwork(nodeUrl, null, true);
        } else {
            clientNetwork = new ClientNetwork(null, true);
        }
        if (clientNetwork.client == null)
            throw new IOException("failed to connect to to the universa network");
        s = getSession(clientNetwork.getNodeNumber());
        reporter.verbose("Session for " + clientNetwork.getNodeNumber() + " is exist: " + (s != null));
        if (s != null)
            reporter.verbose("Session id is " + s.getSessionId());
        clientNetwork.start(s);
    }
    if (clientNetwork != null)
        session = clientNetwork.getSession();
    return clientNetwork;
}
Also used : BasicHttpClientSession(com.icodici.universa.node2.network.BasicHttpClientSession)

Example 2 with com.icodici.universa.node2.network

use of com.icodici.universa.node2.network in project universa by UniversaBlockchain.

the class Main method startNode.

private void startNode() throws SQLException, IOException {
    config.setConsensusConfigUpdater((config, n) -> {
        // Until we fix the announcer
        int negative = (int) Math.ceil(n * 0.11);
        if (negative < 1)
            negative = 1;
        int positive = (int) Math.floor(n * 0.90);
        if (negative + positive == n)
            negative += 1;
        int resyncBreak = (int) Math.ceil(n * 0.2);
        if (resyncBreak < 1)
            resyncBreak = 1;
        if (resyncBreak + positive == n)
            resyncBreak += 1;
        log(myInfo.getNumber() + ": Network consensus is set to (negative/positive/resyncBreak): " + negative + " / " + positive + " / " + resyncBreak);
        config.setPositiveConsensus(positive);
        config.setNegativeConsensus(negative);
        config.setResyncBreakConsensus(resyncBreak);
    });
    network = new NetworkV2(netConfig, myInfo, nodeKey);
    node = new Node(config, myInfo, ledger, network);
    cache = node.getCache();
    parcelCache = node.getParcelCache();
    StateRecord r = ledger.getRecord(HashId.withDigest("bS/c4YMidaVuzTBhHLkGPFAvPbZQHybzQnXAoBwaZYM8eLYb7mAkVYEpuqKRXYc7anqX47BeNdvFN1n7KluH9A=="));
    if (r != null)
        r.destroy();
    clientHTTPServer.setConfig(config);
    clientHTTPServer.setNode(node);
    clientHTTPServer.setCache(cache);
    clientHTTPServer.setParcelCache(parcelCache);
    clientHTTPServer.setLocalCors(myInfo.getPublicHost().equals("localhost"));
}
Also used : StateRecord(com.icodici.universa.node.StateRecord) NetworkV2(com.icodici.universa.node2.network.NetworkV2)

Aggregations

StateRecord (com.icodici.universa.node.StateRecord)1 BasicHttpClientSession (com.icodici.universa.node2.network.BasicHttpClientSession)1 NetworkV2 (com.icodici.universa.node2.network.NetworkV2)1