X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FHighLevelClient.java;h=48399da4914b0bf90ef7903f0b8c4e81de2daa82;hb=64d8425d84114e781a7dea95c0e606349b47a82c;hp=741726f1dd6cee947a6b46d4eeaba765e6b1cd69;hpb=fa94fcde43d1c87745bcdbf25b4fa6242d5b1834;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java b/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java index 741726f..48399da 100644 --- a/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java +++ b/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java @@ -42,6 +42,7 @@ import net.pterodactylus.fcp.FinishedCompression; import net.pterodactylus.fcp.GenerateSSK; import net.pterodactylus.fcp.GetFailed; import net.pterodactylus.fcp.IdentifierCollision; +import net.pterodactylus.fcp.ListPeers; import net.pterodactylus.fcp.NodeData; import net.pterodactylus.fcp.NodeHello; import net.pterodactylus.fcp.Peer; @@ -100,6 +101,9 @@ public class HighLevelClient { /** Mapping from request identifiers to callbacks. */ private Map> keyGenerationCallbacks = Collections.synchronizedMap(new HashMap>()); + /** Mapping from request identifier to peer list callbacks. */ + private Map> peerListCallbacks = Collections.synchronizedMap(new HashMap>()); + /** * Creates a new high-level client that connects to a node on * localhost. @@ -209,6 +213,22 @@ public class HighLevelClient { } /** + * Gets a list of all peers from the node. + * + * @return A callback with the peer list + * @throws IOException + * if an I/O error occurs with the node + */ + public HighLevelCallback getPeers() throws IOException { + String identifier = generateIdentifier("listPeers"); + ListPeers listPeers = new ListPeers(identifier, true, true); + HighLevelCallback peerListCallback = new HighLevelCallback(); + peerListCallbacks.put(identifier, peerListCallback); + fcpConnection.sendMessage(listPeers); + return peerListCallback; + } + + /** * Generates an identifier for the given function. * * @param function @@ -344,7 +364,18 @@ public class HighLevelClient { * @see net.pterodactylus.fcp.FcpListener#receivedPeer(net.pterodactylus.fcp.FcpConnection, * net.pterodactylus.fcp.Peer) */ + @SuppressWarnings("synthetic-access") public void receivedPeer(FcpConnection fcpConnection, Peer peer) { + if (fcpConnection != HighLevelClient.this.fcpConnection) { + return; + } + String identifier = peer.getIdentifier(); + HighLevelCallback peerListCallback = peerListCallbacks.get(identifier); + PeerListResult peerListResult = peerListCallback.getIntermediaryResult(); + if (peerListResult == null) { + peerListResult = new PeerListResult(); + peerListCallback.setResult(peerListResult, false); + } } /**