From 749c2c95584871085b9db63e0e09c89a3bb24dc6 Mon Sep 17 00:00:00 2001 From: Rogiel Sulzbach Date: Sun, 22 Apr 2012 18:53:17 -0300 Subject: [PATCH] Moved peer model related classes to com.torrent4j.model.peer --- .gitignore | 3 + src/main/java/com/torrent4j/TestMain.java | 2 +- .../com/torrent4j/model/TorrentSwarm.java | 2 + .../model/{ => peer}/TorrentPeer.java | 27 ++++-- .../model/peer/TorrentPeerCapability.java | 97 +++++++++++++++++++ .../model/peer/TorrentPeerChoking.java | 10 ++ .../model/{ => peer}/TorrentPeerClient.java | 33 +++++-- .../model/{ => peer}/TorrentPeerID.java | 32 ++++-- .../model/peer/TorrentPeerInterest.java | 10 ++ .../model/{ => peer}/TorrentPeerPieces.java | 4 +- .../model/{ => peer}/TorrentPeerState.java | 13 +-- .../{ => peer}/TorrentPeerTrafficControl.java | 4 +- .../com/torrent4j/net/TorrentProtocol.java | 2 +- .../torrent4j/net/TorrentProtocolPeer.java | 2 +- .../net/peerwire/PeerWireHandler.java | 6 +- .../net/peerwire/PeerWireProtocol.java | 2 +- .../net/peerwire/PeerWireProtocolPeer.java | 2 +- .../traffic/PeerTrafficShapingHandler.java | 4 +- .../storage/InMemoryTorrentStorage.java | 4 +- .../strategy/TorrentDownloadStrategy.java | 2 +- .../strategy/TorrentPeerStrategy.java | 2 +- .../strategy/TorrentUploadStrategy.java | 2 +- .../strategy/standard/PieceSelector.java | 7 +- .../standard/RandomPieceSelector.java | 2 +- .../StandardTorrentDownloadStrategy.java | 2 +- .../standard/StandardTorrentPeerStrategy.java | 2 +- .../standard/StandardTorrentStrategy.java | 2 +- .../StandardTorrentUploadStrategy.java | 2 +- 28 files changed, 232 insertions(+), 50 deletions(-) rename src/main/java/com/torrent4j/model/{ => peer}/TorrentPeer.java (86%) create mode 100644 src/main/java/com/torrent4j/model/peer/TorrentPeerCapability.java create mode 100644 src/main/java/com/torrent4j/model/peer/TorrentPeerChoking.java rename src/main/java/com/torrent4j/model/{ => peer}/TorrentPeerClient.java (52%) rename src/main/java/com/torrent4j/model/{ => peer}/TorrentPeerID.java (58%) create mode 100644 src/main/java/com/torrent4j/model/peer/TorrentPeerInterest.java rename src/main/java/com/torrent4j/model/{ => peer}/TorrentPeerPieces.java (80%) rename src/main/java/com/torrent4j/model/{ => peer}/TorrentPeerState.java (93%) rename src/main/java/com/torrent4j/model/{ => peer}/TorrentPeerTrafficControl.java (73%) diff --git a/.gitignore b/.gitignore index c3a9b66..13af8af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /.project /.classpath /.settings + +target/ +test.torrent \ No newline at end of file diff --git a/src/main/java/com/torrent4j/TestMain.java b/src/main/java/com/torrent4j/TestMain.java index 38fb94b..33a6f99 100644 --- a/src/main/java/com/torrent4j/TestMain.java +++ b/src/main/java/com/torrent4j/TestMain.java @@ -6,7 +6,7 @@ import java.net.InetSocketAddress; import java.nio.file.Paths; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.net.peerwire.PeerWireProtocol; import com.torrent4j.storage.InMemoryTorrentStorage; diff --git a/src/main/java/com/torrent4j/model/TorrentSwarm.java b/src/main/java/com/torrent4j/model/TorrentSwarm.java index 15ea0bb..3bc728c 100644 --- a/src/main/java/com/torrent4j/model/TorrentSwarm.java +++ b/src/main/java/com/torrent4j/model/TorrentSwarm.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.torrent4j.model.peer.TorrentPeer; + public class TorrentSwarm { private final Torrent torrent; private final List peers = new ArrayList<>(); diff --git a/src/main/java/com/torrent4j/model/TorrentPeer.java b/src/main/java/com/torrent4j/model/peer/TorrentPeer.java similarity index 86% rename from src/main/java/com/torrent4j/model/TorrentPeer.java rename to src/main/java/com/torrent4j/model/peer/TorrentPeer.java index b924f82..31d1920 100644 --- a/src/main/java/com/torrent4j/model/TorrentPeer.java +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeer.java @@ -1,11 +1,12 @@ -package com.torrent4j.model; +package com.torrent4j.model.peer; import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.ByteBuffer; -import com.torrent4j.model.TorrentPeerState.TorrentPeerChoking; -import com.torrent4j.model.TorrentPeerState.TorrentPeerInterest; +import com.torrent4j.model.Torrent; +import com.torrent4j.model.TorrentPiece; +import com.torrent4j.model.TorrentPieceBlock; import com.torrent4j.net.TorrentProtocolPeer; /** @@ -74,14 +75,14 @@ public class TorrentPeer { public void setPeerID(TorrentPeerID peerID) { this.peerID = peerID; } - + public void setPeerID(String peerID) { this.peerID = new TorrentPeerID(this, peerID); } /** - * Tries to detect the peer's client. If unknown, {@link TorrentPeerClient#UNKNOWN} is - * returned. + * Tries to detect the peer's client. If unknown, + * {@link TorrentPeerClient#UNKNOWN} is returned. * * @return the peer torrent client */ @@ -89,6 +90,20 @@ public class TorrentPeer { return peerID.getClient(); } + /** + * @return true if the client version is known + */ + public boolean isClientVersionKnown() { + return peerID.isClientVersionKnown(); + } + + /** + * @return the client version as by the PeerID + */ + public String getClientVersion() { + return peerID.getClientVersion(); + } + public TorrentProtocolPeer getProtocolPeer() { return protocolPeer; } diff --git a/src/main/java/com/torrent4j/model/peer/TorrentPeerCapability.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerCapability.java new file mode 100644 index 0000000..d558694 --- /dev/null +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerCapability.java @@ -0,0 +1,97 @@ +package com.torrent4j.model.peer; + +import com.torrent4j.net.peerwire.messages.HandshakeMessage; + +/** + * Enlists all recognized extensions for the bittorrent protocol + * + * @author Rogiel + */ +public enum TorrentPeerCapability { + /** + * These extensions serve multiple purposes. They allow a peer to more + * quickly bootstrap into a swarm by giving a peer a specific set of pieces + * which they will be allowed download regardless of choked status. They + * reduce message overhead by adding HaveAll and HaveNone messages and allow + * explicit rejection of piece requests whereas previously only implicit + * rejection was possible meaning that a peer might be left waiting for a + * piece that would never be delivered. + */ + FAST_PEERS(62), + + /** + * This extension is to allow for the tracking of peers downloading torrents + * without the use of a standard tracker. A peer implementing this protocol + * becomes a "tracker" and stores lists of other nodes/peers which can be + * used to locate new peers. + */ + DHT(64), + + /** + * A protocol in its own right - if two clients indicate they support the + * protocol, then they should switch over to using it. It allows normal + * BitTorrent as well extension messages to be sent over it. Currently + * implemented by Azureus and Transmission. + *

+ * It is not possible to use both this protocol and the LibTorrent extension + * protocol at the same time - if both clients indicate they support both, + * then they should follow the semantics defined by the Extension + * Negotiation Protocol. + */ + AZUREUS_MESSAGING_PROTOCOL(1), + + /** + * This is a protocol for exchanging extension information and was derived + * from an early version of Azureus' extension protocol. It adds one message + * for exchanging arbitrary handshake information including defined + * extension messages, mapping extensions to specific message IDs. + */ + EXTENSION_PROTOCOL(44), + + /** + * These bits are used to allow two clients that support both the Azureus + * Messaging Protocol and LibTorrent's extension protocol to decide which of + * the two extensions should be used for communication. + *

+ * This bit should always be set along with this + * {@link TorrentPeerCapability#EXTENSION_NEGOTIATION_PROTOCOL_2} + * + * @see TorrentPeerCapability#EXTENSION_NEGOTIATION_PROTOCOL_2 + */ + EXTENSION_NEGOTIATION_PROTOCOL_1(47), + /** + * These bits are used to allow two clients that support both the Azureus + * Messaging Protocol and LibTorrent's extension protocol to decide which of + * the two extensions should be used for communication. + *

+ * This bit should always be set along with this + * {@link TorrentPeerCapability#EXTENSION_NEGOTIATION_PROTOCOL_1} + * + * @see TorrentPeerCapability#EXTENSION_NEGOTIATION_PROTOCOL_1 + */ + EXTENSION_NEGOTIATION_PROTOCOL_2(48), + + /** + * A Protocol, considering peers location (in geographical terms) for better + * performance. + */ + LOCATION_AWARE_PROTOCOL(48); + + /** + * This bit is stored on the {@link HandshakeMessage#reserved} long. Those + * set of bits specify which BitTorrent extensions are known and compatible + * with the client. If any given extension is supported by both clients, it + * is enabled by default. + */ + public final int bit; + + /** + * Creates a new enum instance + * + * @param bit + * the bit + */ + private TorrentPeerCapability(int bit) { + this.bit = bit; + } +} diff --git a/src/main/java/com/torrent4j/model/peer/TorrentPeerChoking.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerChoking.java new file mode 100644 index 0000000..92070d3 --- /dev/null +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerChoking.java @@ -0,0 +1,10 @@ +package com.torrent4j.model.peer; + +/** + * Determines whether the peer is choked or unchocked. + * + * @author Rogiel + */ +public enum TorrentPeerChoking { + CHOKED, UNCHOKED; +} \ No newline at end of file diff --git a/src/main/java/com/torrent4j/model/TorrentPeerClient.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerClient.java similarity index 52% rename from src/main/java/com/torrent4j/model/TorrentPeerClient.java rename to src/main/java/com/torrent4j/model/peer/TorrentPeerClient.java index ffd5728..7d21d31 100644 --- a/src/main/java/com/torrent4j/model/TorrentPeerClient.java +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerClient.java @@ -1,4 +1,4 @@ -package com.torrent4j.model; +package com.torrent4j.model.peer; /** * The list of known torrent clients @@ -9,17 +9,17 @@ public enum TorrentPeerClient { /** * µTorrent for Mac (-UM) */ - UTORRENT_FOR_MAC("µTorrent for Mac", "-UM"), + UTORRENT_FOR_MAC("µTorrent for Mac", "-UM", true), /** * µTorrent (-UT) */ - UTORRENT("µTorrent", "-UT"), + UTORRENT("µTorrent", "-UT", true), /** * Transmission (-TR) */ - TRANSMISSION("Transmission", "-TR"), - - UNKNOWN("Unknown", ""); + TRANSMISSION("Transmission", "-TR", true), + + UNKNOWN("Unknown", "", false); /** * An friendly name for the client. Can be used on an UI. @@ -29,6 +29,10 @@ public enum TorrentPeerClient { * The PeerID prefix for the client */ public final String prefix; + /** + * Whether the PeerID has an version attribute + */ + public final boolean versioned; /** * Initializes a new enum value @@ -39,7 +43,24 @@ public enum TorrentPeerClient { * the PeerID prefix */ private TorrentPeerClient(String friendlyName, String prefix) { + this(friendlyName, prefix, false); + } + + /** + * Initializes a new enum value + * + * @param friendlyName + * an friendly name for the client + * @param prefix + * the PeerID prefix + * @param versioned + * whether the PeerID has an version attribute + * + */ + private TorrentPeerClient(String friendlyName, String prefix, + boolean versioned) { this.friendlyName = friendlyName; this.prefix = prefix; + this.versioned = versioned; } } diff --git a/src/main/java/com/torrent4j/model/TorrentPeerID.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerID.java similarity index 58% rename from src/main/java/com/torrent4j/model/TorrentPeerID.java rename to src/main/java/com/torrent4j/model/peer/TorrentPeerID.java index 838286c..080abcf 100644 --- a/src/main/java/com/torrent4j/model/TorrentPeerID.java +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerID.java @@ -1,4 +1,6 @@ -package com.torrent4j.model; +package com.torrent4j.model.peer; + +import com.torrent4j.model.Torrent; /** * This ID represents an PeerID on the BitTorrent network @@ -36,21 +38,39 @@ public class TorrentPeerID { } /** - * Tries to detect the peer's client. If unknown, {@link TorrentPeerClient#UNKNOWN} is - * returned. + * Tries to detect the peer's client. If unknown, + * {@link TorrentPeerClient#UNKNOWN} is returned. * * @return the peer torrent client */ public TorrentPeerClient getClient() { - for(TorrentPeerClient client : TorrentPeerClient.values()) { - if(client == TorrentPeerClient.UNKNOWN) + for (TorrentPeerClient client : TorrentPeerClient.values()) { + if (client == TorrentPeerClient.UNKNOWN) continue; - if(peerID.startsWith(client.prefix)) + if (peerID.startsWith(client.prefix)) return client; } return TorrentPeerClient.UNKNOWN; } + /** + * @return true if the client version is known + */ + public boolean isClientVersionKnown() { + return getClient().versioned; + } + + /** + * @return the client version as by the PeerID + */ + public String getClientVersion() { + if (isClientVersionKnown()) { + return this.peerID.substring(3, 7); + } else { + return null; + } + } + /** * @return the peer */ diff --git a/src/main/java/com/torrent4j/model/peer/TorrentPeerInterest.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerInterest.java new file mode 100644 index 0000000..f5923f3 --- /dev/null +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerInterest.java @@ -0,0 +1,10 @@ +package com.torrent4j.model.peer; + +/** + * Determines whether there are interest on each other pieces + * + * @author Rogiel + */ +public enum TorrentPeerInterest { + INTERESTED, NOT_INTERESTED; +} \ No newline at end of file diff --git a/src/main/java/com/torrent4j/model/TorrentPeerPieces.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerPieces.java similarity index 80% rename from src/main/java/com/torrent4j/model/TorrentPeerPieces.java rename to src/main/java/com/torrent4j/model/peer/TorrentPeerPieces.java index 28cff6c..e844171 100644 --- a/src/main/java/com/torrent4j/model/TorrentPeerPieces.java +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerPieces.java @@ -1,7 +1,9 @@ -package com.torrent4j.model; +package com.torrent4j.model.peer; import java.util.BitSet; +import com.torrent4j.model.AbstractTorrentPiecesContainer; + public class TorrentPeerPieces extends AbstractTorrentPiecesContainer { private final TorrentPeer peer; diff --git a/src/main/java/com/torrent4j/model/TorrentPeerState.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerState.java similarity index 93% rename from src/main/java/com/torrent4j/model/TorrentPeerState.java rename to src/main/java/com/torrent4j/model/peer/TorrentPeerState.java index 90f0a29..276c2c3 100644 --- a/src/main/java/com/torrent4j/model/TorrentPeerState.java +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerState.java @@ -1,24 +1,19 @@ -package com.torrent4j.model; +package com.torrent4j.model.peer; import java.util.Date; +import com.torrent4j.model.Torrent; +import com.torrent4j.model.TorrentPieceBlock; + public class TorrentPeerState { private final TorrentPeer peer; private TorrentPeerInterest remoteInterest = TorrentPeerInterest.NOT_INTERESTED; private TorrentPeerInterest localInterest = TorrentPeerInterest.NOT_INTERESTED; - public enum TorrentPeerInterest { - INTERESTED, NOT_INTERESTED; - } - private TorrentPeerChoking remoteChoked = TorrentPeerChoking.CHOKED; private TorrentPeerChoking locallyChoked = TorrentPeerChoking.CHOKED; - public enum TorrentPeerChoking { - CHOKED, UNCHOKED; - } - private TorrentPieceBlock downloadRequestedBlock; private Date downloadRequestedDate; private TorrentPieceBlock lastDownloadedBlock; diff --git a/src/main/java/com/torrent4j/model/TorrentPeerTrafficControl.java b/src/main/java/com/torrent4j/model/peer/TorrentPeerTrafficControl.java similarity index 73% rename from src/main/java/com/torrent4j/model/TorrentPeerTrafficControl.java rename to src/main/java/com/torrent4j/model/peer/TorrentPeerTrafficControl.java index 46c89d4..ab0d05b 100644 --- a/src/main/java/com/torrent4j/model/TorrentPeerTrafficControl.java +++ b/src/main/java/com/torrent4j/model/peer/TorrentPeerTrafficControl.java @@ -1,4 +1,6 @@ -package com.torrent4j.model; +package com.torrent4j.model.peer; + +import com.torrent4j.model.TorrentTrafficControl; public class TorrentPeerTrafficControl extends TorrentTrafficControl { private final TorrentPeer peer; diff --git a/src/main/java/com/torrent4j/net/TorrentProtocol.java b/src/main/java/com/torrent4j/net/TorrentProtocol.java index 92e01ba..4c01d66 100644 --- a/src/main/java/com/torrent4j/net/TorrentProtocol.java +++ b/src/main/java/com/torrent4j/net/TorrentProtocol.java @@ -1,7 +1,7 @@ package com.torrent4j.net; import com.torrent4j.TorrentController; -import com.torrent4j.model.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeer; public interface TorrentProtocol { void start(TorrentController controller, int listenPort); diff --git a/src/main/java/com/torrent4j/net/TorrentProtocolPeer.java b/src/main/java/com/torrent4j/net/TorrentProtocolPeer.java index 3e2b1c2..26dd8de 100644 --- a/src/main/java/com/torrent4j/net/TorrentProtocolPeer.java +++ b/src/main/java/com/torrent4j/net/TorrentProtocolPeer.java @@ -4,7 +4,7 @@ import java.nio.ByteBuffer; import java.util.BitSet; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeer; public interface TorrentProtocolPeer { public TorrentPeer getTorrentPeer(); diff --git a/src/main/java/com/torrent4j/net/peerwire/PeerWireHandler.java b/src/main/java/com/torrent4j/net/peerwire/PeerWireHandler.java index cb1fc3d..a4d7105 100644 --- a/src/main/java/com/torrent4j/net/peerwire/PeerWireHandler.java +++ b/src/main/java/com/torrent4j/net/peerwire/PeerWireHandler.java @@ -11,9 +11,9 @@ import java.util.Date; import com.torrent4j.TorrentController; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; -import com.torrent4j.model.TorrentPeerState.TorrentPeerChoking; -import com.torrent4j.model.TorrentPeerState.TorrentPeerInterest; +import com.torrent4j.model.peer.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeerChoking; +import com.torrent4j.model.peer.TorrentPeerInterest; import com.torrent4j.model.TorrentPiece; import com.torrent4j.model.TorrentPieceBlock; import com.torrent4j.net.peerwire.codec.PeerWireFrameDecoder; diff --git a/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocol.java b/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocol.java index 65d5c34..ae8f93c 100644 --- a/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocol.java +++ b/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocol.java @@ -14,7 +14,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import com.torrent4j.TorrentController; -import com.torrent4j.model.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.net.TorrentProtocol; public class PeerWireProtocol implements TorrentProtocol { diff --git a/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocolPeer.java b/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocolPeer.java index b7ce9cb..c672af4 100644 --- a/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocolPeer.java +++ b/src/main/java/com/torrent4j/net/peerwire/PeerWireProtocolPeer.java @@ -7,7 +7,7 @@ import java.nio.ByteBuffer; import java.util.BitSet; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.net.TorrentProtocolPeer; import com.torrent4j.net.peerwire.messages.BitFieldMessage; import com.torrent4j.net.peerwire.messages.BlockMessage; diff --git a/src/main/java/com/torrent4j/net/peerwire/traffic/PeerTrafficShapingHandler.java b/src/main/java/com/torrent4j/net/peerwire/traffic/PeerTrafficShapingHandler.java index f23f8c6..049c1f3 100644 --- a/src/main/java/com/torrent4j/net/peerwire/traffic/PeerTrafficShapingHandler.java +++ b/src/main/java/com/torrent4j/net/peerwire/traffic/PeerTrafficShapingHandler.java @@ -5,8 +5,8 @@ import io.netty.handler.traffic.TrafficCounter; import java.util.concurrent.Executor; -import com.torrent4j.model.TorrentPeer; -import com.torrent4j.model.TorrentPeerTrafficControl; +import com.torrent4j.model.peer.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeerTrafficControl; public class PeerTrafficShapingHandler extends ChannelTrafficShapingHandler { private long writeLimit; diff --git a/src/main/java/com/torrent4j/storage/InMemoryTorrentStorage.java b/src/main/java/com/torrent4j/storage/InMemoryTorrentStorage.java index c583094..0fec57f 100644 --- a/src/main/java/com/torrent4j/storage/InMemoryTorrentStorage.java +++ b/src/main/java/com/torrent4j/storage/InMemoryTorrentStorage.java @@ -9,8 +9,8 @@ import com.torrent4j.model.Torrent; import com.torrent4j.util.Range; /** - * An simple {@link TorrentStorage} implementation that stores data into huge - * in-memory direct buffers. Please note that though it provides really fast + * An simple {@link TorrentStorage} implementation that stores data into a huge + * in-memory direct buffer. Please note that though it provides really fast * write and reading, it should not be used in real world implementations. * Storing data in-memory consumes a lot of memory and may cause the JVM to be * terminated by some OSes. diff --git a/src/main/java/com/torrent4j/strategy/TorrentDownloadStrategy.java b/src/main/java/com/torrent4j/strategy/TorrentDownloadStrategy.java index 86e1c89..27002b8 100644 --- a/src/main/java/com/torrent4j/strategy/TorrentDownloadStrategy.java +++ b/src/main/java/com/torrent4j/strategy/TorrentDownloadStrategy.java @@ -1,9 +1,9 @@ package com.torrent4j.strategy; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPiece; import com.torrent4j.model.TorrentPieceBlock; +import com.torrent4j.model.peer.TorrentPeer; /** * Determines the actions that should be taken regarding downloads diff --git a/src/main/java/com/torrent4j/strategy/TorrentPeerStrategy.java b/src/main/java/com/torrent4j/strategy/TorrentPeerStrategy.java index eab3962..4f0e512 100644 --- a/src/main/java/com/torrent4j/strategy/TorrentPeerStrategy.java +++ b/src/main/java/com/torrent4j/strategy/TorrentPeerStrategy.java @@ -1,8 +1,8 @@ package com.torrent4j.strategy; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPiece; +import com.torrent4j.model.peer.TorrentPeer; /** * Determine actions that the client should take regarding peers and their diff --git a/src/main/java/com/torrent4j/strategy/TorrentUploadStrategy.java b/src/main/java/com/torrent4j/strategy/TorrentUploadStrategy.java index 183cf3c..3dae96d 100644 --- a/src/main/java/com/torrent4j/strategy/TorrentUploadStrategy.java +++ b/src/main/java/com/torrent4j/strategy/TorrentUploadStrategy.java @@ -1,8 +1,8 @@ package com.torrent4j.strategy; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPieceBlock; +import com.torrent4j.model.peer.TorrentPeer; /** * Determines the actions that should be taken regarding uploads diff --git a/src/main/java/com/torrent4j/strategy/standard/PieceSelector.java b/src/main/java/com/torrent4j/strategy/standard/PieceSelector.java index 31670e4..3f961bd 100644 --- a/src/main/java/com/torrent4j/strategy/standard/PieceSelector.java +++ b/src/main/java/com/torrent4j/strategy/standard/PieceSelector.java @@ -1,7 +1,7 @@ package com.torrent4j.strategy.standard; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPiece; +import com.torrent4j.model.peer.TorrentPeer; /** * Selects an suitable piece for download @@ -13,6 +13,11 @@ public interface PieceSelector { * Applies an algorithm to determine the most suitable piece for download * from the peer. If no pieces are available or none are worth to download * from this peer, null should be returned. + *

+ * Also note that further interest decisions can be performed on the + * {@link StandardTorrentDownloadStrategy#blockReceived(com.torrent4j.model.Torrent, com.torrent4j.model.TorrentPieceBlock, TorrentPeer)} + * that can set to no interest even if this algorithm has interest into + * downloading an piece. * * @param peer * the peer to download the piece from diff --git a/src/main/java/com/torrent4j/strategy/standard/RandomPieceSelector.java b/src/main/java/com/torrent4j/strategy/standard/RandomPieceSelector.java index 556521a..c9e2981 100644 --- a/src/main/java/com/torrent4j/strategy/standard/RandomPieceSelector.java +++ b/src/main/java/com/torrent4j/strategy/standard/RandomPieceSelector.java @@ -2,8 +2,8 @@ package com.torrent4j.strategy.standard; import java.util.List; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPiece; +import com.torrent4j.model.peer.TorrentPeer; /** * Randomly selects an piece from the available peer pieces diff --git a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentDownloadStrategy.java b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentDownloadStrategy.java index f64de08..bb407c8 100644 --- a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentDownloadStrategy.java +++ b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentDownloadStrategy.java @@ -1,10 +1,10 @@ package com.torrent4j.strategy.standard; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPiece; import com.torrent4j.model.TorrentPieceBlock; import com.torrent4j.model.TorrentSwarm.SwarmBroadcastHandler; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.strategy.TorrentDownloadStrategy; public class StandardTorrentDownloadStrategy implements TorrentDownloadStrategy { diff --git a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentPeerStrategy.java b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentPeerStrategy.java index ed4c241..8c0063a 100644 --- a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentPeerStrategy.java +++ b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentPeerStrategy.java @@ -1,8 +1,8 @@ package com.torrent4j.strategy.standard; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPiece; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.strategy.TorrentPeerStrategy; public class StandardTorrentPeerStrategy implements TorrentPeerStrategy { diff --git a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentStrategy.java b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentStrategy.java index 7dfdd16..1af8ec7 100644 --- a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentStrategy.java +++ b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentStrategy.java @@ -3,7 +3,7 @@ package com.torrent4j.strategy.standard; import java.util.ArrayList; import java.util.List; -import com.torrent4j.model.TorrentPeer; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.strategy.TorrentDownloadStrategy; import com.torrent4j.strategy.TorrentPeerStrategy; import com.torrent4j.strategy.TorrentStrategy; diff --git a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentUploadStrategy.java b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentUploadStrategy.java index ed8aa61..6d937df 100644 --- a/src/main/java/com/torrent4j/strategy/standard/StandardTorrentUploadStrategy.java +++ b/src/main/java/com/torrent4j/strategy/standard/StandardTorrentUploadStrategy.java @@ -3,8 +3,8 @@ package com.torrent4j.strategy.standard; import java.io.IOException; import com.torrent4j.model.Torrent; -import com.torrent4j.model.TorrentPeer; import com.torrent4j.model.TorrentPieceBlock; +import com.torrent4j.model.peer.TorrentPeer; import com.torrent4j.storage.TorrentStorage; import com.torrent4j.strategy.TorrentUploadStrategy;