|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.http.serve.Component
simple.http.load.Service
trackerBT.TrackerService
public class TrackerService
Service called to answer a peer requesting information about peers sharing a given torrent
Field Summary | |
---|---|
private static int |
DONE
|
private static int |
INTERNAL_ERROR
|
private static int |
MALFORMED_REQUEST
|
private static java.lang.String[] |
MESSAGE
|
private static int |
MISSING_DL
|
private static int |
MISSING_EVENT
|
private static int |
MISSING_FILEID
|
private static int |
MISSING_LEFT
|
private static int |
MISSING_PEERID
|
private static int |
MISSING_PORT
|
private static int |
MISSING_UL
|
(package private) org.jdom.Document |
peerList
|
private static int |
UNKNOWN_TORRENT
|
Fields inherited from class simple.http.load.Service |
---|
engine |
Fields inherited from class simple.http.serve.Component |
---|
context |
Constructor Summary | |
---|---|
TrackerService(simple.http.serve.Context context)
Default constructor for the tracker service, requested by the Simple server |
Method Summary | |
---|---|
private void |
cleanPeerList(org.jdom.Element root)
Cleans the peer list. |
private byte[] |
createAnswer(int err,
java.util.List l)
Encode the answer that will be sent to the peer. |
private boolean |
isNewTorrent(org.jdom.Element root,
java.lang.String hash)
Search if the torrent requested is registered to this tracker |
private java.util.HashMap |
parseURI(java.lang.String uri)
Method called to parse the Request URI and retrieve the parameters in it |
private java.util.List |
peerSharing(org.jdom.Element root,
java.lang.String hash,
java.lang.String peerid)
Returns the list of the peer currently sharing a given torrent |
void |
process(simple.http.Request req,
simple.http.Response resp)
Method called when a request is received at the tracker address It constructs the response message according to the parameters of the request. |
int |
processPeerList(java.util.Map param,
java.util.List peers)
Process the peer list according to the given parameters. |
private void |
registerPeer(org.jdom.Element root,
java.lang.String id,
java.lang.String ip,
java.lang.String port,
java.lang.String hash)
Register or update the remote peer in the local peer database, represented by a XML document |
private boolean |
torrentExists(java.lang.String id)
Look if the given torrent is already registered on this tracker |
Methods inherited from class simple.http.load.Service |
---|
prepare |
Methods inherited from class simple.http.serve.Component |
---|
handle, handle, handle, process, process |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int DONE
private static final int INTERNAL_ERROR
private static final int MALFORMED_REQUEST
private static final java.lang.String[] MESSAGE
private static final int MISSING_DL
private static final int MISSING_EVENT
private static final int MISSING_FILEID
private static final int MISSING_LEFT
private static final int MISSING_PEERID
private static final int MISSING_PORT
private static final int MISSING_UL
org.jdom.Document peerList
private static final int UNKNOWN_TORRENT
Constructor Detail |
---|
public TrackerService(simple.http.serve.Context context)
context
- Context that was provided to the Simple serverMethod Detail |
---|
private void cleanPeerList(org.jdom.Element root)
root
- The root of the XML document that represents the peers currently
sharing a file and announced to this trackerprivate byte[] createAnswer(int err, java.util.List l)
err
- Represent the status of the response. If different from 0, then
it means that an error occured and the response will be a message that
explains what goes wrong.
If equal to zero, then the answer a bencoded dictionary containing the peers
sharing the file, and contained in the List ll
- The list of peers sharing the file
private boolean isNewTorrent(org.jdom.Element root, java.lang.String hash)
root
- Root element of the XML document representing the torrents databasehash
- The SHA1 hash of the requested torrent, i.e. the torrent id
private java.util.HashMap parseURI(java.lang.String uri) throws java.io.UnsupportedEncodingException
uri
- The URI to be parsed
java.io.UnsupportedEncodingException
private java.util.List peerSharing(org.jdom.Element root, java.lang.String hash, java.lang.String peerid)
root
- Root element of the XML document representing the peer databasehash
- Id of the requested filepeerid
- Id of the peer
public void process(simple.http.Request req, simple.http.Response resp) throws java.io.IOException
process
in class simple.http.serve.Component
req
- Request message received from a peer with its parameters.
Parameters must be:
-- peer_id: the id of the peer that addresses the request
-- info_hash: the SHA1 hash of the torrent the peer is sharing and requesting
-- port: the port the peer is listening on
-- ip: (optional) the ip address of the peer
-- updated: total amount already uploaded by the peer
-- downloaded: total amount already downloaded by the peer
-- left: number of bytes left to complete download. O means peer is a seedresp
- Response message that will be constructed and returned.
The response is a bencoded dictionary containing the list of all peers currently sharing the file given in parameter
java.io.IOException
public int processPeerList(java.util.Map param, java.util.List peers)
param
- Parameters needed to process the peers list. Parameters must be:
info_hash, peer_id, port, ippeers
- List where all peers sharing the file will be returned.
private void registerPeer(org.jdom.Element root, java.lang.String id, java.lang.String ip, java.lang.String port, java.lang.String hash)
root
- The root element of the XML document representing the peer databaseid
- The id of the peerip
- The ip address of the peerport
- The listening port of the peerhash
- The file(s) that the peer is sharingprivate boolean torrentExists(java.lang.String id)
id
- The file id
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |