Search in sources :

Example 1 with NodeNetworkAddress

use of com.jd.blockchain.consensus.NodeNetworkAddress in project jdchain-core by blockchain-jd-com.

the class LedgerPeersManager method updateTopology.

public Set<NetworkAddress> updateTopology() {
    for (Map.Entry<NetworkAddress, LedgerPeerConnectionManager> entry : connections.entrySet()) {
        try {
            logger.debug("UpdateTopology by {}", entry.getKey());
            NodeNetworkAddresses nodeNetworkAddresses = entry.getValue().loadMonitors();
            if (null != nodeNetworkAddresses) {
                NodeNetworkAddress[] nodeAddresses = nodeNetworkAddresses.getNodeNetworkAddresses();
                if (nodeAddresses != null && nodeAddresses.length > 0) {
                    Set<NetworkAddress> addresses = new HashSet<>();
                    boolean satisfied = true;
                    for (NodeNetworkAddress address : nodeAddresses) {
                        // 存在端口小于0的情况则不使用此次查询结果
                        if (address.getMonitorPort() > 0) {
                            addresses.add(new NetworkAddress(address.getHost(), address.getMonitorPort(), address.isMonitorSecure()));
                        } else {
                            satisfied = false;
                            break;
                        }
                    }
                    if (satisfied) {
                        logger.debug("UpdateTopology by {} : {}", entry.getKey(), addresses);
                        return addresses;
                    } else {
                        continue;
                    }
                }
            }
        } catch (Exception e) {
            logger.warn("UpdateTopology by {}", entry.getKey(), e);
        }
    }
    return null;
}
Also used : NodeNetworkAddress(com.jd.blockchain.consensus.NodeNetworkAddress) NodeNetworkAddress(com.jd.blockchain.consensus.NodeNetworkAddress) NetworkAddress(utils.net.NetworkAddress) NodeNetworkAddresses(com.jd.blockchain.consensus.NodeNetworkAddresses) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

NodeNetworkAddress (com.jd.blockchain.consensus.NodeNetworkAddress)1 NodeNetworkAddresses (com.jd.blockchain.consensus.NodeNetworkAddresses)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 NetworkAddress (utils.net.NetworkAddress)1