protected String parseBlockHash(NetworkPeers.Peer remotePeer) { ObjectUtils.checkNotNull(remotePeer); if (remotePeer.block == null) { return null; } int index = remotePeer.block.indexOf("-"); if (index == -1) { return null; } String hash = remotePeer.block.substring(index + 1); return hash; }
protected Integer parseBlockNumber(NetworkPeers.Peer remotePeer) { ObjectUtils.checkNotNull(remotePeer); if (remotePeer.block == null) { return null; } int index = remotePeer.block.indexOf("-"); if (index == -1) { return null; } String str = remotePeer.block.substring(0, index); try { return Integer.parseInt(str); } catch (NumberFormatException e) { return null; } }
@Override public List<Peer> findPeers( Peer peer, String status, EndpointProtocol endpointProtocol, Integer currentBlockNumber, String currentBlockHash) { ObjectUtils.checkNotNull(peer); List<Peer> result = new ArrayList<Peer>(); NetworkPeers remoteResult = httpService.executeRequest(peer, URL_PEERS, NetworkPeers.class); for (NetworkPeers.Peer remotePeer : remoteResult.peers) { boolean match = (status == null || status.equalsIgnoreCase(remotePeer.status)) && (currentBlockNumber == null || currentBlockNumber.equals(parseBlockNumber(remotePeer))) && (currentBlockHash == null || currentBlockHash.equals(parseBlockHash(remotePeer))); if (match) { for (NetworkPeering.Endpoint endpoint : remotePeer.endpoints) { match = endpointProtocol == null || endpointProtocol == endpoint.protocol; if (match) { Peer childPeer = toPeer(endpoint); if (childPeer != null) { result.add(childPeer); } } } } } return result; }