mirror of
https://github.com/Rogiel/torrent4j
synced 2025-12-06 07:32:47 +00:00
Moved peer model related classes to com.torrent4j.model.peer
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
/.project
|
/.project
|
||||||
/.classpath
|
/.classpath
|
||||||
/.settings
|
/.settings
|
||||||
|
|
||||||
|
target/
|
||||||
|
test.torrent
|
||||||
@@ -6,7 +6,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
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.net.peerwire.PeerWireProtocol;
|
||||||
import com.torrent4j.storage.InMemoryTorrentStorage;
|
import com.torrent4j.storage.InMemoryTorrentStorage;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
public class TorrentSwarm {
|
public class TorrentSwarm {
|
||||||
private final Torrent torrent;
|
private final Torrent torrent;
|
||||||
private final List<TorrentPeer> peers = new ArrayList<>();
|
private final List<TorrentPeer> peers = new ArrayList<>();
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.torrent4j.model;
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import com.torrent4j.model.TorrentPeerState.TorrentPeerChoking;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeerState.TorrentPeerInterest;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
import com.torrent4j.net.TorrentProtocolPeer;
|
import com.torrent4j.net.TorrentProtocolPeer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,8 +81,8 @@ public class TorrentPeer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to detect the peer's client. If unknown, {@link TorrentPeerClient#UNKNOWN} is
|
* Tries to detect the peer's client. If unknown,
|
||||||
* returned.
|
* {@link TorrentPeerClient#UNKNOWN} is returned.
|
||||||
*
|
*
|
||||||
* @return the peer torrent client
|
* @return the peer torrent client
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +90,20 @@ public class TorrentPeer {
|
|||||||
return peerID.getClient();
|
return peerID.getClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <code>true</code> 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() {
|
public TorrentProtocolPeer getProtocolPeer() {
|
||||||
return protocolPeer;
|
return protocolPeer;
|
||||||
}
|
}
|
||||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* <p>
|
||||||
|
* 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.
|
||||||
|
* <p>
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the peer is choked or unchocked.
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
public enum TorrentPeerChoking {
|
||||||
|
CHOKED, UNCHOKED;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.torrent4j.model;
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of known torrent clients
|
* The list of known torrent clients
|
||||||
@@ -9,17 +9,17 @@ public enum TorrentPeerClient {
|
|||||||
/**
|
/**
|
||||||
* µTorrent for Mac (<strong>-UM</strong>)
|
* µTorrent for Mac (<strong>-UM</strong>)
|
||||||
*/
|
*/
|
||||||
UTORRENT_FOR_MAC("µTorrent for Mac", "-UM"),
|
UTORRENT_FOR_MAC("µTorrent for Mac", "-UM", true),
|
||||||
/**
|
/**
|
||||||
* µTorrent (<strong>-UT</strong>)
|
* µTorrent (<strong>-UT</strong>)
|
||||||
*/
|
*/
|
||||||
UTORRENT("µTorrent", "-UT"),
|
UTORRENT("µTorrent", "-UT", true),
|
||||||
/**
|
/**
|
||||||
* Transmission (<strong>-TR</strong>)
|
* Transmission (<strong>-TR</strong>)
|
||||||
*/
|
*/
|
||||||
TRANSMISSION("Transmission", "-TR"),
|
TRANSMISSION("Transmission", "-TR", true),
|
||||||
|
|
||||||
UNKNOWN("Unknown", "");
|
UNKNOWN("Unknown", "", false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An friendly name for the client. Can be used on an UI.
|
* 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
|
* The PeerID prefix for the client
|
||||||
*/
|
*/
|
||||||
public final String prefix;
|
public final String prefix;
|
||||||
|
/**
|
||||||
|
* Whether the PeerID has an version attribute
|
||||||
|
*/
|
||||||
|
public final boolean versioned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new enum value
|
* Initializes a new enum value
|
||||||
@@ -39,7 +43,24 @@ public enum TorrentPeerClient {
|
|||||||
* the PeerID prefix
|
* the PeerID prefix
|
||||||
*/
|
*/
|
||||||
private TorrentPeerClient(String friendlyName, String 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.friendlyName = friendlyName;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
|
this.versioned = versioned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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
|
* This ID represents an PeerID on the BitTorrent network
|
||||||
@@ -36,8 +38,8 @@ public class TorrentPeerID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to detect the peer's client. If unknown, {@link TorrentPeerClient#UNKNOWN} is
|
* Tries to detect the peer's client. If unknown,
|
||||||
* returned.
|
* {@link TorrentPeerClient#UNKNOWN} is returned.
|
||||||
*
|
*
|
||||||
* @return the peer torrent client
|
* @return the peer torrent client
|
||||||
*/
|
*/
|
||||||
@@ -51,6 +53,24 @@ public class TorrentPeerID {
|
|||||||
return TorrentPeerClient.UNKNOWN;
|
return TorrentPeerClient.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <code>true</code> 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
|
* @return the peer
|
||||||
*/
|
*/
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether there are interest on each other pieces
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
public enum TorrentPeerInterest {
|
||||||
|
INTERESTED, NOT_INTERESTED;
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.torrent4j.model;
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
|
import com.torrent4j.model.AbstractTorrentPiecesContainer;
|
||||||
|
|
||||||
|
|
||||||
public class TorrentPeerPieces extends AbstractTorrentPiecesContainer {
|
public class TorrentPeerPieces extends AbstractTorrentPiecesContainer {
|
||||||
private final TorrentPeer peer;
|
private final TorrentPeer peer;
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
package com.torrent4j.model;
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.torrent4j.model.Torrent;
|
||||||
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
|
|
||||||
public class TorrentPeerState {
|
public class TorrentPeerState {
|
||||||
private final TorrentPeer peer;
|
private final TorrentPeer peer;
|
||||||
|
|
||||||
private TorrentPeerInterest remoteInterest = TorrentPeerInterest.NOT_INTERESTED;
|
private TorrentPeerInterest remoteInterest = TorrentPeerInterest.NOT_INTERESTED;
|
||||||
private TorrentPeerInterest localInterest = TorrentPeerInterest.NOT_INTERESTED;
|
private TorrentPeerInterest localInterest = TorrentPeerInterest.NOT_INTERESTED;
|
||||||
|
|
||||||
public enum TorrentPeerInterest {
|
|
||||||
INTERESTED, NOT_INTERESTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TorrentPeerChoking remoteChoked = TorrentPeerChoking.CHOKED;
|
private TorrentPeerChoking remoteChoked = TorrentPeerChoking.CHOKED;
|
||||||
private TorrentPeerChoking locallyChoked = TorrentPeerChoking.CHOKED;
|
private TorrentPeerChoking locallyChoked = TorrentPeerChoking.CHOKED;
|
||||||
|
|
||||||
public enum TorrentPeerChoking {
|
|
||||||
CHOKED, UNCHOKED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TorrentPieceBlock downloadRequestedBlock;
|
private TorrentPieceBlock downloadRequestedBlock;
|
||||||
private Date downloadRequestedDate;
|
private Date downloadRequestedDate;
|
||||||
private TorrentPieceBlock lastDownloadedBlock;
|
private TorrentPieceBlock lastDownloadedBlock;
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
package com.torrent4j.model;
|
package com.torrent4j.model.peer;
|
||||||
|
|
||||||
|
import com.torrent4j.model.TorrentTrafficControl;
|
||||||
|
|
||||||
public class TorrentPeerTrafficControl extends TorrentTrafficControl {
|
public class TorrentPeerTrafficControl extends TorrentTrafficControl {
|
||||||
private final TorrentPeer peer;
|
private final TorrentPeer peer;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.torrent4j.net;
|
package com.torrent4j.net;
|
||||||
|
|
||||||
import com.torrent4j.TorrentController;
|
import com.torrent4j.TorrentController;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
public interface TorrentProtocol {
|
public interface TorrentProtocol {
|
||||||
void start(TorrentController controller, int listenPort);
|
void start(TorrentController controller, int listenPort);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
public interface TorrentProtocolPeer {
|
public interface TorrentProtocolPeer {
|
||||||
public TorrentPeer getTorrentPeer();
|
public TorrentPeer getTorrentPeer();
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import java.util.Date;
|
|||||||
|
|
||||||
import com.torrent4j.TorrentController;
|
import com.torrent4j.TorrentController;
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.model.TorrentPeerState.TorrentPeerChoking;
|
import com.torrent4j.model.peer.TorrentPeerChoking;
|
||||||
import com.torrent4j.model.TorrentPeerState.TorrentPeerInterest;
|
import com.torrent4j.model.peer.TorrentPeerInterest;
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
import com.torrent4j.model.TorrentPieceBlock;
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
import com.torrent4j.net.peerwire.codec.PeerWireFrameDecoder;
|
import com.torrent4j.net.peerwire.codec.PeerWireFrameDecoder;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import com.torrent4j.TorrentController;
|
import com.torrent4j.TorrentController;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.net.TorrentProtocol;
|
import com.torrent4j.net.TorrentProtocol;
|
||||||
|
|
||||||
public class PeerWireProtocol implements TorrentProtocol {
|
public class PeerWireProtocol implements TorrentProtocol {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
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.TorrentProtocolPeer;
|
||||||
import com.torrent4j.net.peerwire.messages.BitFieldMessage;
|
import com.torrent4j.net.peerwire.messages.BitFieldMessage;
|
||||||
import com.torrent4j.net.peerwire.messages.BlockMessage;
|
import com.torrent4j.net.peerwire.messages.BlockMessage;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import io.netty.handler.traffic.TrafficCounter;
|
|||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import com.torrent4j.model.TorrentPeer;
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.model.TorrentPeerTrafficControl;
|
import com.torrent4j.model.peer.TorrentPeerTrafficControl;
|
||||||
|
|
||||||
public class PeerTrafficShapingHandler extends ChannelTrafficShapingHandler {
|
public class PeerTrafficShapingHandler extends ChannelTrafficShapingHandler {
|
||||||
private long writeLimit;
|
private long writeLimit;
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import com.torrent4j.model.Torrent;
|
|||||||
import com.torrent4j.util.Range;
|
import com.torrent4j.util.Range;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An simple {@link TorrentStorage} implementation that stores data into huge
|
* An simple {@link TorrentStorage} implementation that stores data into a huge
|
||||||
* in-memory direct buffers. Please note that though it provides really fast
|
* in-memory direct buffer. Please note that though it provides really fast
|
||||||
* write and reading, it should not be used in real world implementations.
|
* 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
|
* Storing data in-memory consumes a lot of memory and may cause the JVM to be
|
||||||
* terminated by some OSes.
|
* terminated by some OSes.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.torrent4j.strategy;
|
package com.torrent4j.strategy;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
import com.torrent4j.model.TorrentPieceBlock;
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the actions that should be taken regarding downloads
|
* Determines the actions that should be taken regarding downloads
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.torrent4j.strategy;
|
package com.torrent4j.strategy;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine actions that the client should take regarding peers and their
|
* Determine actions that the client should take regarding peers and their
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.torrent4j.strategy;
|
package com.torrent4j.strategy;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPieceBlock;
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the actions that should be taken regarding uploads
|
* Determines the actions that should be taken regarding uploads
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.torrent4j.strategy.standard;
|
package com.torrent4j.strategy.standard;
|
||||||
|
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects an suitable piece for download
|
* Selects an suitable piece for download
|
||||||
@@ -13,6 +13,11 @@ public interface PieceSelector {
|
|||||||
* Applies an algorithm to determine the most suitable piece for download
|
* 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 the peer. If no pieces are available or none are worth to download
|
||||||
* from this peer, <code>null</code> should be returned.
|
* from this peer, <code>null</code> should be returned.
|
||||||
|
* <p>
|
||||||
|
* 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
|
* @param peer
|
||||||
* the peer to download the piece from
|
* the peer to download the piece from
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package com.torrent4j.strategy.standard;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Randomly selects an piece from the available peer pieces
|
* Randomly selects an piece from the available peer pieces
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.torrent4j.strategy.standard;
|
package com.torrent4j.strategy.standard;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
import com.torrent4j.model.TorrentPieceBlock;
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
import com.torrent4j.model.TorrentSwarm.SwarmBroadcastHandler;
|
import com.torrent4j.model.TorrentSwarm.SwarmBroadcastHandler;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.strategy.TorrentDownloadStrategy;
|
import com.torrent4j.strategy.TorrentDownloadStrategy;
|
||||||
|
|
||||||
public class StandardTorrentDownloadStrategy implements TorrentDownloadStrategy {
|
public class StandardTorrentDownloadStrategy implements TorrentDownloadStrategy {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.torrent4j.strategy.standard;
|
package com.torrent4j.strategy.standard;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPiece;
|
import com.torrent4j.model.TorrentPiece;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.strategy.TorrentPeerStrategy;
|
import com.torrent4j.strategy.TorrentPeerStrategy;
|
||||||
|
|
||||||
public class StandardTorrentPeerStrategy implements TorrentPeerStrategy {
|
public class StandardTorrentPeerStrategy implements TorrentPeerStrategy {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.torrent4j.strategy.standard;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.torrent4j.model.TorrentPeer;
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.strategy.TorrentDownloadStrategy;
|
import com.torrent4j.strategy.TorrentDownloadStrategy;
|
||||||
import com.torrent4j.strategy.TorrentPeerStrategy;
|
import com.torrent4j.strategy.TorrentPeerStrategy;
|
||||||
import com.torrent4j.strategy.TorrentStrategy;
|
import com.torrent4j.strategy.TorrentStrategy;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package com.torrent4j.strategy.standard;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.torrent4j.model.Torrent;
|
import com.torrent4j.model.Torrent;
|
||||||
import com.torrent4j.model.TorrentPeer;
|
|
||||||
import com.torrent4j.model.TorrentPieceBlock;
|
import com.torrent4j.model.TorrentPieceBlock;
|
||||||
|
import com.torrent4j.model.peer.TorrentPeer;
|
||||||
import com.torrent4j.storage.TorrentStorage;
|
import com.torrent4j.storage.TorrentStorage;
|
||||||
import com.torrent4j.strategy.TorrentUploadStrategy;
|
import com.torrent4j.strategy.TorrentUploadStrategy;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user