Don't return the announce response, it's not useful

Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>
Change AnnounceResponseListener interface

Modified the AnnounceResponseListener interface to get split parameters
for leechers, seeders, interval and peer list instead of the BEValue
map. This is in preparation of the upcoming implementation of UDP
tracker support, which uses a different, binary-based announce protocol.

This also allows for a great deal of simplification in the Client's code
when parsing peers, as this logic is moved in a simpler form into the
Announce class.

Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>
Start refactoring of announcers

In preparation for the implementation of UDP tracker support through a
different implementation of the Announce class, proceed to some code
refoctoring of the Announce class hierarchy.

Announce related stuff is now in its own subpackage
com.turn.ttorrent.client.announce. Announce is now a base abstract class
for announcers, and HTTPAnnounce implements the announcer to talk with
HTTP trackers.

Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>
Remove unused imports in Client class

Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>
Ignore more Eclipse stuff

Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>
Code style and Javadoc comments fixes

Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>
B-encoding tool suite improvements

Add a helper function to the BDecoder to decode directly from a
ByteBuffer instead of an InputStream (uses ByteArrayInputStream and an
AutoCloseInputStream to get an input stream from the ByteBuffer's
backing byte array).

Add a helper function to the BEncoder to encode directly into a
ByteBuffer instead of into an OutputStream (uses ByteArrayOutputStream
and ByteBuffer.wrap on the backing array of the output stream).

Add getShort() from a BEValue, returning the shortValue() from the
decoded Number.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Peer class improvements

Add a Peer constructor that only takes an IP address and a port number
to create a peer-ID-less peer.

Add a helper function that returns a formatted, short peer ID in the
form "..LAST_6_CHARS_OF_PEER_ID" that is used in various peer ID
outputs.

Add a getRawIp() method that returns the peer's IP address as a byte
array in network byte order.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Generic BitTorrent protocol message definitions

Separate BitTorrent protocol specific code into a common.protocol
package. The peer messages class gets moved there as PeerMessage.java,
and a new class describing and implementing the tracker messages is
created as TrackerMessage.java.

The TrackerMessage class currenty provides implementations for all HTTP
tracker protocol messages (announce request, announce response, error
response), with parsing and message crafting capabilities. UDP tracker
protocol messages implementation to follow.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Handle outbound peer connections with a thread pool executor

Use a thread pool executor to connect to remote peers instead of taping
the announce thread to initiate outbound connections (since that's where
the peer discovery event comes from). This allows for the announce
thread to be gracefully stopped without delay with the clients request
graceful exit, which in turns allow for the proper sending of a STOPPED
announce event to the tracker when the client exits.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Revamped announce framework and related client/tracker improvements

Finished the complete revamp of the client's announce framework. The
Announce class is now a base class for periodic announce mechanisms.
The HTTP announce protocol (and later, the UDP announce protocol) are
implemented as subclasses of this base Announce class, which
periodically calls the announce() method with the correct announce
event.

The base Announce class also sits as an AnnounceResponseListener to
automatically update its announce interval from the interval requested
in the announce response message from the tracker.

On the client's side, the handling of peer discovery and outbound peer
connections has been reviewed since the peers now come in as Peer
objects. The getOrCreatePeer() method as also been improved to correctly
keep track of inbound/outbound peer connections to avoid having two peer
exchanges, one inbound and one outbond, that reach the same remote peer
(because incoming peer connections come from a random, high-range port
number instead of the port number they announce).

Connection failures to new peers are also now correctly handled and
reported by the client with an appropriate warning message.

The HTTP announce protocol has been completely re-implemented on top of
this new announce framework, using the TrackerMessage tracker message
parsing/crafting abilities which ultimately makes the HTTPAnnounce class
much simpler.

This change also implements a main class for the Tracker, as well as the
ability to directly load TrackedTorrent without reparsing they b-encoded
metainfo structure twice, and more importantly a completely re-vamped
TrackerService that makes use of the TrackerMessage classes as well.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Throw MessageValidationException instead of a NPE when B-decoding fails

Correctly throw a MessageValidationException instead of a
NullPointerException when the B-decoding of a message's byte buffer
fails (most likely because the buffer is empty or because it doesn't
contain B-encoded data).

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Improved README file, with  Markdown syntax

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
More announcing improvements

Implement UDP announcer skeleton.

Implement a factory method Announce.getAnnounce() to get the correct
announcer based on the announce URL's protocol, and use it in the
Client.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Move HTTP tracker messages into the protocol.http package

Extract HTTP tracker message implementations into their own sub-package
at com.turn.ttorrent.common.protocol.http. Modify the HTTP announcer,
the Tracker code and clean-up TrackerMessage accordingly.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Start implementing the UDP tracker protocol messages

Implement the base UDPTrackerRequestMessage and
UDPTrackerResponseMessage classes and the UDPConnectRequestMessage.
Other message types to follow.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Continue working on UDP announcer skeleton

Refactored some code from HTTP announcer into Announce since it's not
protocol-specific and can thus be used by the UDP announcer directly.

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Add javadoc target to generate ttorrent's Javadocs

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Various code comment fixes to fix Javadoc warnings

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>
Improve Maven pom.xml

Signed-off-by: Maxime Petazzoni <mpetazzoni@turn.com>