Coder Social home page Coder Social logo

Comments (9)

aldenml avatar aldenml commented on July 18, 2024

Take a look at https://github.com/frostwire/frostwire-jlibtorrent/blob/master/src/main/java/com/frostwire/jlibtorrent/Session.java#L846

Create one for you (getSwig() is public) and add:
flags &= ~add_torrent_params.flags_t.seed_mode.swigValue();

I don't like a set of a java enum, but I will research how to improve the API in the java layer. We left getSwig() to allow for all sort of low level coding like this case.

from frostwire-jlibtorrent.

dessalines avatar dessalines commented on July 18, 2024

Thanks, this helps a lot.

from frostwire-jlibtorrent.

gubatron avatar gubatron commented on July 18, 2024

@tchoulihan
TIP: if you ever need to pass the getSwig() reference to another object, try passing a copy of it instead. It happens that the GC may leave you with an invalid reference which often leads to a crash.

from frostwire-jlibtorrent.

dessalines avatar dessalines commented on July 18, 2024

I'll keep this in mind.

from frostwire-jlibtorrent.

dessalines avatar dessalines commented on July 18, 2024

Sorry to ask about this again, but I'm trying to create a custom add_torrent method where by default, auto_manage is false, and seed_mode is true.

Setting the flags is confusing, because in the settings you appear to be doing bitwise inversions and ORs, instead of setting multiple flags.

Wouldn't this line in your code be turning off automanage, since its using ~(or invert bits)?
https://github.com/frostwire/frostwire-jlibtorrent/blob/master/src/main/java/com/frostwire/jlibtorrent/Session.java#L942

Would this be correct for me then?

// always set automanage to false
        add_torrent_params p = add_torrent_params.create_instance();
        TorrentInfo ti = new TorrentInfo(torrentFile);
        String savePath = outputParent.getAbsolutePath();
        p.setTi(ti.getSwig().copy());
        p.setSave_path(savePath);
        p.setStorage_mode(storage_mode_t.storage_mode_sparse);
        long flags = p.getFlags();
        if (saveResumeData.exists()) {
            byte[] data;
            try {
                data = Files.readAllBytes(Paths.get(saveResumeData.getAbsolutePath()));
                p.setResume_data(Vectors.bytes2char_vector(data));
                flags |= add_torrent_params.flags_t.flag_use_resume_save_path.swigValue();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        // Set seed mode
        if (seedMode) {
            flags &= ~add_torrent_params.flags_t.flag_seed_mode.swigValue();
        }

        // Turn off automanage
        flags &= add_torrent_params.flags_t.flag_auto_managed.swigValue(); 
        p.setFlags(flags);

        TorrentHandle torrent = new TorrentHandle(session.getSwig().add_torrent(p));

from frostwire-jlibtorrent.

gubatron avatar gubatron commented on July 18, 2024

yes, I believe the intention there is to turn off the automanage.

>>> f = 0b111
>>> f &= ~0b001
>>> bin(f)
'0b110' # bit is turned off
>>> f &= ~0b001
>>> bin(f)
'0b110' # bit remains turned off

from frostwire-jlibtorrent.

aldenml avatar aldenml commented on July 18, 2024

I think you can always call TorrentHandle::setAutoManaged, https://github.com/frostwire/frostwire-jlibtorrent/blob/master/src/main/java/com/frostwire/jlibtorrent/TorrentHandle.java#L297

from frostwire-jlibtorrent.

dessalines avatar dessalines commented on July 18, 2024

I just figured this out.
So I converted the long to a binary string, figured out which enum_flags_t were turned on by default.

Here are what the bits do:
http://libtorrent.org/reference-Session.html#add_torrent_params

It turns out auto_managed is turned on by default, so you have to do:
flags -= add_torrent_params.flags_t.flag_auto_managed.swigValue(); to turn it off.

And to turn on the others(that aren't already on by default), you can just add the swig values like so:
flags += add_torrent_params.flags_t.flag_seed_mode.swigValue();

Here are the default flags when you run p.getFlags():
default flags = 10001001110000

@aldenml , I actually needed to turn off automanage as I add the torrents, because if you try turning it off afterwards, libtorrent still might have paused them before it receives that message for some reason.

from frostwire-jlibtorrent.

gubatron avatar gubatron commented on July 18, 2024

It turns out auto_managed is turned on by default, so you have to do:
flags -= add_torrent_params.flags_t.flag_auto_managed.swigValue(); to turn it off.

yeah, which is what we do.

from frostwire-jlibtorrent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.