Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transmission download problem #206

Open
Hronom opened this issue Jul 22, 2017 · 0 comments
Open

Transmission download problem #206

Hronom opened this issue Jul 22, 2017 · 0 comments

Comments

@Hronom
Copy link

Hronom commented Jul 22, 2017

I've got the problem that, Transmission client able to download files from the torrent only when one of clients(ttorrent clients) downloading file(not in seed mode).
Please help, I need to seed to the Transmission clients.

Here is my Tracker code:

import com.turn.ttorrent.tracker.TrackedTorrent;
import com.turn.ttorrent.tracker.Tracker;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;

public class TtorrentServer {
    public static void main(String[] args)
        throws IOException, NoSuchAlgorithmException, InterruptedException {
        Tracker tracker = new Tracker(new InetSocketAddress(6969));
        FilenameFilter filter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".torrent");
            }
        };

        for (File f : new File(".").listFiles(filter)) {
            TrackedTorrent trackedTorrent = TrackedTorrent.load(f);
            tracker.announce(trackedTorrent);
        }
        tracker.start();
        Thread.sleep(TimeUnit.DAYS.toMillis(100));
        tracker.stop();
    }
}

Here is the code of master client:

import com.turn.ttorrent.client.Client;
import com.turn.ttorrent.client.SharedTorrent;
import com.turn.ttorrent.common.Torrent;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import static java.nio.file.StandardOpenOption.CREATE;

public class TtorrentClientMaster {
    public static void main(String[] args)
        throws IOException, NoSuchAlgorithmException, URISyntaxException, InterruptedException {
        ArrayList<File> files = new ArrayList<>();
        listf("files", files);
        Torrent torrent = SharedTorrent.create(
            new File("files"),
            files,
            new URI("http://0.0.0.0:6969/announce"),
            "Hronom"
        );
        try (OutputStream outputStream = Files.newOutputStream(Paths.get("files.torrent"), CREATE)) {
            torrent.save(outputStream);
        }
        
        Client client = new Client(null, new SharedTorrent(torrent, new File(".")));
        client.share();
        Thread.sleep(TimeUnit.DAYS.toMillis(100));
        client.stop();
    }

    public static void listf(String directoryName, ArrayList<File> files) throws IOException {
        File directory = new File(directoryName);

        // get all the files from a directory
        File[] fList = directory.listFiles();
        for (File file : fList) {
            if (file.isFile()) {
                files.add(file);
            } else if (file.isDirectory()) {
                listf(file.getPath(), files);
            }
        }
    }
}

Here is the code of my slave client:

import com.turn.ttorrent.client.Client;
import com.turn.ttorrent.client.SharedTorrent;
import com.turn.ttorrent.common.Torrent;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class TtorrentClientSlave1 {
    public static void main(String[] args)
        throws IOException, NoSuchAlgorithmException, URISyntaxException, InterruptedException {
        ArrayList<File> files = new ArrayList<>();
        SharedTorrent sharedTorrent =
            SharedTorrent.fromFile(new File("files.torrent"), new File("./output_torrent"));
        Client client = new Client(null, sharedTorrent);
        client.share();
        Thread.sleep(TimeUnit.DAYS.toMillis(100));
        client.stop();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant