Search in sources :

Example 1 with RemoteNodeData

use of neo.network.model.RemoteNodeData in project neo-java by coranos.

the class TestNetwork method test001WaitForNetwork.

/**
 * test waiting for network.
 */
@Test
public void test001WaitForNetwork() {
    final RemoteNodeData data = CONTROLLER.getNewRemoteNodeData();
    data.setConnectionPhase(NodeConnectionPhaseEnum.UNKNOWN);
    final InetSocketAddress addressAndPort = new InetSocketAddress("127.0.0.1", 0);
    data.setTcpAddressAndPort(addressAndPort);
    final RemoteNodeControllerRunnable r = new RemoteNodeControllerRunnable(CONTROLLER, data);
    r.run();
}
Also used : RemoteNodeData(neo.network.model.RemoteNodeData) InetSocketAddress(java.net.InetSocketAddress) RemoteNodeControllerRunnable(neo.network.RemoteNodeControllerRunnable) Test(org.junit.Test)

Example 2 with RemoteNodeData

use of neo.network.model.RemoteNodeData in project neo-java by coranos.

the class StatsModel method addNodeConnectionPhaseStats.

/**
 * adds stats for how many peers are in each onnection [hase.
 *
 * @param peerDataList
 *            the set of connected remote peers.
 */
private void addNodeConnectionPhaseStats(final List<RemoteNodeData> peerDataList) {
    final Map<NodeConnectionPhaseEnum, Integer> connectionPhaseMap = new EnumMap<>(NodeConnectionPhaseEnum.class);
    for (final NodeConnectionPhaseEnum connectionPhase : NodeConnectionPhaseEnum.values()) {
        connectionPhaseMap.put(connectionPhase, 0);
    }
    for (final RemoteNodeData data : peerDataList) {
        synchronized (data) {
            final int oldCount = connectionPhaseMap.get(data.getConnectionPhase());
            connectionPhaseMap.put(data.getConnectionPhase(), oldCount + 1);
        }
    }
    for (final NodeConnectionPhaseEnum connectionPhase : connectionPhaseMap.keySet()) {
        final int count = connectionPhaseMap.get(connectionPhase);
        addNameAndValue(WordUtils.capitalize(connectionPhase.name()), count);
    }
}
Also used : RemoteNodeData(neo.network.model.RemoteNodeData) NodeConnectionPhaseEnum(neo.network.model.NodeConnectionPhaseEnum) EnumMap(java.util.EnumMap)

Example 3 with RemoteNodeData

use of neo.network.model.RemoteNodeData in project neo-java by coranos.

the class StatsModel method addVersionStats.

/**
 * add stats on how many peers are at a given version.
 *
 * @param peerDataList
 *            the set of connected remote peers.
 */
private void addVersionStats(final List<RemoteNodeData> peerDataList) {
    final Map<String, Integer> versionCountMap = new TreeMap<>();
    for (final RemoteNodeData data : peerDataList) {
        final String version = data.getVersion();
        if (version != null) {
            if (versionCountMap.containsKey(version)) {
                final int oldCount = versionCountMap.get(version);
                versionCountMap.put(version, oldCount + 1);
            } else {
                versionCountMap.put(version, 1);
            }
        }
    }
    for (final String version : versionCountMap.keySet()) {
        final int count = versionCountMap.get(version);
        addNameAndValue(version, count);
    }
}
Also used : RemoteNodeData(neo.network.model.RemoteNodeData) TreeMap(java.util.TreeMap)

Example 4 with RemoteNodeData

use of neo.network.model.RemoteNodeData in project neo-java by coranos.

the class LocalControllerNode method runPeers.

/**
 * change all unknown and inactive remote nodes to the pool, and put them in the
 * "try-start" phase.
 *
 * @return true if any new peers were added to the pool.
 * @throws Exception
 *             if an error occuured.
 */
private boolean runPeers() {
    if (stopped) {
        return false;
    }
    boolean anyChanged = false;
    final List<RemoteNodeData> peerDataList = new ArrayList<>();
    synchronized (peerDataSet) {
        peerDataList.addAll(peerDataSet);
    }
    for (final RemoteNodeData data : peerDataList) {
        LOG.trace("refreshThread[1] {} runPeers node with phase {}", data.getTcpAddressAndPortString(), data.getConnectionPhase());
        if ((data.getConnectionPhase() == NodeConnectionPhaseEnum.UNKNOWN) || (data.getConnectionPhase() == NodeConnectionPhaseEnum.INACTIVE)) {
            synchronized (this) {
                LOG.trace("refreshThread[2] {} runPeers node with phase {}", data.getTcpAddressAndPortString(), data.getConnectionPhase());
                synchronized (RemoteNodeData.class) {
                    data.setConnectionPhase(NodeConnectionPhaseEnum.TRY_START);
                }
                final RemoteNodeControllerRunnable r = new RemoteNodeControllerRunnable(this, data);
                threadPool.execute(r);
                anyChanged = true;
            }
        }
    }
    return anyChanged;
}
Also used : RemoteNodeData(neo.network.model.RemoteNodeData) ArrayList(java.util.ArrayList)

Example 5 with RemoteNodeData

use of neo.network.model.RemoteNodeData in project neo-java by coranos.

the class LocalControllerNode method startThreadPool.

/**
 * adds all the "unknown" remote nodes to the thread pool.
 *
 * @throws Exception
 *             if an error occurs.
 */
public void startThreadPool() {
    if (stopped) {
        return;
    }
    final List<RemoteNodeData> bootstrapPeerList = new ArrayList<>();
    synchronized (peerDataSet) {
        for (final RemoteNodeData data : peerDataSet) {
            if (data.getConnectionPhase().equals(NodeConnectionPhaseEnum.UNKNOWN)) {
                bootstrapPeerList.add(data);
            }
        }
    }
    notifyNodeDataChangeListeners();
    for (final RemoteNodeData data : bootstrapPeerList) {
        addRemoteNodeDataToPool(data);
    }
}
Also used : RemoteNodeData(neo.network.model.RemoteNodeData) ArrayList(java.util.ArrayList)

Aggregations

RemoteNodeData (neo.network.model.RemoteNodeData)11 ArrayList (java.util.ArrayList)4 InetSocketAddress (java.net.InetSocketAddress)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 LocalNodeData (neo.network.model.LocalNodeData)2 JSONObject (org.json.JSONObject)2 EnumMap (java.util.EnumMap)1 TreeMap (java.util.TreeMap)1 AddrPayload (neo.model.network.AddrPayload)1 NetworkAddressWithTime (neo.model.network.NetworkAddressWithTime)1 VersionPayload (neo.model.network.VersionPayload)1 RemoteNodeControllerRunnable (neo.network.RemoteNodeControllerRunnable)1 NodeConnectionPhaseEnum (neo.network.model.NodeConnectionPhaseEnum)1 JSONArray (org.json.JSONArray)1 Test (org.junit.Test)1