Search in sources :

Example 1 with Property

use of utils.Property in project jdchain-core by blockchain-jd-com.

the class BftsmartConsensusSettingsBuilder method modifySystemProperties.

/**
 * update consensus system properties
 */
private Property[] modifySystemProperties(Property[] systemProperties, Properties newProps) {
    Map<String, Property> propertyMapOrig = convert2Map(systemProperties);
    Map<String, Property> propertyMapNew = new HashMap<>();
    Property[] properties = PropertiesUtils.getOrderedValues(newProps);
    if (newProps.getProperty(PARTICIPANT_OP_KEY) != null) {
        if (newProps.getProperty(PARTICIPANT_OP_KEY).equals("deactive")) {
            String deActiveId = newProps.getProperty(DEACTIVE_PARTICIPANT_ID_KEY);
            for (String key : propertyMapOrig.keySet()) {
                if (key.startsWith(keyOfNode(CONSENSUS_HOST_PATTERN, Integer.parseInt(deActiveId))) || key.startsWith(keyOfNode(CONSENSUS_PORT_PATTERN, Integer.parseInt(deActiveId))) || key.startsWith(keyOfNode(CONSENSUS_SECURE_PATTERN, Integer.parseInt(deActiveId))) || key.startsWith(keyOfNode(PUBKEY_PATTERN, Integer.parseInt(deActiveId)))) {
                    continue;
                }
                propertyMapNew.put(key, propertyMapOrig.get(key));
            }
            for (Property property : properties) {
                propertyMapNew.put(property.getName(), new Property(property.getName(), property.getValue()));
            }
            return convert2Array(propertyMapNew);
        }
    }
    propertyMapNew = propertyMapOrig;
    for (Property property : properties) {
        propertyMapNew.put(property.getName(), new Property(property.getName(), property.getValue()));
    }
    return convert2Array(propertyMapNew);
}
Also used : HashMap(java.util.HashMap) Property(utils.Property)

Example 2 with Property

use of utils.Property in project jdchain-core by blockchain-jd-com.

the class ManagementController method prepareActiveTx.

// 在指定的账本上准备一笔激活参与方状态及系统配置参数的操作
private TransactionRequest prepareActiveTx(HashDigest ledgerHash, ParticipantNode node, NetworkAddress addConsensusNodeAddress, Properties customProperties) {
    int activeID = node.getId();
    // organize system config properties
    Property[] properties = ParticipantContext.context().participantService().createActiveProperties(addConsensusNodeAddress, node.getPubKey(), activeID, customProperties);
    TxBuilder txbuilder = new TxBuilder(ledgerHash, ledgerCryptoSettings.get(ledgerHash).getHashAlgorithm());
    // This transaction contains participant state update and settings update two
    // ops
    txbuilder.states().update(new BlockchainIdentityData(node.getPubKey()), ParticipantNodeState.CONSENSUS);
    txbuilder.consensus().update(properties);
    TransactionRequestBuilder reqBuilder = txbuilder.prepareRequest();
    reqBuilder.signAsEndpoint(new AsymmetricKeypair(ledgerKeypairs.get(ledgerHash).getPubKey(), ledgerKeypairs.get(ledgerHash).getPrivKey()));
    return reqBuilder.buildRequest();
}
Also used : TxBuilder(com.jd.blockchain.transaction.TxBuilder) Property(utils.Property) ServiceEndpoint(com.jd.httpservice.agent.ServiceEndpoint)

Example 3 with Property

use of utils.Property in project jdchain-core by blockchain-jd-com.

the class ManagementController method prepareUpdateTx.

