Search in sources :

Example 1 with MemoryBasedViewStorage

use of bftsmart.reconfiguration.views.MemoryBasedViewStorage in project bftsmart by blockchain-jd-com.

the class ConsensusTest_ method createClient.

/**
 * 准备共识客户端
 */
public void createClient(int nodeNum) {
    TOMConfiguration config = loadClientConfig(nodeNum);
    latestView = new View(0, config.getInitialView(), config.getF(), addresses.toArray(new NodeNetwork[addresses.size()]));
    ViewStorage viewStorage = new MemoryBasedViewStorage(latestView);
    clientProxy = new AsynchServiceProxy(config, viewStorage);
    Random random = new Random();
    bytes = new byte[4];
    random.nextBytes(bytes);
}
Also used : ViewStorage(bftsmart.reconfiguration.views.ViewStorage) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) Random(java.util.Random) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) View(bftsmart.reconfiguration.views.View) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Example 2 with MemoryBasedViewStorage

use of bftsmart.reconfiguration.views.MemoryBasedViewStorage 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 3 with MemoryBasedViewStorage

use of bftsmart.reconfiguration.views.MemoryBasedViewStorage 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 4 with MemoryBasedViewStorage

use of bftsmart.reconfiguration.views.MemoryBasedViewStorage 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)

Aggregations

TOMConfiguration (bftsmart.reconfiguration.util.TOMConfiguration)4 MemoryBasedViewStorage (bftsmart.reconfiguration.views.MemoryBasedViewStorage)4 View (bftsmart.reconfiguration.views.View)3 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)2 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 HostsConfig (bftsmart.reconfiguration.util.HostsConfig)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 Properties (java.util.Properties)1