X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Futil%2Ffcp%2FFcpConnection.java;h=a8b6024213c97314b2792951e79f42ed8be7b56b;hb=a1d90ea4e35f7f4f03b352216a1fca37c8e99037;hp=846e135312de809439345bf87d9445af4935772d;hpb=0a4d1ff98574325df37f7cbb6b0655e86dd0cef4;p=jSite2.git diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 846e135..a8b6024 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -29,7 +29,11 @@ import java.util.ArrayList; import java.util.List; import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName; +import net.pterodactylus.util.fcp.message.EndListPeerNotes; +import net.pterodactylus.util.fcp.message.EndListPeers; import net.pterodactylus.util.fcp.message.NodeHello; +import net.pterodactylus.util.fcp.message.Peer; +import net.pterodactylus.util.fcp.message.PeerNote; import net.pterodactylus.util.fcp.message.SSKKeypair; import net.pterodactylus.util.io.Closer; @@ -184,6 +188,58 @@ public class FcpConnection { } /** + * Notifies listeners that a “Peer” message was received. + * + * @see FcpListener#receivedPeer(FcpConnection, Peer) + * @param peer + * The “Peer” message + */ + private void fireReceivedPeer(Peer peer) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedPeer(this, peer); + } + } + + /** + * Notifies all listeners that an “EndListPeers” message was received. + * + * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers) + * @param endListPeers + * The “EndListPeers” message + */ + private void fireReceivedEndListPeers(EndListPeers endListPeers) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedEndListPeers(this, endListPeers); + } + } + + /** + * Notifies all listeners that a “PeerNote” message was received. + * + * @see FcpListener#receviedPeerNote(FcpConnection, PeerNote) + * @param peerNote + */ + private void fireReceivedPeerNote(PeerNote peerNote) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receviedPeerNote(this, peerNote); + } + } + + /** + * Notifies all listeners that an “EndListPeerNotes” message was received. + * + * @see FcpListener#receivedEndListPeerNotes(FcpConnection, + * EndListPeerNotes) + * @param endListPeerNotes + * The “EndListPeerNotes” message + */ + private void fireReceivedEndListPeerNotes(EndListPeerNotes endListPeerNotes) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedEndListPeerNotes(this, endListPeerNotes); + } + } + + /** * Notifies all registered listeners that a message has been received. * * @see FcpListener#receivedMessage(FcpConnection, FcpMessage) @@ -257,7 +313,15 @@ public class FcpConnection { */ void handleMessage(FcpMessage fcpMessage) { String messageName = fcpMessage.getName(); - if ("SSKKeypair".equals(messageName)) { + if ("Peer".equals(messageName)) { + fireReceivedPeer(new Peer(fcpMessage)); + } else if ("PeerNote".equals(messageName)) { + fireReceivedPeerNote(new PeerNote(fcpMessage)); + } else if ("EndListPeerNotes".equals(messageName)) { + fireReceivedEndListPeerNotes(new EndListPeerNotes(fcpMessage)); + } else if ("EndListPeers".equals(messageName)) { + fireReceivedEndListPeers(new EndListPeers(fcpMessage)); + } else if ("SSKKeypair".equals(messageName)) { fireReceivedSSKKeypair(new SSKKeypair(fcpMessage)); } else if ("NodeHello".equals(messageName)) { fireReceivedNodeHello(new NodeHello(fcpMessage));