// 在指定的账本上准备一笔激活参与方状态及系统配置参数的操作
private TransactionRequest prepareUpdateTx(HashDigest ledgerHash, ParticipantNode node, NetworkAddress updateConsensusNodeAddress, Properties customProperties) {
    int activeID = node.getId();
    // organize system config properties
    Property[] properties = ParticipantContext.context().participantService().createUpdateProperties(updateConsensusNodeAddress, node.getPubKey(), activeID, customProperties);
    TxBuilder txbuilder = new TxBuilder(ledgerHash, ledgerCryptoSettings.get(ledgerHash).getHashAlgorithm());
    // This transaction contains participant state update and settings update two
    // ops
    txbuilder.states().update(new BlockchainIdentityData(node.getPubKey()), ParticipantNodeState.CONSENSUS);
    txbuilder.consensus().update(properties);
    TransactionRequestBuilder reqBuilder = txbuilder.prepareRequest();
    reqBuilder.signAsEndpoint(new AsymmetricKeypair(ledgerKeypairs.get(ledgerHash).getPubKey(), ledgerKeypairs.get(ledgerHash).getPrivKey()));
    return reqBuilder.buildRequest();
}
Also used : TxBuilder(com.jd.blockchain.transaction.TxBuilder) Property(utils.Property) ServiceEndpoint(com.jd.httpservice.agent.ServiceEndpoint)

Example 4 with Property

use of utils.Property in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Bft method createActiveProperties.

@Override
public Property[] createActiveProperties(NetworkAddress address, PubKey activePubKey, int activeID, Properties systemConfig) {
    int oldServerNum = Integer.parseInt(systemConfig.getProperty(SERVER_NUM_KEY));
    int oldFNum = Integer.parseInt(systemConfig.getProperty(F_NUM_KEY));
    String oldView = systemConfig.getProperty(SERVER_VIEW_KEY);
    List<Property> properties = new ArrayList<Property>();
    properties.add(new Property(keyOfNode(CONSENSUS_HOST_PATTERN, activeID), address.getHost()));
    properties.add(new Property(keyOfNode(CONSENSUS_PORT_PATTERN, activeID), String.valueOf(address.getPort())));
    properties.add(new Property(keyOfNode(CONSENSUS_SECURE_PATTERN, activeID), String.valueOf(address.isSecure())));
    properties.add(new Property(keyOfNode(PUBKEY_PATTERN, activeID), activePubKey.toBase58()));
    properties.add(new Property(SERVER_NUM_KEY, String.valueOf(Integer.parseInt(systemConfig.getProperty(SERVER_NUM_KEY)) + 1)));
    properties.add(new Property(PARTICIPANT_OP_KEY, "active"));
    properties.add(new Property(ACTIVE_PARTICIPANT_ID_KEY, String.valueOf(activeID)));
    if ((oldServerNum + 1) >= (3 * (oldFNum + 1) + 1)) {
        properties.add(new Property(F_NUM_KEY, String.valueOf(oldFNum + 1)));
    }
    properties.add(new Property(SERVER_VIEW_KEY, createActiveView(oldView, activeID)));
    return properties.toArray(new Property[properties.size()]);
}
Also used : ArrayList(java.util.ArrayList) Property(utils.Property)

Example 5 with Property

use of utils.Property in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Bft method createUpdateProperties.

@Override
public Property[] createUpdateProperties(NetworkAddress address, PubKey activePubKey, int activeID, Properties systemConfig) {
    String oldView = systemConfig.getProperty(SERVER_VIEW_KEY);
    List<Property> properties = new ArrayList<Property>();
    properties.add(new Property(keyOfNode(CONSENSUS_HOST_PATTERN, activeID), address.getHost()));
    properties.add(new Property(keyOfNode(CONSENSUS_PORT_PATTERN, activeID), String.valueOf(address.getPort())));
    properties.add(new Property(keyOfNode(CONSENSUS_SECURE_PATTERN, activeID), String.valueOf(address.isSecure())));
    properties.add(new Property(keyOfNode(PUBKEY_PATTERN, activeID), activePubKey.toBase58()));
    properties.add(new Property(PARTICIPANT_OP_KEY, "active"));
    properties.add(new Property(ACTIVE_PARTICIPANT_ID_KEY, String.valueOf(activeID)));
    properties.add(new Property(SERVER_VIEW_KEY, createActiveView(oldView, activeID)));
    return properties.toArray(new Property[properties.size()]);
}
Also used : ArrayList(java.util.ArrayList) Property(utils.Property)

Aggregations

Property (utils.Property)12 ArrayList (java.util.ArrayList)7 TxBuilder (com.jd.blockchain.transaction.TxBuilder)3 ServiceEndpoint (com.jd.httpservice.agent.ServiceEndpoint)3 MsgQueueBlockSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings)1 MsgQueueNetworkSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)1 HashMap (java.util.HashMap)1