Skip to content

Commit

Permalink
Better Session constructor to be able to use IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 24, 2016
1 parent dfccbac commit 4df7c76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/main/java/com/frostwire/jlibtorrent/Session.java
Expand Up @@ -84,8 +84,17 @@ public Session() {
this(new SettingsPack(), false, null);
}

public Session(String ip, int port, boolean logging, AlertListener listener) {
this(createSettings(ip, port), logging, listener);
/**
* This constructor allow you to specify the listen interfaces in the
* same format libtorrent accepts. Like for example, IPv4+IPv6 in the
* first available port: "0.0.0.0:0,[::]:0"
*
* @param interfaces
* @param logging
* @param listener
*/
public Session(String interfaces, boolean logging, AlertListener listener) {
this(createSettings(interfaces), logging, listener);
}

public session getSwig() {
Expand Down Expand Up @@ -1075,11 +1084,10 @@ private static session createSession(SettingsPack settings, boolean logging) {
return new session(sp);
}

private static SettingsPack createSettings(String ip, int port) {
private static SettingsPack createSettings(String interfaces) {
settings_pack sp = new settings_pack();

String iface = String.format("%s:%d", ip, port);
sp.set_str(settings_pack.string_types.listen_interfaces.swigValue(), iface);
sp.set_str(settings_pack.string_types.listen_interfaces.swigValue(), interfaces);

return new SettingsPack(sp);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/frostwire/jlibtorrent/demo/DhtShell.java
Expand Up @@ -50,7 +50,7 @@ public void alert(Alert<?> alert) {
}
};

Session s = new Session("0.0.0.0", 0, false, mainListener);
Session s = new Session("0.0.0.0:0,[::]:0", false, mainListener);
DHT dht = new DHT(s);
Downloader downloader = new Downloader(s);

Expand Down

0 comments on commit 4df7c76

Please sign in to comment.