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