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);
}
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;
}
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!");
}
}
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;
}
Aggregations