Difference between revisions of "ECF BitTorrent Provider"

From Eclipsepedia

Jump to: navigation, search
m (org.eclipse.bittorrent)
(Plug-in Usage)
Line 70: Line 70:
 
# - '''LATER''' start a download from a torrent and alter the number of connections that can be made
 
# - '''LATER''' start a download from a torrent and alter the number of connections that can be made
  
 +
The use cases listed below makes use of an implementation of the ITorrentStateListener interface. All references to ''stateListener'' can be referred back to the implementation provided below.
 +
 +
ITorrentStateListener stateListener = new ITorrentStateListener() {
 +
    public void stateChanged(int state) {
 +
        switch (state) {
 +
        case ITorrentStateListener.STARTED:
 +
            System.out.println("The torrent set-up is starting...");
 +
            break;
 +
        case ITorrentStateListener.DOWNLOADING:
 +
            System.out.println("The downloading has begun...");
 +
            break;
 +
        case ITorrentStateListener.PAUSED:
 +
            System.out.println("The downloading has been paused...");
 +
            break;
 +
        case ITorrentStateListener.FINISHED:
 +
            System.out.println("The download is now complete...");
 +
            break;
 +
        }
 +
    }
 +
};
  
 
'''Use Case 1''' - download a torrent's contents to completion
 
'''Use Case 1''' - download a torrent's contents to completion
Line 75: Line 95:
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host = new Host(torrent);
 
  Host host = new Host(torrent);
  host.start();
+
  host.start(stateListener);
  
 
'''Use Case 2''' - stop the download after a period of time
 
'''Use Case 2''' - stop the download after a period of time
Line 81: Line 101:
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host = new Host(torrent);
 
  Host host = new Host(torrent);
  host.start();
+
  host.start(stateListener);
 
  // after some amount of time has passed
 
  // after some amount of time has passed
 
  host.stop();
 
  host.stop();
Line 89: Line 109:
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host = new Host(torrent);
 
  Host host = new Host(torrent);
  host.start();
+
  host.start(stateListener);
 
  // after some amount of time has passed
 
  // after some amount of time has passed
 
  host.pause();
 
  host.pause();
Line 99: Line 119:
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host = new Host(torrent);
 
  Host host = new Host(torrent);
  host.start();
+
  host.start(stateListener);
 
  // after some amount of time has passed
 
  // after some amount of time has passed
 
  host.stop();
 
  host.stop();
Line 108: Line 128:
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent");
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent");
 
  Host host01 = new Host(torrent01);
 
  Host host01 = new Host(torrent01);
  host.start();
+
  host.start(stateListener);
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
 
  Host host02 = new Host(torrent02);
 
  Host host02 = new Host(torrent02);
  host.start();
+
  host.start(stateListener);
  
 
'''Use Case 4''' - start downloading two different torrents and pause one of them after a period of time
 
'''Use Case 4''' - start downloading two different torrents and pause one of them after a period of time
Line 117: Line 137:
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host01 = new Host(torrent01);
 
  Host host01 = new Host(torrent01);
  host01.start();
+
  host01.start(stateListener);
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
 
  Host host02 = new Host(torrent02);
 
  Host host02 = new Host(torrent02);
  host02.start();
+
  host02.start(stateListener);
 
  // some time passes
 
  // some time passes
 
  host02.pause();
 
  host02.pause();
Line 128: Line 148:
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host01 = new Host(torrent01);
 
  Host host01 = new Host(torrent01);
  host01.start();
+
  host01.start(stateListener);
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
 
  Host host02 = new Host(torrent02);
 
  Host host02 = new Host(torrent02);
  host02.start();
+
  host02.start(stateListener);
 
  // some time passes
 
  // some time passes
 
  host02.pause();
 
  host02.pause();
Line 141: Line 161:
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host01 = new Host(torrent01);
 
  Host host01 = new Host(torrent01);
  host01.start();
+
  host01.start(stateListener);
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Torrent torrent02 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
 
  Host host02 = new Host(torrent02);
 
  Host host02 = new Host(torrent02);
  host02.start();
+
  host02.start(stateListener);
 
  // some time passes
 
  // some time passes
 
  host02.pause();
 
  host02.pause();

Revision as of 21:24, 7 June 2006

Project Lead: Remy Chi Jian Suen

Mentor(s): Wayne Beaton, Scott Lewis, and Chris Aniszczyk

The goal if this project is to create an implementation of the file sharing API provided by the Eclipse Communication Framework using the BitTorrent protocol.

Contents

BitTorrent Plug-in Data Model

The package name org.eclipse.bittorrent may be altered when the plug-in is released.

Text in red denotes that the code has not been written yet.

org.eclipse.bittorrent

Host - reads in a Torrent connects to peers to begin seeding or downloading

  • contains exactly one Torrent
  • contains one or more DataFiles
  • contains one or more Pieces

