use of org.ethereum.net.rlpx.Node in project rskj by rsksmart.
the class PeerExplorer method handlePingMessage.
public void handlePingMessage(String ip, PingPeerMessage message) {
this.sendPong(ip, message);
Node connectedNode = this.establishedConnections.get(message.getNodeId());
if (connectedNode == null) {
this.sendPing(new InetSocketAddress(ip, message.getPort()), 1);
} else {
updateEntry(connectedNode);
}
}
use of org.ethereum.net.rlpx.Node in project rskj by rsksmart.
the class PeerExplorer method collectRandomNodes.
private Set<Node> collectRandomNodes(List<Node> originalList, int elementsNbr) {
Set<Node> ret = new HashSet<>();
SecureRandom rnd = new SecureRandom();
while (ret.size() < elementsNbr) {
int i = rnd.nextInt(originalList.size());
ret.add(originalList.get(i));
}
return ret;
}
use of org.ethereum.net.rlpx.Node in project rskj by rsksmart.
the class PeerExplorer method removeConnections.
private void removeConnections(List<PeerDiscoveryRequest> expiredRequests) {
if (CollectionUtils.isNotEmpty(expiredRequests)) {
for (PeerDiscoveryRequest req : expiredRequests) {
Node node = req.getRelatedNode();
if (node != null) {
this.establishedConnections.remove(node.getId());
this.distanceTable.removeNode(node);
}
}
}
}
use of org.ethereum.net.rlpx.Node in project rskj by rsksmart.
the class NeighborsPeerMessage method create.
public static NeighborsPeerMessage create(List<Node> nodes, String check, ECKey privKey) {
byte[][] nodeRLPs = null;
if (nodes != null) {
nodeRLPs = new byte[nodes.size()][];
int i = 0;
for (Node node : nodes) {
nodeRLPs[i] = node.getRLP();
++i;
}
}
byte[] rlpListNodes = RLP.encodeList(nodeRLPs);
byte[] rlpCheck = RLP.encodeElement(check.getBytes(StandardCharsets.UTF_8));
byte[] type = new byte[] { (byte) DiscoveryMessageType.NEIGHBORS.getTypeValue() };
byte[] data = RLP.encodeList(rlpListNodes, rlpCheck);
NeighborsPeerMessage neighborsMessage = new NeighborsPeerMessage();
neighborsMessage.encode(type, data, privKey);
neighborsMessage.nodes = nodes;
neighborsMessage.messageId = check;
return neighborsMessage;
}
use of org.ethereum.net.rlpx.Node in project rskj by rsksmart.
the class NeighborsPeerMessage method parse.
@Override
public final void parse(byte[] data) {
RLPList list = (RLPList) RLP.decode2OneItem(data, 0);
RLPList nodesRLP = (RLPList) list.get(0);
nodes = new ArrayList<>();
for (int i = 0; i < nodesRLP.size(); ++i) {
RLPList nodeRLP = (RLPList) nodesRLP.get(i);
Node node = new Node(nodeRLP.getRLPData());
nodes.add(node);
}
RLPItem chk = (RLPItem) list.get(1);
this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
}
Aggregations