frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
446 stars 137 forks source link

ResumeData #178

Closed WhiteTrashLord closed 6 years ago

WhiteTrashLord commented 6 years ago

Hi :)

I am finally upgrading to version 1.2! Can you please fix SaveResumeDataAlert? The method resumeData() seems to be missing :(

I did not really check it, but your StatusDurationTest might fail because of a NullPointerException because of this.

com.frostwire.jlibtorrent.Hex

Please make this class public ;)

Some more functions to add torrents in the class SessionManager would be great. It seems I can only use the function download right now.

gubatron commented 6 years ago

not sure what you mean with the method resumeData() seems to be missing. (I guess things have changed quite a bit in this respect at the libtorrent layer and everything changed for us too)

The alert has a params() method that has the data (and a very helpful abstraction layer) you'd use to serialize.

This is how we use the alert on FrostWire for example:

    private void serializeResumeData(SaveResumeDataAlert alert) {
        try {
            if (th.isValid()) {
                String infoHash = th.infoHash().toString();
                File file = engine.resumeDataFile(infoHash);
                entry e = add_torrent_params.write_resume_data(alert.swig().getParams());
                e.dict().set(EXTRA_DATA_KEY, Entry.fromMap(extra).swig());
                FileUtils.writeByteArrayToFile(file, Vectors.byte_vector2bytes(e.bencode()));
            }
        } catch (Throwable e) {
            LOG.warn("Error saving resume data", e);
        }
    }

I think what you ask is beyond the scope of the library.

gubatron commented 6 years ago

Some more functions to add torrents in the class SessionManager would be great

what do you have in mind? can you share any proposals and why the current ones aren't sufficient?

aldenml commented 6 years ago

Hi @WhiteTrashLord the comment above is right, and the test StatusDurationTest is commented so that it's not running for now. Hex will be no public :), same for Files. Remember, there is SessionManager#swig() that give you full access to a near libtorrent API.

WhiteTrashLord commented 6 years ago

@gubatron

Thank you for your fast answer. But your code is not working here.

I miss something simple like this ( it was working in 1.1 ):

SaveResumeDataAlert srda = (SaveResumeDataAlert) alert; byte [] output = srda.resumeData().bencode();

@aldenml

I often use swig. In 1.1 I could create a sha1_hash from a HEX String with sha1_hash.from_hex. In 1.2 it's no longer possible. I have to use a Sha1Hash for this. But okay it's really not a big deal.

A TorrentAdd function in the SessionManager which returns a TorrentHandle might be useful. But currently I would not need it.

Is is quite simple to add a torrent in 1.2 in a paused state?

aldenml commented 6 years ago

paused state? SessionHandle#addTorrent should help you, but like download in SessionManager, I don't think so, but let me take a review and see if it makes sense to address some of your comments in the API

WhiteTrashLord commented 6 years ago

Okay, I just found SessionHandle. But SessionHandle not really used so much in your code. Is this class really necessary? I would like to have all this kind of functions in the SessionManager :)

WhiteTrashLord commented 6 years ago

Will this work?

SaveResumeDataAlert srda = (SaveResumeDataAlert) alert; entry e = add_torrent_params.write_resume_data(srda.swig().getParams());
byte [] output = Vectors.byte_vector2bytes(e.bencode());

Or do I need this?

e.dict().set(EXTRA_DATA_KEY, Entry.fromMap(extra).swig());

I don't know the content of this fields.