Skip to content

Commit

Permalink
Working in DHT with new SettingsPack API.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 26, 2015
1 parent fb4d500 commit 0ce7222
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/com/frostwire/jlibtorrent/DHT.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.frostwire.jlibtorrent.alerts.DhtImmutableItemAlert;
import com.frostwire.jlibtorrent.swig.char_vector;
import com.frostwire.jlibtorrent.swig.dht_item;
import com.frostwire.jlibtorrent.swig.settings_pack;
import com.frostwire.jlibtorrent.swig.sha1_hash;

import java.util.ArrayList;
Expand Down Expand Up @@ -32,11 +33,15 @@ public DHT(Session s) {
}

public void start() {
s.startDHT();
SettingsPack pack = new SettingsPack();
pack.setBoolean(settings_pack.bool_types.enable_dht.swigValue(), true);
s.applySettings(pack);
}

public void stop() {
s.stopDHT();
SettingsPack pack = new SettingsPack();
pack.setBoolean(settings_pack.bool_types.enable_dht.swigValue(), false);
s.applySettings(pack);

This comment has been minimized.

Copy link
@gubatron

gubatron Feb 26, 2015

Collaborator

DRY with private method

private void toggleDHT(boolean on) {
    SettingsPack pack = new SettingsPack();
    pack.setBoolean(settings_pack.bool_types.enable_dht.swigValue(), on);
    s.applySettings(pack);
}

public void start() {
    toggleDHT(true);
}

public void stop() {
    toggleDHT(false);
}

This comment has been minimized.

Copy link
@aldenml

aldenml Feb 26, 2015

Author Collaborator

Will do it (it was in my list)

}

public boolean isRunning() {
Expand Down
11 changes: 11 additions & 0 deletions src/com/frostwire/jlibtorrent/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ public void removeTorrent(TorrentHandle th) {
}
}

/**
* Applies the settings specified by the settings_pack ``sp``. This is an
* asynchronous operation that will return immediately and actually apply
* the settings to the main thread of libtorrent some time later.
*
* @param sp
*/
public void applySettings(SettingsPack sp) {
s.apply_settings(sp.getSwig());
}

/**
* In case you want to destruct the session asynchrounously, you can
* request a session destruction proxy. If you don't do this, the
Expand Down
37 changes: 37 additions & 0 deletions src/com/frostwire/jlibtorrent/SettingsPack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.frostwire.jlibtorrent;

import com.frostwire.jlibtorrent.swig.settings_pack;

/**
* The ``settings_pack`` struct, contains the names of all settings as
* enum values. These values are passed in to the ``set_str()``,
* ``set_int()``, ``set_bool()`` functions, to specify the setting to
* change.
*
* @author gubatron
* @author aldenml
*/
public final class SettingsPack {

private final settings_pack sp;

public SettingsPack(settings_pack sp) {
this.sp = sp;
}

public SettingsPack() {
this(new settings_pack());
}

public settings_pack getSwig() {
return sp;
}

public boolean getBoolean(int name) {
return sp.get_bool(name);
}

public void setBoolean(int name, boolean value) {
sp.set_bool(name, value);
}
}
6 changes: 3 additions & 3 deletions src/com/frostwire/jlibtorrent/TorrentHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,9 @@ public void removeHttpSeed(String url) {
// IPv4 or IPv6 address). When specifying multiple interfaces, the
// torrent will round-robin which interface to use for each outgoing
// conneciton. This is useful for clients that are multi-homed.
public void useInterface(String netInterface) {
th.use_interface(netInterface);
}
// public void useInterface(String netInterface) {
// th.use_interface(netInterface);
// }

// Fills the specified ``std::vector<int>`` with the availability for
// each piece in this torrent. libtorrent does not keep track of
Expand Down

0 comments on commit 0ce7222

Please sign in to comment.