Torrent - a representation of the metainfo stored within a .torrent file

ITorrentStateListener - reports what state the download is in right now, such as whether it is 'downloading' or 'completed'

ITorrentProgressListener - monitors how far the download has gone

IPieceProgressListener - monitors the download progress of a particular piece

org.eclipse.bittorrent.internal.torrent

DataFile - a representation of a file on the user's system for read/write operations

  • contains one or more Pieces

Piece - a piece of data that is needed to complete a download

  • contains one or more DataFiles


org.eclipse.bittorrent.internal.net

ConnectionPool - a thread pool that manages ConnectionThreads

  • contains exactly one Host
  • contains one or more ConnectionThreads

ConnectionThread - creates a PeerConnection to talk to a peer

  • contains exactly one PeerConnection

PeerConnection - connects to a peer and exchanges information

  • exactly one Host


org.eclipse.bittorrent.internal.encode

BEncodedDictionary - holds the key-value pairs stored within a bencoded string.

Decode - decodes information such as the contents of a torrent file

Encode - converts or alters information for use


Plug-in Usage

This section will describe how a developer would create a client using the BitTorrent plug-in.

Use Cases

  1. - downloads a single file from a torrent until completion
  2. - begin downloading a single file from a torrent and pause the download after a period of time
    1. - resume the download
    2. - cancel the download and delete the downloaded files
  3. - start two downloads from two torrents until completion
  4. - begin two downloads from two torrent and then pause the second one after a period of time
    1. - resume the second download after the first has completed
    2. - cancel the first download and start the second download
  5. - begin downloading from a torrent and monitor its progress with a listener
  6. - LATER start downloading multiple files from a torrent and select which files should be downloaded
  7. - LATER begin downloading a file from a torrent and cap the download/upload speeds
  8. - LATER start a download from a torrent and alter the number of connections that can be made

The use cases listed below makes use of an implementation of the ITorrentStateListener interface. All references to stateListener can be referred back to the implementation provided below.

ITorrentStateListener stateListener = new ITorrentStateListener() {
    public void stateChanged(int state) {
        switch (state) {
        case ITorrentStateListener.STARTED:
            System.out.println("The torrent set-up is starting...");
            break;
        case ITorrentStateListener.DOWNLOADING:
            System.out.println("The downloading has begun...");
            break;
        case ITorrentStateListener.PAUSED:
            System.out.println("The downloading has been paused...");
            break;
        case ITorrentStateListener.FINISHED:
            System.out.println("The download is now complete...");
            break;
        }
    }
};

Use Case 1 - download a torrent's contents to completion

Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host = new Host(torrent);
host.start(stateListener);

Use Case 2 - stop the download after a period of time

Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host = new Host(torrent);
host.start(stateListener);
// after some amount of time has passed
host.stop();

Use Case 2.1 - resume downloading a torrent after pausing it for a period of time

Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host = new Host(torrent);
host.start(stateListener);
// after some amount of time has passed
host.pause();
// more time passes
host.resume();

Use Case 2.2 - start a download and then stop it and remove all downloaded files

Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host = new Host(torrent);
host.start(stateListener);
// after some amount of time has passed
host.stop();
host.remove();

Use Case 3 - begin downloading from two different torrents until completion

Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent");
Host host01 = new Host(torrent01);
host.start(stateListener);
Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
Host host02 = new Host(torrent02);
host.start(stateListener);

Use Case 4 - start downloading two different torrents and pause one of them after a period of time

Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host01 = new Host(torrent01);
host01.start(stateListener);
Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
Host host02 = new Host(torrent02);
host02.start(stateListener);
// some time passes
host02.pause();

Use Case 4.1 - resume downloading the second torrent after the first has finished

Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host01 = new Host(torrent01);
host01.start(stateListener);
Torrent torrent02 = new Torrent(new FileInputStream("eclipse-ecf.torrent"));
Host host02 = new Host(torrent02);
host02.start(stateListener);
// some time passes
host02.pause();
while (!host01.isCompleted());
host02.resume();

Use Case 4.2 - cancel the first download and resume the second download

Torrent torrent01 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host01 = new Host(torrent01);
host01.start(stateListener);
Torrent torrent02 = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host02 = new Host(torrent02);
host02.start(stateListener);
// some time passes
host02.pause();
// more time passes
host01.stop();
host02.resume();

Use Case 5 - begin downloading from a torrent and monitor its progress with a listener

Torrent torrent = new Torrent(new FileInputStream("eclipse-sdk.torrent"));
Host host = new Host(torrent);
host.addProgressListener(new ProgressListener() {
    public void progressEvent(ProgressEvent event) {
        System.out.println(event.getRemaining());
    }
});

External Links

Eclipse Communication Framework Website

BitTorrent Specification