Search in sources :

Example 6 with TOMConfiguration

use of bftsmart.reconfiguration.util.TOMConfiguration in project jdchain-core by blockchain-jd-com.

the class BftsmartPeerProxyFactory method create.

@Override
public AsynchServiceProxy create() throws Exception {
    BftsmartTopology topology = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTopology());
    View view = topology.getView();
    if (view == null) {
        throw new IllegalStateException("No topology view in the bftsmart client settings!");
    }
    MemoryBasedViewStorage viewStorage = new MemoryBasedViewStorage(view);
    TOMConfiguration tomConfiguration = BinarySerializeUtils.deserialize(bftsmartClientSettings.getTomConfig());
    // every proxy client has unique id;
    int processId = allocateId();
    tomConfiguration.setProcessId(processId);
    AsynchServiceProxy peerProxy = new AsynchServiceProxy(tomConfiguration, viewStorage, bftsmartClientSettings.getSSLSecurity());
    if (LOGGER.isInfoEnabled()) {
        // 打印view
        int[] processes = view.getProcesses();
        NodeNetwork[] addresses = new NodeNetwork[processes.length];
        for (int i = 0; i < addresses.length; i++) {
            addresses[i] = view.getAddress(processes[i]);
        }
        LOGGER.info("Creating pooled bftsmart client ... [PooledClientID={}] [ViewID={}] [ViewTopology={}] [Peers={}]", processId, view.getId(), Arrays.toString(processes), Arrays.toString(addresses));
    }
    return peerProxy;
}
Also used : BftsmartTopology(com.jd.blockchain.consensus.bftsmart.BftsmartTopology) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) View(bftsmart.reconfiguration.views.View) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork)

Example 7 with TOMConfiguration

use of bftsmart.reconfiguration.util.TOMConfiguration in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Bft method createPeerProxy.

private ServiceProxy createPeerProxy(Properties systemConfig, int viewId, List<NodeSettings> origConsensusNodes, SSLSecurity security) {
    HostsConfig hostsConfig;
    List<HostsConfig.Config> configList = new ArrayList<>();
    List<NodeNetwork> nodeAddresses = new ArrayList<>();
    try {
        int[] origConsensusProcesses = new int[origConsensusNodes.size()];
        for (int i = 0; i < origConsensusNodes.size(); i++) {
            BftsmartNodeSettings node = (BftsmartNodeSettings) origConsensusNodes.get(i);
            origConsensusProcesses[i] = node.getId();
            configList.add(new HostsConfig.Config(node.getId(), node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
            nodeAddresses.add(new NodeNetwork(node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
        }
        // 构建共识的代理客户端需要的主机配置和系统参数配置结构
        hostsConfig = new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()]));
        Properties tempSystemConfig = (Properties) systemConfig.clone();
        // 构建tom 配置
        TOMConfiguration tomConfig = new TOMConfiguration(-(new Random().nextInt(Integer.MAX_VALUE - 2) - 1), tempSystemConfig, hostsConfig);
        View view = new View(viewId, origConsensusProcesses, tomConfig.getF(), nodeAddresses.toArray(new NodeNetwork[nodeAddresses.size()]));
        LOGGER.info("ManagementController start updateView operation!, current view : {}", view.toString());
        // 构建共识的代理客户端,连接目标共识节点,并递交交易进行共识过程
        return new ServiceProxy(tomConfig, new MemoryBasedViewStorage(view), null, null, security);
    } catch (Exception e) {
        throw new CreateProxyClientException("create proxy client exception!");
    }
}
Also used : BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) ArrayList(java.util.ArrayList) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) Properties(java.util.Properties) View(bftsmart.reconfiguration.views.View) Random(java.util.Random) ServiceProxy(bftsmart.tom.ServiceProxy) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Example 8 with TOMConfiguration

use of bftsmart.reconfiguration.util.TOMConfiguration in project aware by bergerch.

the class RSAKeyPairGenerator method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2)
        System.err.println("Use: RSAKeyPairGenerator <id> <key length> [config dir]");
    String confHome = "";
    if (args.length > 2)
        confHome = args[2];
    TOMConfiguration conf = new TOMConfiguration(Integer.parseInt(args[0]), confHome, null);
    String provider = conf.getSignatureAlgorithmProvider();
    new RSAKeyPairGenerator().run(Integer.parseInt(args[0]), Integer.parseInt(args[1]), provider);
}
Also used : TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Example 9 with TOMConfiguration

use of bftsmart.reconfiguration.util.TOMConfiguration in project bftsmart by blockchain-jd-com.

the class TestNodeServer method startNode.

public ServiceReplica startNode(String realmName) {
    TOMConfiguration config = initConfig();
    try {
        // mock messsageHandler and cs
        MessageHandler messageHandler = new MessageHandler();
        MessageHandler mockMessageHandler = Mockito.spy(messageHandler);
        ClientCommunicationServerSide clientCommunication = ClientCommunicationFactory.createServerSide(new ServerViewController(config, new MemoryBasedViewStorage(latestView)));
        ServerCommunicationSystem cs = new ServerCommunicationSystemImpl(clientCommunication, mockMessageHandler, new ServerViewController(config, new MemoryBasedViewStorage(latestView)), realmName);
        ServerCommunicationSystem mockCs = Mockito.spy(cs);
        replica = new ServiceReplica(mockMessageHandler, mockCs, config, this, this, (int) -1, latestView, realmName);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return replica;
}
Also used : ClientCommunicationServerSide(bftsmart.communication.client.ClientCommunicationServerSide) ServiceReplica(bftsmart.tom.ServiceReplica) ServerCommunicationSystemImpl(bftsmart.communication.ServerCommunicationSystemImpl) MessageHandler(bftsmart.communication.MessageHandler) ServerCommunicationSystem(bftsmart.communication.ServerCommunicationSystem) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration) ServerViewController(bftsmart.reconfiguration.ServerViewController) IOException(java.io.IOException)

Example 10 with TOMConfiguration

use of bftsmart.reconfiguration.util.TOMConfiguration in project bftsmart by blockchain-jd-com.

the class MACKeyGeneratorTest method generateConfig.

private static ReplicaConfiguration generateConfig(int id, int[] viewProcessIds) {
    HostsConfig hosts = new HostsConfig();
    hosts.add(0, "localhost", 10010, 10012);
    hosts.add(1, "localhost", 10020, 10022);
    hosts.add(2, "localhost", 10030, 10032);
    hosts.add(3, "localhost", 10040, 10042);
    TOMConfiguration conf = new TOMConfiguration(0, new Properties(), hosts);
    return conf;
}
Also used : HostsConfig(bftsmart.reconfiguration.util.HostsConfig) Properties(java.util.Properties) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Aggregations

TOMConfiguration (bftsmart.reconfiguration.util.TOMConfiguration)10 HostsConfig (bftsmart.reconfiguration.util.HostsConfig)5 Properties (java.util.Properties)5 MemoryBasedViewStorage (bftsmart.reconfiguration.views.MemoryBasedViewStorage)4 View (bftsmart.reconfiguration.views.View)4 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)3 AsynchServiceProxy (bftsmart.tom.AsynchServiceProxy)2 Random (java.util.Random)2 MessageHandler (bftsmart.communication.MessageHandler)1 ServerCommunicationSystem (bftsmart.communication.ServerCommunicationSystem)1 ServerCommunicationSystemImpl (bftsmart.communication.ServerCommunicationSystemImpl)1 ClientCommunicationServerSide (bftsmart.communication.client.ClientCommunicationServerSide)1 ServerViewController (bftsmart.reconfiguration.ServerViewController)1 ViewStorage (bftsmart.reconfiguration.views.ViewStorage)1 ServiceProxy (bftsmart.tom.ServiceProxy)1 ServiceReplica (bftsmart.tom.ServiceReplica)1 BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)1 BftsmartTopology (com.jd.blockchain.consensus.bftsmart.BftsmartTopology)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1