use of co.rsk.net.NodeID in project rskj by rsksmart.
the class DecidingSyncStateTest method startsSyncingWith5Peers.
@Test
public void startsSyncingWith5Peers() {
SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
SimpleSyncInformation syncInformation = new SimpleSyncInformation();
ChannelManager channelManager = RskMockFactory.getChannelManager();
PeersInformation knownPeers = new PeersInformation(syncInformation, channelManager, syncConfiguration);
SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers);
Collection<Channel> peers = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
NodeID nodeID = new NodeID(HashUtil.randomPeerId());
Channel channel = mock(Channel.class);
when(channel.getNodeId()).thenReturn(nodeID);
peers.add(channel);
when(channelManager.getActivePeers()).thenReturn(peers);
knownPeers.registerPeer(nodeID).setStatus(StatusUtils.getFakeStatus());
syncState.newPeerStatus();
}
Assert.assertTrue(syncEventsHandler.startSyncingWasCalled());
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class Web3ImplScoringTest method getPeerList.
@Test
public void getPeerList() throws UnknownHostException {
NodeID node = generateNodeID();
InetAddress address = generateNonLocalIPAddressV4();
PeerScoringManager peerScoringManager = createPeerScoringManager();
peerScoringManager.recordEvent(node, address, EventType.VALID_BLOCK);
peerScoringManager.recordEvent(node, address, EventType.VALID_TRANSACTION);
peerScoringManager.recordEvent(node, address, EventType.VALID_BLOCK);
Web3Impl web3 = createWeb3(peerScoringManager);
PeerScoringInformation[] result = web3.sco_peerList();
Assert.assertNotNull(result);
Assert.assertEquals(2, result.length);
PeerScoringInformation info = result[0];
Assert.assertEquals(Hex.toHexString(node.getID()).substring(0, 8), info.getId());
Assert.assertEquals(2, info.getValidBlocks());
Assert.assertEquals(0, info.getInvalidBlocks());
Assert.assertEquals(1, info.getValidTransactions());
Assert.assertEquals(0, info.getInvalidTransactions());
Assert.assertTrue(info.getScore() > 0);
info = result[1];
Assert.assertEquals(address.getHostAddress(), info.getId());
Assert.assertEquals(2, info.getValidBlocks());
Assert.assertEquals(0, info.getInvalidBlocks());
Assert.assertEquals(1, info.getValidTransactions());
Assert.assertEquals(0, info.getInvalidTransactions());
Assert.assertTrue(info.getScore() > 0);
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class HandshakeHandler method recordEvent.
private void recordEvent(ChannelHandlerContext ctx, EventType event) {
SocketAddress socketAddress = ctx.channel().remoteAddress();
// TODO(mmarquez): what if it is not ??
if (socketAddress instanceof InetSocketAddress) {
NodeID nodeID = channel.getNodeId();
InetAddress address = ((InetSocketAddress) socketAddress).getAddress();
peerScoringManager.recordEvent(nodeID, address, event);
}
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerExplorer method addConnection.
private void addConnection(PongPeerMessage message, String ip, int port) {
Node senderNode = new Node(message.getNodeId().getID(), ip, port);
if (!StringUtils.equals(senderNode.getHexId(), this.localNode.getHexId())) {
OperationResult result = this.distanceTable.addNode(senderNode);
if (result.isSuccess()) {
NodeID senderId = senderNode.getId();
this.establishedConnections.put(senderId, senderNode);
logger.debug("New Peer found ip:[{}] port[{}]", ip, port);
} else {
this.challengeManager.startChallenge(result.getAffectedEntry().getNode(), senderNode, this);
}
}
}
use of co.rsk.net.NodeID in project rskj by rsksmart.
the class PeerExplorer method handleFindNode.
public void handleFindNode(FindNodePeerMessage message) {
NodeID nodeId = message.getNodeId();
Node connectedNode = this.establishedConnections.get(nodeId);
if (connectedNode != null) {
List<Node> nodesToSend = this.distanceTable.getClosestNodes(nodeId);
logger.debug("About to send [{}] neighbors to ip[{}] port[{}] nodeId[{}]", nodesToSend.size(), connectedNode.getHost(), connectedNode.getPort(), connectedNode.getHexIdShort());
this.sendNeighbors(connectedNode.getAddress(), nodesToSend, message.getMessageId());
updateEntry(connectedNode);
}
}
Aggregations