mpetazzoni / ttorrent

BitTorrent Java library with tracker and download client
http://mpetazzoni.github.com/ttorrent/
Apache License 2.0
1.38k stars 502 forks source link

SimpleClient download call is blocking [need info] #226

Closed asadsm closed 5 years ago

asadsm commented 5 years ago

Using the following code, based off of the code in the cli package. Code blocks on client.downloadTorrentAsync. Similar issue for client.downloadTorrentAsync despite the fact that the file is downloaded successfully. The torrents were created using code similar to what's given in cli package as well. Any ideas what I'm doing wrong here?

public static void main(String[] args) {
        ArrayList<String> torrentFiles = new ArrayList<>();
        Arrays.stream(args).filter(arg -> arg.contains(".torrent")).forEach(tor -> torrentFiles.add(tor));

        try {
            SimpleClient client = new SimpleClient();
            Inet4Address iPv4Address = getIPv4Address(null);
            for (String tor : torrentFiles) {
                System.out.println("Starting download for " + tor);
                client.downloadTorrentAsync(tor, "/home/scratch/test/torrent_test/", iPv4Address);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static Inet4Address getIPv4Address(String iface)
            throws SocketException, UnsupportedAddressTypeException,
            UnknownHostException {
        if (iface != null) {
            Enumeration<InetAddress> addresses =
                    NetworkInterface.getByName(iface).getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress addr = addresses.nextElement();
                if (addr instanceof Inet4Address) {
                    return (Inet4Address) addr;
                }
            }
        }

        InetAddress localhost = InetAddress.getLocalHost();
        if (localhost instanceof Inet4Address) {
            return (Inet4Address) localhost;
        }

        throw new UnsupportedAddressTypeException();
    }
asadsm commented 5 years ago

It seems to be stuck in the while loop in DigestBase

                while(var3 >= this.blockSize) {
                    this.implCompress(var1, var2);
                    var3 -= this.blockSize;
                    var2 += this.blockSize;
                }
Dead-off commented 5 years ago

Are you sure that code blocks on client.downloadTorrentAsync invocation? You don't stop simple client instance. Executor services are creating there and they will hold java process.

asadsm commented 5 years ago

Yes as I'm using a for loop to start download for all torrents passed in. It only outputs the first sout statement

Dead-off commented 5 years ago

DigestBase is a part of JRE. I think it works correctly:)

Then can you enable debug logging and provide logs? Just add this code at start main method for enable logging

BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("[%d{MMdd HH:mm:ss,SSS} %t] %6p - %20.20c - %m %n")));
    org.apache.log4j.Logger.getRootLogger().setLevel(Level.DEBUG);
asadsm commented 5 years ago

Well, I came in this morning and ran the code and it did not get stuck....very weird given I just pressed play on the IDE. I have no idea what happened...sorry for the trouble