This commit is contained in:
Thomas 2021-02-02 18:03:24 +01:00
parent 70e8133350
commit f120d8fad5
120 changed files with 5286 additions and 15171 deletions

View File

@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.1.2'
def nav_version = "2.3.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

View File

@ -30,7 +30,7 @@ before_install:
- export BOOST_ROOT=$PWD/boost_1_73_0
- export BOOST_BUILD_PATH=$BOOST_ROOT
# openssl: download
# openssl: download
- wget -nv -O openssl.tar.gz https://www.openssl.org/source/openssl-1.1.1i.tar.gz
- tar xzf openssl.tar.gz
- export OPENSSL_SOURCE=$PWD/openssl-1.1.1i

View File

@ -22,20 +22,6 @@ repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
tasks.withType(Test) {
systemProperty "java.library.path", "."
}
test {
testLogging {
events "passed", "skipped", "failed", "standard_out"
}
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -56,42 +56,6 @@ public final class AddTorrentParams {
this(add_torrent_params.create_instance());
}
/**
* @return an instance with the default storage
*/
public static AddTorrentParams createInstance() {
return new AddTorrentParams(add_torrent_params.create_instance());
}
/**
* @return an instance with a disabled storage
*/
public static AddTorrentParams createInstanceDisabledStorage() {
return new AddTorrentParams(add_torrent_params.create_instance_disabled_storage());
}
/**
* @return an instance with a zero storage
*/
public static AddTorrentParams createInstanceZeroStorage() {
return new AddTorrentParams(add_torrent_params.create_instance_zero_storage());
}
/**
* Helper function to parse a magnet uri and fill the parameters.
*
* @param uri the magnet uri
* @return the params object filled with the data from the magnet
*/
public static AddTorrentParams parseMagnetUri(String uri) {
error_code ec = new error_code();
add_torrent_params params = add_torrent_params.parse_magnet_uri(uri, ec);
if (ec.value() != 0) {
throw new IllegalArgumentException("Invalid magnet uri: " + ec.message());
}
return new AddTorrentParams(params);
}
/**
* @return the native object
*/
@ -539,4 +503,40 @@ public final class AddTorrentParams {
p.set_banned_peers(v);
}
/**
* @return an instance with the default storage
*/
public static AddTorrentParams createInstance() {
return new AddTorrentParams(add_torrent_params.create_instance());
}
/**
* @return an instance with a disabled storage
*/
public static AddTorrentParams createInstanceDisabledStorage() {
return new AddTorrentParams(add_torrent_params.create_instance_disabled_storage());
}
/**
* @return an instance with a zero storage
*/
public static AddTorrentParams createInstanceZeroStorage() {
return new AddTorrentParams(add_torrent_params.create_instance_zero_storage());
}
/**
* Helper function to parse a magnet uri and fill the parameters.
*
* @param uri the magnet uri
* @return the params object filled with the data from the magnet
*/
public static AddTorrentParams parseMagnetUri(String uri) {
error_code ec = new error_code();
add_torrent_params params = add_torrent_params.parse_magnet_uri(uri, ec);
if (ec.value() != 0) {
throw new IllegalArgumentException("Invalid magnet uri: " + ec.message());
}
return new AddTorrentParams(params);
}
}

View File

@ -39,15 +39,6 @@ public final class Address implements Comparable<Address>, Cloneable {
this(new address());
}
static String toString(address a) {
error_code ec = new error_code();
String s = a.to_string(ec);
if (ec.value() != 0) {
s = "<invalid address>";
}
return s;
}
/**
* @return native object
*/
@ -125,4 +116,13 @@ public final class Address implements Comparable<Address>, Cloneable {
public Address clone() {
return new Address(new address(addr));
}
static String toString(address a) {
error_code ec = new error_code();
String s = a.to_string(ec);
if (ec.value() != 0) {
s = "<invalid address>";
}
return s;
}
}

View File

@ -16,6 +16,17 @@ final class AlertMulticaster implements AlertListener {
this.b = b;
}
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
a.alert(alert);
b.alert(alert);
}
public static AlertListener add(AlertListener a, AlertListener b) {
return addInternal(a, b);
}
@ -24,6 +35,17 @@ final class AlertMulticaster implements AlertListener {
return removeInternal(l, oldl);
}
private AlertListener remove(AlertListener oldl) {
if (oldl == a) return b;
if (oldl == b) return a;
AlertListener a2 = removeInternal(a, oldl);
AlertListener b2 = removeInternal(b, oldl);
if (a2 == a && b2 == b) {
return this; // it's not here
}
return addInternal(a2, b2);
}
private static AlertListener addInternal(AlertListener a, AlertListener b) {
if (a == null) return b;
if (b == null) return a;
@ -39,26 +61,4 @@ final class AlertMulticaster implements AlertListener {
return l; // it's not here
}
}
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
a.alert(alert);
b.alert(alert);
}
private AlertListener remove(AlertListener oldl) {
if (oldl == a) return b;
if (oldl == b) return a;
AlertListener a2 = removeInternal(a, oldl);
AlertListener b2 = removeInternal(b, oldl);
if (a2 == a && b2 == b) {
return this; // it's not here
}
return addInternal(a2, b2);
}
}

View File

@ -31,19 +31,6 @@ public final class BDecodeNode {
this.buffer = buffer;
}
public static BDecodeNode bdecode(byte[] data) {
byte_vector buffer = Vectors.bytes2byte_vector(data);
bdecode_node n = new bdecode_node();
error_code ec = new error_code();
int ret = bdecode_node.bdecode(buffer, n, ec);
if (ret == 0) {
return new BDecodeNode(n, buffer);
} else {
throw new IllegalArgumentException("Can't decode data: " + ec.message());
}
}
/**
* @return the native object
*/
@ -73,4 +60,17 @@ public final class BDecodeNode {
public String toString() {
return bdecode_node.to_string(n, false, 2);
}
public static BDecodeNode bdecode(byte[] data) {
byte_vector buffer = Vectors.bytes2byte_vector(data);
bdecode_node n = new bdecode_node();
error_code ec = new error_code();
int ret = bdecode_node.bdecode(buffer, n, ec);
if (ret == 0) {
return new BDecodeNode(n, buffer);
} else {
throw new IllegalArgumentException("Can't decode data: " + ec.message());
}
}
}

View File

@ -105,12 +105,19 @@ public final class BlockInfo {
*/
UNKNOWN(-1);
private final int swigValue;
BlockState(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the state
@ -124,12 +131,5 @@ public final class BlockInfo {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -38,6 +38,35 @@ public final class Entry {
this(new entry(n));
}
public entry swig() {
return e;
}
public byte[] bencode() {
return Vectors.byte_vector2bytes(e.bencode());
}
public String string() {
return e.string();
}
public long integer() {
return e.integer();
}
public List<Entry> list() {
return new EntryList(e.list());
}
public Map<String, Entry> dictionary() {
return new EntryMap(e.dict());
}
@Override
public String toString() {
return e.to_string();
}
public static Entry bdecode(byte[] data) {
return new Entry(entry.bdecode(Vectors.bytes2byte_vector(data)));
}
@ -99,35 +128,6 @@ public final class Entry {
return new Entry(e);
}
public entry swig() {
return e;
}
public byte[] bencode() {
return Vectors.byte_vector2bytes(e.bencode());
}
public String string() {
return e.string();
}
public long integer() {
return e.integer();
}
public List<Entry> list() {
return new EntryList(e.list());
}
public Map<String, Entry> dictionary() {
return new EntryMap(e.dict());
}
@Override
public String toString() {
return e.to_string();
}
private static final class EntryList extends AbstractList<Entry> {
private final entry_vector v;

View File

@ -58,7 +58,7 @@ public final class EnumNet {
}
public static Address getGateway(SessionManager session, IpInterface ipInterface, ip_route_vector routes) {
return new Address(libtorrent.get_gateway(ipInterface.swig(), routes));
return new Address(libtorrent.get_gateway(ipInterface.swig(), routes));
}
public static final class IpInterface {

View File

@ -20,29 +20,6 @@ import java.util.ArrayList;
*/
public final class FileStorage {
/**
* This file is a pad file. The creator of the
* torrent promises the file is entirely filled with
* zeroes and does not need to be downloaded. The
* purpose is just to align the next file to either
* a block or piece boundary.
*/
public static final file_flags_t FLAG_PAD_FILE = file_storage.flag_pad_file;
/**
* This file is hidden (sets the hidden attribute
* on windows).
*/
public static final file_flags_t FLAG_HIDDEN = file_storage.flag_hidden;
/**
* This file is executable (sets the executable bit
* on posix like systems).
*/
public static final file_flags_t FLAG_EXECUTABLE = file_storage.flag_executable;
/**
* This file is a symlink. The symlink target is
* specified in a separate field
*/
public static final file_flags_t FLAG_SYMLINK = file_storage.flag_symlink;
private final file_storage fs;
private final torrent_info ti;
@ -64,17 +41,6 @@ public final class FileStorage {
this.ti = ti;
}
static ArrayList<FileSlice> mapBlock(file_slice_vector v) {
int size = (int) v.size();
ArrayList<FileSlice> l = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
l.add(new FileSlice(v.get(i)));
}
return l;
}
/**
* @return the native object
*/
@ -436,6 +402,33 @@ public final class FileStorage {
return l;
}
/**
* This file is a pad file. The creator of the
* torrent promises the file is entirely filled with
* zeroes and does not need to be downloaded. The
* purpose is just to align the next file to either
* a block or piece boundary.
*/
public static final file_flags_t FLAG_PAD_FILE = file_storage.flag_pad_file;
/**
* This file is hidden (sets the hidden attribute
* on windows).
*/
public static final file_flags_t FLAG_HIDDEN = file_storage.flag_hidden;
/**
* This file is executable (sets the executable bit
* on posix like systems).
*/
public static final file_flags_t FLAG_EXECUTABLE = file_storage.flag_executable;
/**
* This file is a symlink. The symlink target is
* specified in a separate field
*/
public static final file_flags_t FLAG_SYMLINK = file_storage.flag_symlink;
/**
* Returns a bitmask of flags from {@link file_flags_t} that apply
* to file at {@code index}.
@ -468,4 +461,15 @@ public final class FileStorage {
public int fileIndexAtOffset(long offset) {
return fs.file_index_at_offset(offset);
}
static ArrayList<FileSlice> mapBlock(file_slice_vector v) {
int size = (int) v.size();
ArrayList<FileSlice> l = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
l.add(new FileSlice(v.get(i)));
}
return l;
}
}

View File

@ -26,11 +26,11 @@ import java.io.InputStream;
final class Files {
private static final int EOF = -1;
private Files() {
}
private static final int EOF = -1;
/**
* Reads the contents of a file into a byte array.
* The file is always closed.

View File

@ -22,15 +22,15 @@ package com.frostwire.jlibtorrent;
*/
final class Hex {
private Hex() {
}
/**
* Used to build output as Hex
*/
private static final char[] DIGITS_LOWER =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private Hex() {
}
/**
* Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The
* returned array will be half the length of the passed array, as it takes two characters to represent any given
@ -66,7 +66,8 @@ final class Hex {
* The returned array will be double the length of the passed array, as it takes two characters to represent any
* given byte.
*
* @param data a byte[] to convert to Hex characters
* @param data
* a byte[] to convert to Hex characters
* @return A char[] containing hexadecimal characters
*/
public static String encode(final byte[] data) {
@ -78,8 +79,10 @@ final class Hex {
* The returned array will be double the length of the passed array, as it takes two characters to represent any
* given byte.
*
* @param data a byte[] to convert to Hex characters
* @param toDigits the output alphabet
* @param data
* a byte[] to convert to Hex characters
* @param toDigits
* the output alphabet
* @return A char[] containing hexadecimal characters
* @since 1.4
*/
@ -97,8 +100,10 @@ final class Hex {
/**
* Converts a hexadecimal character to an integer.
*
* @param ch A character to convert to an integer digit
* @param index The index of the character in the source
* @param ch
* A character to convert to an integer digit
* @param index
* The index of the character in the source
* @return An integer
*/
private static int toDigit(final char ch, final int index) {

View File

@ -34,12 +34,19 @@ public enum MoveFlags {
*/
DONT_REPLACE(move_flags_t.dont_replace);
private final move_flags_t swigValue;
MoveFlags(move_flags_t swigValue) {
this.swigValue = swigValue;
}
private final move_flags_t swigValue;
/**
* @return the native value
*/
public move_flags_t swig() {
return swigValue;
}
/**
* @param swigValue the native value
*/
@ -52,11 +59,4 @@ public enum MoveFlags {
}
throw new IllegalArgumentException("Enum value not supported");
}
/**
* @return the native value
*/
public move_flags_t swig() {
return swigValue;
}
}

View File

@ -209,12 +209,27 @@ public enum Operation {
*/
HOSTNAME_LOOKUP(operation_t.hostname_lookup.swigValue());
private final int swigValue;
Operation(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value.
*/
public int swig() {
return swigValue;
}
public String nativeName() {
try {
return libtorrent.operation_name(operation_t.swigToEnum(swigValue));
} catch (Throwable e) {
return "invalid enum value";
}
}
/**
* @param swigValue the native value
* @return the swig enum.
@ -236,19 +251,4 @@ public enum Operation {
public static Operation fromSwig(operation_t swigValue) {
return fromSwig(swigValue.swigValue());
}
/**
* @return the native value.
*/
public int swig() {
return swigValue;
}
public String nativeName() {
try {
return libtorrent.operation_name(operation_t.swigToEnum(swigValue));
} catch (Throwable e) {
return "invalid enum value";
}
}
}

View File

@ -11,15 +11,6 @@ import com.frostwire.jlibtorrent.swig.string_string_pair;
*/
public final class Pair<T1, T2> {
/**
* the first element
*/
public final T1 first;
/**
* the second element
*/
public final T2 second;
/**
* @param first first element
* @param second second element
@ -29,6 +20,16 @@ public final class Pair<T1, T2> {
this.second = second;
}
/**
* the first element
*/
public final T1 first;
/**
* the second element
*/
public final T2 second;
/**
* @return a native object
*/

View File

@ -188,12 +188,19 @@ public class PeerInfo {
*/
UNKNOWN(-1);
private final int swigValue;
ConnectionType(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the swig value
* @return the enum value
@ -207,12 +214,5 @@ public class PeerInfo {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -14,12 +14,16 @@ public enum PortmapProtocol {
UDP(portmap_protocol.udp.swigValue());
private final int swigValue;
PortmapProtocol(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
public int swig() {
return swigValue;
}
public static PortmapProtocol fromSwig(int swigValue) {
PortmapProtocol[] enumValues = PortmapProtocol.class.getEnumConstants();
for (PortmapProtocol ev : enumValues) {
@ -29,8 +33,4 @@ public enum PortmapProtocol {
}
throw new IllegalArgumentException("No enum " + PortmapProtocol.class + " with value " + swigValue);
}
public int swig() {
return swigValue;
}
}

View File

@ -12,12 +12,16 @@ public enum PortmapTransport {
UPNP(portmap_transport.upnp.swigValue());
private final int swigValue;
PortmapTransport(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
public int swig() {
return swigValue;
}
public static PortmapTransport fromSwig(int swigValue) {
PortmapTransport[] enumValues = PortmapTransport.class.getEnumConstants();
for (PortmapTransport ev : enumValues) {
@ -27,8 +31,4 @@ public enum PortmapTransport {
}
throw new IllegalArgumentException("No enum " + PortmapTransport.class + " with value " + swigValue);
}
public int swig() {
return swigValue;
}
}

View File

@ -52,12 +52,19 @@ public enum Priority {
*/
SEVEN(7);
private final int swigValue;
Priority(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the enum corresponding value
@ -103,11 +110,4 @@ public enum Priority {
return v;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}

View File

@ -37,43 +37,8 @@ import java.util.List;
*/
public class SessionHandle {
/**
* When set, the session will start paused. Call SessionHandle::resume() to start
*/
public static final session_flags_t PAUSED = session_handle.paused;
/**
* Saves settings (i.e. the {@link SettingsPack}).
*/
public static final save_state_flags_t SAVE_SETTINGS = session_handle.save_settings;
/**
* Saves {@link DhtSettings}.
*/
public static final save_state_flags_t SAVE_DHT_SETTINGS = session_handle.save_dht_settings;
/**
* Saves dht state such as nodes and node-id, possibly accelerating
* joining the DHT if provided at next session startup.
*/
public static final save_state_flags_t SAVE_DHT_STATE = session_handle.save_dht_state;
/**
* Delete the files belonging to the torrent from disk,
* including the part-file, if there is one.
*/
public static final remove_flags_t DELETE_FILES = session_handle.delete_files;
/**
* Delete just the part-file associated with this torrent.
*/
public static final remove_flags_t DELETE_PARTFILE = session_handle.delete_partfile;
/**
* This option indicates if the ports are mapped using natpmp
* and UPnP. If mapping was already made, they are deleted and added
* again. This only works if natpmp and/or upnp are configured to be
* enable.
*/
public static final reopen_network_flags_t REOPEN_MAP_PORTS = session_handle.reopen_map_ports;
public static final int DHT_ANNOUNCE_SEED = 1;
public static final int DHT_ANNOUNCE_IMPLIED_PORT = 1 << 1;
public static final int DHT_ANNOUNCE_SSL_TORRENT = 1 << 2;
private static final Logger LOG = Logger.getLogger(SessionHandle.class);
protected final session_handle s;
/**
@ -94,6 +59,27 @@ public class SessionHandle {
return s.is_valid();
}
/**
* When set, the session will start paused. Call SessionHandle::resume() to start
*/
public static final session_flags_t PAUSED = session_handle.paused;
/**
* Saves settings (i.e. the {@link SettingsPack}).
*/
public static final save_state_flags_t SAVE_SETTINGS = session_handle.save_settings;
/**
* Saves {@link DhtSettings}.
*/
public static final save_state_flags_t SAVE_DHT_SETTINGS = session_handle.save_dht_settings;
/**
* Saves dht state such as nodes and node-id, possibly accelerating
* joining the DHT if provided at next session startup.
*/
public static final save_state_flags_t SAVE_DHT_STATE = session_handle.save_dht_state;
/**
* Loads and saves all session settings, including dht settings,
* encryption settings and proxy settings. This method
@ -288,6 +274,17 @@ public class SessionHandle {
s.async_add_torrent(params.swig());
}
/**
* Delete the files belonging to the torrent from disk,
* including the part-file, if there is one.
*/
public static final remove_flags_t DELETE_FILES = session_handle.delete_files;
/**
* Delete just the part-file associated with this torrent.
*/
public static final remove_flags_t DELETE_PARTFILE = session_handle.delete_partfile;
/**
* This method will close all peer connections associated with the torrent and tell the
* tracker that we've stopped participating in the swarm. This operation cannot fail.
@ -307,6 +304,17 @@ public class SessionHandle {
}
}
/**
* This option indicates if the ports are mapped using natpmp
* and UPnP. If mapping was already made, they are deleted and added
* again. This only works if natpmp and/or upnp are configured to be
* enable.
*/
public static final reopen_network_flags_t REOPEN_MAP_PORTS = session_handle.reopen_map_ports;
public static final int DHT_ANNOUNCE_SEED = 1;
public static final int DHT_ANNOUNCE_IMPLIED_PORT = 1 << 1;
public static final int DHT_ANNOUNCE_SSL_TORRENT = 1 << 2;
// starts/stops UPnP, NATPMP or LSD port mappers they are stopped by
// default These functions are not available in case
// ``TORRENT_DISABLE_DHT`` is defined. ``start_dht`` starts the dht node
@ -346,42 +354,6 @@ public class SessionHandle {
// and false
// otherwise.
/**
* This method will close all peer connections associated with the torrent and tell the
* tracker that we've stopped participating in the swarm. This operation cannot fail.
* When it completes, you will receive a torrent_removed_alert.
*
* @param th
*/
public void removeTorrent(TorrentHandle th) {
if (th.isValid()) {
s.remove_torrent(th.swig());
}
}
/**
* Pausing the session has the same effect as pausing every torrent in
* it, except that torrents will not be resumed by the auto-manage
* mechanism.
*/
public void pause() {
s.pause();
}
/**
* Resuming will restore the torrents to their previous paused
* state. i.e. the session pause state is separate from the torrent pause
* state. A torrent is inactive if it is paused or if the session is
* paused.
*/
public void resume() {
s.resume();
}
public boolean isPaused() {
return s.is_paused();
}
void setDhtSettings(DhtSettings settings) {
s.set_dht_settings(settings.swig());
}
@ -447,6 +419,19 @@ public class SessionHandle {
s.delete_port_mapping(handle);
}
/**
* This method will close all peer connections associated with the torrent and tell the
* tracker that we've stopped participating in the swarm. This operation cannot fail.
* When it completes, you will receive a torrent_removed_alert.
*
* @param th
*/
public void removeTorrent(TorrentHandle th) {
if (th.isValid()) {
s.remove_torrent(th.swig());
}
}
/**
* Instructs the session to reopen all listen and outgoing sockets.
* <p>
@ -562,6 +547,29 @@ public class SessionHandle {
s.dht_get_peers(infoHash.swig());
}
/**
* Pausing the session has the same effect as pausing every torrent in
* it, except that torrents will not be resumed by the auto-manage
* mechanism.
*/
public void pause() {
s.pause();
}
/**
* Resuming will restore the torrents to their previous paused
* state. i.e. the session pause state is separate from the torrent pause
* state. A torrent is inactive if it is paused or if the session is
* paused.
*/
public void resume() {
s.resume();
}
public boolean isPaused() {
return s.is_paused();
}
/**
* @param infoHash
* @param port

View File

@ -73,11 +73,13 @@ public class SessionManager {
private final ReentrantLock sync;
private final ReentrantLock syncMagnet;
private final SessionStats stats;
private final Map<String, String> listenEndpoints;
private volatile session session;
private final SessionStats stats;
private long lastStatsRequestTime;
private boolean firewalled;
private volatile session session;
private String externalAddress;
private int externalPort;
private Thread alertsLoop;
@ -103,40 +105,6 @@ public class SessionManager {
this(false);
}
private static alert_category_t alertMask(boolean logging) {
alert_category_t mask = alert.all_categories;
if (!logging) {
alert_category_t log_mask = alert.session_log_notification;
log_mask = log_mask.or_(alert.torrent_log_notification);
log_mask = log_mask.or_(alert.peer_log_notification);
log_mask = log_mask.or_(alert.dht_log_notification);
log_mask = log_mask.or_(alert.port_mapping_log_notification);
log_mask = log_mask.or_(alert.picker_log_notification);
mask = mask.and_(log_mask.inv());
}
return mask;
}
private static String dhtBootstrapNodes() {
StringBuilder sb = new StringBuilder();
sb.append("dht.libtorrent.org:25401").append(",");
sb.append("router.bittorrent.com:6881").append(",");
sb.append("router.utorrent.com:6881").append(",");
sb.append("dht.transmissionbt.com:6881").append(",");
// for DHT IPv6
sb.append("router.silotis.us:6881");
return sb.toString();
}
private static boolean isSpecialType(int type) {
return type == AlertType.SESSION_STATS.swig() ||
type == AlertType.STATE_UPDATE.swig() ||
type == AlertType.SESSION_STATS_HEADER.swig();
}
public session swig() {
return session;
}
@ -158,49 +126,19 @@ public class SessionManager {
start(params, null);
}
/**
* @param params
* @param flags You can pass a flag like SessionHandle.PAUSED to start the session paused.
*/
public void start(SessionParams params, session_flags_t flags) {
if (session != null) {
return;
}
sync.lock();
try {
if (session != null) {
return;
}
onBeforeStart();
resetState();
params.settings().setInteger(settings_pack.int_types.alert_mask.swigValue(), alertMask(logging).to_int());
sessionParams = params;
if (flags == null) {
session = new session(params.swig());
} else {
session = new session(params.swig(), flags);
}
alertsLoop();
// block all connections to port < 1024, but
// allows 80 and 443 for web seeds
port_filter f = new port_filter();
f.add_rule(0, 79, 1);
f.add_rule(81, 442, 1);
f.add_rule(444, 1023, 1);
session.set_port_filter(f);
onAfterStart();
} finally {
sync.unlock();
private static alert_category_t alertMask(boolean logging) {
alert_category_t mask = alert.all_categories;
if (!logging) {
alert_category_t log_mask = alert.session_log_notification;
log_mask = log_mask.or_(alert.torrent_log_notification);
log_mask = log_mask.or_(alert.peer_log_notification);
log_mask = log_mask.or_(alert.dht_log_notification);
log_mask = log_mask.or_(alert.port_mapping_log_notification);
log_mask = log_mask.or_(alert.picker_log_notification);
mask = mask.and_(log_mask.inv());
}
return mask;
}
public void start() {
@ -323,10 +261,6 @@ public class SessionManager {
return stats.dhtNodes();
}
//--------------------------------------------------
// Settings methods
//--------------------------------------------------
public boolean isFirewalled() {
return firewalled;
}
@ -339,6 +273,10 @@ public class SessionManager {
return new ArrayList<>(listenEndpoints.values());
}
//--------------------------------------------------
// Settings methods
//--------------------------------------------------
/**
* Returns a setting pack with all the settings
* the current session is working with.
@ -441,10 +379,6 @@ public class SessionManager {
return settings().maxPeerlistSize();
}
//--------------------------------------------------
// more methods
//--------------------------------------------------
public void maxPeers(int limit) {
if (session == null) {
return;
@ -466,6 +400,10 @@ public class SessionManager {
applySettings(new SettingsPack().listenInterfaces(value));
}
//--------------------------------------------------
// more methods
//--------------------------------------------------
/**
* This function will post a {@link SessionStatsAlert} object, containing a
* snapshot of the performance counters from the internals of libtorrent.
@ -1197,6 +1135,70 @@ public class SessionManager {
return name != null && name.contains(FETCH_MAGNET_DOWNLOAD_KEY);
}
private static String dhtBootstrapNodes() {
StringBuilder sb = new StringBuilder();
sb.append("dht.libtorrent.org:25401").append(",");
sb.append("router.bittorrent.com:6881").append(",");
sb.append("router.utorrent.com:6881").append(",");
sb.append("dht.transmissionbt.com:6881").append(",");
// for DHT IPv6
sb.append("router.silotis.us:6881");
return sb.toString();
}
private static boolean isSpecialType(int type) {
return type == AlertType.SESSION_STATS.swig() ||
type == AlertType.STATE_UPDATE.swig() ||
type == AlertType.SESSION_STATS_HEADER.swig();
}
/**
* @param params
* @param flags You can pass a flag like SessionHandle.PAUSED to start the session paused.
*/
public void start(SessionParams params, session_flags_t flags) {
if (session != null) {
return;
}
sync.lock();
try {
if (session != null) {
return;
}
onBeforeStart();
resetState();
params.settings().setInteger(settings_pack.int_types.alert_mask.swigValue(), alertMask(logging).to_int());
sessionParams = params;
if (flags == null) {
session = new session(params.swig());
} else {
session = new session(params.swig(), flags);
}
alertsLoop();
// block all connections to port < 1024, but
// allows 80 and 443 for web seeds
port_filter f = new port_filter();
f.add_rule(0, 79, 1);
f.add_rule(81, 442, 1);
f.add_rule(444, 1023, 1);
session.set_port_filter(f);
onAfterStart();
} finally {
sync.unlock();
}
}
private void alertsLoop() {
Runnable r = new Runnable() {
@Override
@ -1286,14 +1288,14 @@ public class SessionManager {
public static final class MutableItem {
public final Entry item;
public final byte[] signature;
public final long seq;
private MutableItem(Entry item, byte[] signature, long seq) {
this.item = item;
this.signature = signature;
this.seq = seq;
}
public final Entry item;
public final byte[] signature;
public final long seq;
}
}

View File

@ -52,39 +52,6 @@ public final class Sha1Hash implements Comparable<Sha1Hash>, Cloneable {
this(new sha1_hash());
}
/**
* returns an all-F sha1-hash. i.e. the maximum value
* representable by a 160 bit number (20 bytes). This is
* a static member function.
*
* @return the maximum number
*/
public static Sha1Hash max() {
return new Sha1Hash(sha1_hash.max());
}
/**
* returns an all-zero sha1-hash. i.e. the minimum value
* representable by a 160 bit number (20 bytes). This is
* a static member function.
*
* @return the minimum number (zero)
*/
public static Sha1Hash min() {
return new Sha1Hash(sha1_hash.min());
}
static ArrayList<Sha1Hash> convert(sha1_hash_vector v) {
int size = (int) v.size();
ArrayList<Sha1Hash> l = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
l.add(new Sha1Hash(v.get(i)));
}
return l;
}
/**
* @return the native object
*/
@ -171,4 +138,37 @@ public final class Sha1Hash implements Comparable<Sha1Hash>, Cloneable {
public Sha1Hash clone() {
return new Sha1Hash(new sha1_hash(h));
}
/**
* returns an all-F sha1-hash. i.e. the maximum value
* representable by a 160 bit number (20 bytes). This is
* a static member function.
*
* @return the maximum number
*/
public static Sha1Hash max() {
return new Sha1Hash(sha1_hash.max());
}
/**
* returns an all-zero sha1-hash. i.e. the minimum value
* representable by a 160 bit number (20 bytes). This is
* a static member function.
*
* @return the minimum number (zero)
*/
public static Sha1Hash min() {
return new Sha1Hash(sha1_hash.min());
}
static ArrayList<Sha1Hash> convert(sha1_hash_vector v) {
int size = (int) v.size();
ArrayList<Sha1Hash> l = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
l.add(new Sha1Hash(v.get(i)));
}
return l;
}
}

View File

@ -30,9 +30,6 @@ public final class StatsMetric {
public static final int TYPE_COUNTER = metric_type_t.counter.swigValue();
public static final int TYPE_GAUGE = metric_type_t.gauge.swigValue();
public final String name;
public final int valueIndex;
public final int type;
StatsMetric(stats_metric sm) {
this.name = sm.get_name();
@ -40,6 +37,12 @@ public final class StatsMetric {
this.type = sm.getType().swigValue();
}
public final String name;
public final int valueIndex;
public final int type;
@Override
public String toString() {
return name + ":" + valueIndex + ":" + typeStr();

View File

@ -28,12 +28,19 @@ public enum StorageMode {
*/
UNKNOWN(-1);
private final int swigValue;
StorageMode(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the java enum
@ -47,11 +54,4 @@ public enum StorageMode {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}

View File

@ -22,6 +22,14 @@ import static com.frostwire.jlibtorrent.swig.libtorrent.set_piece_hashes_ex;
*/
public final class TorrentBuilder {
private File path;
private int pieceSize;
private int padFileLimit;
private create_flags_t flags;
private int alignment;
private String comment;
private String creator;
/**
* This will insert pad files to align the files to piece boundaries, for
* optimized disk-I/O. This will minimize the number of bytes of pad-
@ -55,6 +63,7 @@ public final class TorrentBuilder {
* symlinks.
*/
public static final create_flags_t SYMLINKS = create_torrent.symlinks;
private boolean priv;
/**
* To create a torrent that can be updated via a *mutable torrent*
* (see BEP38_). This also needs to be enabled for torrents that update
@ -64,19 +73,7 @@ public final class TorrentBuilder {
*/
public static final create_flags_t MUTABLE_TORRENT_SUPPORT = create_torrent.mutable_torrent_support;
private final List<String> urlSeeds;
private final List<String> httpSeeds;
private final List<Pair<String, Integer>> nodes;
private final List<Pair<String, Integer>> trackers;
private final List<Sha1Hash> similarTorrents;
private final List<String> collections;
private File path;
private int pieceSize;
private int padFileLimit;
private create_flags_t flags;
private int alignment;
private String comment;
private String creator;
private boolean priv;
private Listener listener;
public TorrentBuilder() {
@ -586,6 +583,12 @@ public final class TorrentBuilder {
return new Result(t);
}
private final List<String> httpSeeds;
private final List<Pair<String, Integer>> nodes;
private final List<Pair<String, Integer>> trackers;
private final List<Sha1Hash> similarTorrents;
private final List<String> collections;
/**
*
*/

View File

@ -9,6 +9,11 @@ import com.frostwire.jlibtorrent.swig.torrent_flags_t;
*/
public final class TorrentFlags {
/**
* Set this flag to disable peer exchange for this torrent.
*/
public static final torrent_flags_t DISABLE_PEX = libtorrent.getDisable_pex();
// If ``seed_mode`` is set, libtorrent will assume that all files
// are present for this torrent and that they all match the hashes in
// the torrent file. Each time a peer requests to download a block,
@ -25,6 +30,7 @@ public final class TorrentFlags {
// If resume data is passed in with this torrent, the seed mode saved
// in there will override the seed mode you set here.
public static final torrent_flags_t SEED_MODE = libtorrent.getSeed_mode();
// If ``upload_mode`` is set, the torrent will be initialized in
// upload-mode, which means it will not make any piece requests. This
// state is typically entered on disk I/O errors, and if the torrent
@ -40,6 +46,7 @@ public final class TorrentFlags {
// got there. If it's important to manually control when the torrent
// leaves upload mode, don't make it auto managed.
public static final torrent_flags_t UPLOAD_MODE = libtorrent.getUpload_mode();
// determines if the torrent should be added in *share mode* or not.
// Share mode indicates that we are not interested in downloading the
// torrent, but merely want to improve our share ratio (i.e. increase
@ -59,18 +66,21 @@ public final class TorrentFlags {
// The share mode has one setting, the share ratio target, see
// ``settings_pack::share_mode_target`` for more info.
public static final torrent_flags_t SHARE_MODE = libtorrent.getShare_mode();
// determines if the IP filter should apply to this torrent or not. By
// default all torrents are subject to filtering by the IP filter
// (i.e. this flag is set by default). This is useful if certain
// torrents needs to be exempt for some reason, being an auto-update
// torrent for instance.
public static final torrent_flags_t APPLY_IP_FILTER = libtorrent.getApply_ip_filter();
// specifies whether or not the torrent is to be started in a paused
// state. I.e. it won't connect to the tracker or any of the peers
// until it's resumed. This is typically a good way of avoiding race
// conditions when setting configuration options on torrents before
// starting them.
public static final torrent_flags_t PAUSED = libtorrent.getPaused();
// If the torrent is auto-managed (``auto_managed``), the torrent
// may be resumed at any point, regardless of how it paused. If it's
// important to manually control when the torrent is paused and
@ -88,18 +98,22 @@ public final class TorrentFlags {
// ``override_resume_data``.
public static final torrent_flags_t AUTO_MANAGED = libtorrent.getAuto_managed();
public static final torrent_flags_t DUPLICATE_IS_ERROR = libtorrent.getDuplicate_is_error();
// on by default and means that this torrent will be part of state
// updates when calling post_torrent_updates().
public static final torrent_flags_t UPDATE_SUBSCRIBE = libtorrent.getUpdate_subscribe();
// sets the torrent into super seeding mode. If the torrent is not a
// seed, this flag has no effect. It has the same effect as calling
// ``torrent_handle::super_seeding(true)`` on the torrent handle
// immediately after adding it.
public static final torrent_flags_t SUPER_SEEDING = libtorrent.getSuper_seeding();
// sets the sequential download state for the torrent. It has the same
// effect as calling ``torrent_handle::sequential_download(true)`` on
// the torrent handle immediately after adding it.
public static final torrent_flags_t SEQUENTIAL_DOWNLOAD = libtorrent.getSequential_download();
// When this flag is set, the
// torrent will *force stop* whenever it transitions from a
// non-data-transferring state into a data-transferring state (referred to
@ -130,16 +144,19 @@ public final class TorrentFlags {
// will most likely start in between posting the alert and receiving the
// call to pause.
public static final torrent_flags_t STOP_WHEN_READY = libtorrent.getStop_when_ready();
// when this flag is set, the tracker list in the add_torrent_params
// object override any trackers from the torrent file. If the flag is
// not set, the trackers from the add_torrent_params object will be
// added to the list of trackers used by the torrent.
public static final torrent_flags_t OVERRIDE_TRACKERS = libtorrent.getOverride_trackers();
// If this flag is set, the web seeds from the add_torrent_params
// object will override any web seeds in the torrent file. If it's not
// set, web seeds in the add_torrent_params object will be added to the
// list of web seeds used by the torrent.
public static final torrent_flags_t OVERRIDE_WEB_SEEDS = libtorrent.getOverride_web_seeds();
/**
* If this flag is set (which it is by default) the torrent will be
* considered needing to save its resume data immediately as it's
@ -147,6 +164,7 @@ public final class TorrentFlags {
* This flag is cleared by a successful call to save_resume_data()
*/
public static final torrent_flags_t NEED_SAVE_RESUME = libtorrent.getNeed_save_resume();
/**
* Set this flag to disable DHT for this torrent. This lets you have the DHT
* enabled for the whole client, and still have specific torrents not
@ -154,16 +172,14 @@ public final class TorrentFlags {
* from it.
*/
public static final torrent_flags_t DISABLE_DHT = libtorrent.getDisable_dht();
/**
* Set this flag to disable local service discovery for this torrent.
*/
public static final torrent_flags_t DISABLE_LSD = libtorrent.getDisable_lsd();
/**
* Set this flag to disable peer exchange for this torrent.
*/
public static final torrent_flags_t DISABLE_PEX = libtorrent.getDisable_pex();
public static final torrent_flags_t ALL = libtorrent.getAll();
private TorrentFlags() {
}
public static final torrent_flags_t ALL = libtorrent.getAll();
}

View File

@ -53,84 +53,12 @@ import java.util.List;
*/
public final class TorrentHandle {
/**
* Instruct libtorrent to overwrite any data that may already have been
* downloaded with the data of the new piece being added.
*/
public static final add_piece_flags_t OVERWRITE_EXISTING = torrent_handle.overwrite_existing;
/**
* calculates ``distributed_copies``, ``distributed_full_copies`` and
* ``distributed_fraction``.
*/
public static final status_flags_t QUERY_DISTRIBUTED_COPIES = torrent_handle.query_distributed_copies;
/**
* includes partial downloaded blocks in ``total_done`` and
* ``total_wanted_done``.
*/
public static final status_flags_t QUERY_ACCURATE_DOWNLOAD_COUNTERS = torrent_handle.query_accurate_download_counters;
/**
* includes ``last_seen_complete``.
*/
public static final status_flags_t QUERY_LAST_SEEN_COMPLETE = torrent_handle.query_last_seen_complete;
/**
* includes ``pieces``.
*/
public static final status_flags_t QUERY_PIECES = torrent_handle.query_pieces;
/**
* includes ``verified_pieces`` (only applies to torrents in *seed mode*).
*/
public static final status_flags_t QUERY_VERIFIED_PIECES = torrent_handle.query_verified_pieces;
/**
* includes ``torrent_file``, which is all the static information from the .torrent file.
*/
public static final status_flags_t QUERY_TORRENT_FILE = torrent_handle.query_torrent_file;
/**
* includes {@code name}, the name of the torrent. This is either derived
* from the .torrent file, or from the {@code &dn=} magnet link argument
* or possibly some other source. If the name of the torrent is not
* known, this is an empty string.
*/
public static final status_flags_t QUERY_NAME = torrent_handle.query_name;
/**
* includes ``save_path``, the path to the directory the files of the
* torrent are saved to.
*/
public static final status_flags_t QUERY_SAVE_PATH = torrent_handle.query_save_path;
/**
* The disk cache will be flushed before creating the resume data.
* This avoids a problem with file timestamps in the resume data in
* case the cache hasn't been flushed yet.
*/
public static final resume_data_flags_t FLUSH_DISK_CACHE = torrent_handle.flush_disk_cache;
/**
* The resume data will contain the metadata from the torrent file as
* well. This is default for any torrent that's added without a
* torrent file (such as a magnet link or a URL).
*/
public static final resume_data_flags_t SAVE_INFO_DICT = torrent_handle.save_info_dict;
/**
* If nothing significant has changed in the torrent since the last
* time resume data was saved, fail this attempt. Significant changes
* primarily include more data having been downloaded, file or piece
* priorities having changed etc. If the resume data doesn't need
* saving, a save_resume_data_failed_alert is posted with the error
* resume_data_not_modified.
*/
public static final resume_data_flags_t ONLY_IF_MODIFIED = torrent_handle.only_if_modified;
/**
* By default, force-reannounce will still honor the min-interval
* published by the tracker. If this flag is set, it will be ignored
* and the tracker is announced immediately.
*/
public static final reannounce_flags_t IGNORE_MIN_INTERVAL = torrent_handle.ignore_min_interval;
/**
*
*/
public static final deadline_flags_t ALERT_WHEN_AVAILABLE = torrent_handle.alert_when_available;
private static final long REQUEST_STATUS_RESOLUTION_MILLIS = 500;
// cache this zero flag for performance reasons
private static final status_flags_t STATUS_FLAGS_ZERO = new status_flags_t();
private final torrent_handle th;
private long lastStatusRequestTime;
private TorrentStatus lastStatus;
@ -145,6 +73,12 @@ public final class TorrentHandle {
return th;
}
/**
* Instruct libtorrent to overwrite any data that may already have been
* downloaded with the data of the new piece being added.
*/
public static final add_piece_flags_t OVERWRITE_EXISTING = torrent_handle.overwrite_existing;
/**
* This function will write {@code data} to the storage as piece {@code piece},
* as if it had been downloaded from a peer. {@code data} is expected to
@ -302,6 +236,52 @@ public final class TorrentHandle {
return status(false);
}
/**
* calculates ``distributed_copies``, ``distributed_full_copies`` and
* ``distributed_fraction``.
*/
public static final status_flags_t QUERY_DISTRIBUTED_COPIES = torrent_handle.query_distributed_copies;
/**
* includes partial downloaded blocks in ``total_done`` and
* ``total_wanted_done``.
*/
public static final status_flags_t QUERY_ACCURATE_DOWNLOAD_COUNTERS = torrent_handle.query_accurate_download_counters;
/**
* includes ``last_seen_complete``.
*/
public static final status_flags_t QUERY_LAST_SEEN_COMPLETE = torrent_handle.query_last_seen_complete;
/**
* includes ``pieces``.
*/
public static final status_flags_t QUERY_PIECES = torrent_handle.query_pieces;
/**
* includes ``verified_pieces`` (only applies to torrents in *seed mode*).
*/
public static final status_flags_t QUERY_VERIFIED_PIECES = torrent_handle.query_verified_pieces;
/**
* includes ``torrent_file``, which is all the static information from the .torrent file.
*/
public static final status_flags_t QUERY_TORRENT_FILE = torrent_handle.query_torrent_file;
/**
* includes {@code name}, the name of the torrent. This is either derived
* from the .torrent file, or from the {@code &dn=} magnet link argument
* or possibly some other source. If the name of the torrent is not
* known, this is an empty string.
*/
public static final status_flags_t QUERY_NAME = torrent_handle.query_name;
/**
* includes ``save_path``, the path to the directory the files of the
* torrent are saved to.
*/
public static final status_flags_t QUERY_SAVE_PATH = torrent_handle.query_save_path;
/**
* This method returns an up to date torrent status, the {@code flags} parameters
* is an or-combination of the {@link status_flags_t} native values, in case you want
@ -349,7 +329,6 @@ public final class TorrentHandle {
/**
* Note that this is a blocking function, unlike torrent_handle::is_valid() which returns immediately.
*
* @return Returns true if the torrent is in the session. It returns true before SessionHandle::removeTorrent() is called, and false afterward.
*/
public boolean inSession() {
@ -593,6 +572,30 @@ public final class TorrentHandle {
th.set_ssl_certificate_buffer2(cert, pk, dh);
}
/**
* The disk cache will be flushed before creating the resume data.
* This avoids a problem with file timestamps in the resume data in
* case the cache hasn't been flushed yet.
*/
public static final resume_data_flags_t FLUSH_DISK_CACHE = torrent_handle.flush_disk_cache;
/**
* The resume data will contain the metadata from the torrent file as
* well. This is default for any torrent that's added without a
* torrent file (such as a magnet link or a URL).
*/
public static final resume_data_flags_t SAVE_INFO_DICT = torrent_handle.save_info_dict;
/**
* If nothing significant has changed in the torrent since the last
* time resume data was saved, fail this attempt. Significant changes
* primarily include more data having been downloaded, file or piece
* priorities having changed etc. If the resume data doesn't need
* saving, a save_resume_data_failed_alert is posted with the error
* resume_data_not_modified.
*/
public static final resume_data_flags_t ONLY_IF_MODIFIED = torrent_handle.only_if_modified;
/**
* ``save_resume_data()`` generates fast-resume data and returns it as an
* entry. This entry is suitable for being bencoded. For more information
@ -836,6 +839,13 @@ public final class TorrentHandle {
th.force_recheck();
}
/**
* By default, force-reannounce will still honor the min-interval
* published by the tracker. If this flag is set, it will be ignored
* and the tracker is announced immediately.
*/
public static final reannounce_flags_t IGNORE_MIN_INTERVAL = torrent_handle.ignore_min_interval;
// ``force_reannounce()`` will force this torrent to do another tracker
// request, to receive new peers. The ``seconds`` argument specifies how
// many seconds from now to issue the tracker announces.
@ -1189,6 +1199,11 @@ public final class TorrentHandle {
th.set_piece_deadline(index, deadline);
}
/**
*
*/
public static final deadline_flags_t ALERT_WHEN_AVAILABLE = torrent_handle.alert_when_available;
/**
* This function sets or resets the deadline associated with a specific
* piece index (``index``). libtorrent will attempt to download this
@ -1367,12 +1382,12 @@ public final class TorrentHandle {
*/
PIECE_GRANULARITY(torrent_handle.file_progress_flags_t.piece_granularity.swigValue());
private final int swigValue;
FileProgressFlags(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/

View File

@ -75,50 +75,6 @@ public final class TorrentInfo {
}
}
public static TorrentInfo bdecode(byte[] data) {
return new TorrentInfo(bdecode0(data));
}
// helper function
static ArrayList<AnnounceEntry> trackers(announce_entry_vector v) {
int size = (int) v.size();
ArrayList<AnnounceEntry> l = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
l.add(new AnnounceEntry(v.get(i)));
}
return l;
}
private static torrent_info bdecode0(File file) {
try {
byte[] data = Files.bytes(file);
return bdecode0(data);
} catch (IOException e) {
throw new IllegalArgumentException("Can't decode data from file: " + file, e);
}
}
private static torrent_info bdecode0(byte[] data) {
byte_vector buffer = Vectors.bytes2byte_vector(data);
bdecode_node n = new bdecode_node();
error_code ec = new error_code();
int ret = bdecode_node.bdecode(buffer, n, ec);
if (ret == 0) {
ec.clear();
torrent_info ti = new torrent_info(n, ec);
buffer.clear(); // prevents GC
if (ec.value() != 0) {
throw new IllegalArgumentException("Can't decode data: " + ec.message());
}
return ti;
} else {
throw new IllegalArgumentException("Can't decode data: " + ec.message());
}
}
/**
* @return the native object
*/
@ -706,4 +662,48 @@ public final class TorrentInfo {
public byte[] bencode() {
return toEntry().bencode();
}
public static TorrentInfo bdecode(byte[] data) {
return new TorrentInfo(bdecode0(data));
}
// helper function
static ArrayList<AnnounceEntry> trackers(announce_entry_vector v) {
int size = (int) v.size();
ArrayList<AnnounceEntry> l = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
l.add(new AnnounceEntry(v.get(i)));
}
return l;
}
private static torrent_info bdecode0(File file) {
try {
byte[] data = Files.bytes(file);
return bdecode0(data);
} catch (IOException e) {
throw new IllegalArgumentException("Can't decode data from file: " + file, e);
}
}
private static torrent_info bdecode0(byte[] data) {
byte_vector buffer = Vectors.bytes2byte_vector(data);
bdecode_node n = new bdecode_node();
error_code ec = new error_code();
int ret = bdecode_node.bdecode(buffer, n, ec);
if (ret == 0) {
ec.clear();
torrent_info ti = new torrent_info(n, ec);
buffer.clear(); // prevents GC
if (ec.value() != 0) {
throw new IllegalArgumentException("Can't decode data: " + ec.message());
}
return ti;
} else {
throw new IllegalArgumentException("Can't decode data: " + ec.message());
}
}
}

View File

@ -24,10 +24,6 @@ public final class TorrentStatus implements Cloneable {
this.ts = ts;
}
private static long time2millis(long time) {
return time * 1000;
}
/**
* @return the native object
*/
@ -150,22 +146,8 @@ public final class TorrentStatus implements Cloneable {
return ts.getTotal_redundant_bytes();
}
/**
* IMPORTANT: If you are not getting up to date information about pieces
* remember that PieceIndexBitfield data is considered augmented data
* for a torrentHandle.status() call, meaning, if you want to get the latest
* piece data, you must use the TorrentHandle.QUERY_PIECES flag when invoking
* torrentHandle.status(TorrentHandle.QUERY_PIECES). Keep in mind this is
* an expensive call, therefore not part of the default flags.
* <p>
* A bitmask that represents which pieces we have (set to true) and the
* pieces we don't have. It's a pointer and may be set to 0 if the
* torrent isn't downloading or seeding.
*
* @return the bitfield of pieces
*/
public PieceIndexBitfield pieces() {
return new PieceIndexBitfield(ts.getPieces(), ts);
private static long time2millis(long time) {
return time * 1000;
}
/**
@ -699,6 +681,24 @@ public final class TorrentStatus implements Cloneable {
return new TorrentStatus(new torrent_status(ts));
}
/**
* IMPORTANT: If you are not getting up to date information about pieces
* remember that PieceIndexBitfield data is considered augmented data
* for a torrentHandle.status() call, meaning, if you want to get the latest
* piece data, you must use the TorrentHandle.QUERY_PIECES flag when invoking
* torrentHandle.status(TorrentHandle.QUERY_PIECES). Keep in mind this is
* an expensive call, therefore not part of the default flags.
* <p>
* A bitmask that represents which pieces we have (set to true) and the
* pieces we don't have. It's a pointer and may be set to 0 if the
* torrent isn't downloading or seeding.
*
* @return the bitfield of pieces
*/
public PieceIndexBitfield pieces() {
return new PieceIndexBitfield(ts.getPieces(), ts);
}
/**
* the different overall states a torrent can be in.
*/
@ -750,12 +750,19 @@ public final class TorrentStatus implements Cloneable {
*/
UNKNOWN(-1);
private final int swigValue;
State(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue
* @return
@ -769,12 +776,5 @@ public final class TorrentStatus implements Cloneable {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -96,12 +96,19 @@ public final class WebSeedEntry {
*/
UNKNOWN(-1);
private final int swigValue;
Type(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue
* @return
@ -115,12 +122,5 @@ public final class WebSeedEntry {
}
return UNKNOWN;
}
/**
* @return
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -9,6 +9,8 @@ import com.frostwire.jlibtorrent.swig.alert_category_t;
*/
public interface Alert<T extends alert> {
T swig();
alert_category_t ERROR_NOTIFICATION = alert.error_notification;
alert_category_t PEER_NOTIFICATION = alert.peer_notification;
alert_category_t PORT_MAPPING_NOTIFICATION = alert.port_mapping_notification;
@ -34,8 +36,6 @@ public interface Alert<T extends alert> {
alert_category_t BLOCK_PROGRESS_NOTIFICATION = alert.block_progress_notification;
alert_category_t ALL_CATEGORIES = alert.all_categories;
T swig();
/**
* A timestamp is automatically created in the constructor (in milliseconds).
*

View File

@ -186,12 +186,20 @@ public enum AlertType {
UNKNOWN(-1);
private static final AlertType[] TABLE = buildTable();
private final int swigValue;
AlertType(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native swig value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native swig value
* @return the API enum alert type
@ -302,11 +310,4 @@ public enum AlertType {
arr[96] = SOCKS5_ALERT;
return arr;
}
/**
* @return the native swig value
*/
public int swig() {
return swigValue;
}
}

View File

@ -273,12 +273,19 @@ public enum CloseReason {
*/
UNKNOWN(-1);
private final int swigValue;
CloseReason(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* Converted method, it's public in order to be used in other
* internal packages.
@ -295,11 +302,4 @@ public enum CloseReason {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}

View File

@ -42,12 +42,19 @@ public final class DhtLogAlert extends AbstractAlert<dht_log_alert> {
TRAVERSAL(dht_log_alert.dht_module_t.traversal.swigValue()),
UNKNOWN(-1);
private final int swigValue;
DhtModule(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the java enum
@ -61,12 +68,5 @@ public final class DhtLogAlert extends AbstractAlert<dht_log_alert> {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -69,12 +69,19 @@ public final class DhtPktAlert extends AbstractAlert<dht_pkt_alert> {
*/
UNKNOWN(-1);
private final int swigValue;
Direction(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the java enum
@ -88,12 +95,5 @@ public final class DhtPktAlert extends AbstractAlert<dht_pkt_alert> {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -98,12 +98,19 @@ public final class IncomingConnectionAlert extends AbstractAlert<incoming_connec
*/
UNKNOWN(-1);
private final int swigValue;
SocketType(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the java enum
@ -117,12 +124,5 @@ public final class IncomingConnectionAlert extends AbstractAlert<incoming_connec
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -39,32 +39,6 @@ public final class MetadataReceivedAlert extends TorrentAlert<metadata_received_
this.sync = new ReentrantLock();
}
private static byte[] createTorrent(torrent_handle th, torrent_info ti, boolean extra) {
create_torrent ct = new create_torrent(ti);
if (extra) {
string_vector v = th.get_url_seeds();
int size = (int) v.size();
for (int i = 0; i < size; i++) {
ct.add_url_seed(v.get(i));
}
v = th.get_http_seeds();
size = (int) v.size();
for (int i = 0; i < size; i++) {
ct.add_http_seed(v.get(i));
}
announce_entry_vector trackers = th.trackers();
size = (int) trackers.size();
for (int i = 0; i < size; i++) {
announce_entry t = trackers.get(i);
ct.add_tracker(Vectors.byte_vector2ascii(t.get_url()), t.getTier());
}
}
entry e = ct.generate();
return Vectors.byte_vector2bytes(e.bencode());
}
/**
* Returns the size of the metadata (info section).
* <p>
@ -177,4 +151,30 @@ public final class MetadataReceivedAlert extends TorrentAlert<metadata_received_
public byte[] torrentData() {
return torrentData(false);
}
private static byte[] createTorrent(torrent_handle th, torrent_info ti, boolean extra) {
create_torrent ct = new create_torrent(ti);
if (extra) {
string_vector v = th.get_url_seeds();
int size = (int) v.size();
for (int i = 0; i < size; i++) {
ct.add_url_seed(v.get(i));
}
v = th.get_http_seeds();
size = (int) v.size();
for (int i = 0; i < size; i++) {
ct.add_http_seed(v.get(i));
}
announce_entry_vector trackers = th.trackers();
size = (int) trackers.size();
for (int i = 0; i < size; i++) {
announce_entry t = trackers.get(i);
ct.add_tracker(Vectors.byte_vector2ascii(t.get_url()), t.getTier());
}
}
entry e = ct.generate();
return Vectors.byte_vector2bytes(e.bencode());
}
}

View File

@ -75,12 +75,19 @@ public final class PeerBlockedAlert extends TorrentAlert<peer_blocked_alert> {
*/
UNKNOWN(-1);
private final int swigValue;
Reason(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue
* @return
@ -94,12 +101,5 @@ public final class PeerBlockedAlert extends TorrentAlert<peer_blocked_alert> {
}
return UNKNOWN;
}
/**
* @return
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -78,12 +78,19 @@ public final class PeerLogAlert extends PeerAlert<peer_log_alert> {
*/
UNKNOWN(-1);
private final int swigValue;
Direction(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue
* @return
@ -97,12 +104,5 @@ public final class PeerLogAlert extends PeerAlert<peer_log_alert> {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}
}

View File

@ -97,12 +97,16 @@ public final class PerformanceAlert extends TorrentAlert<performance_alert> {
UNKNOWN(-1);
private final int swigValue;
PerformanceWarning(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
public int getSwig() {
return swigValue;
}
public static PerformanceWarning fromSwig(int swigValue) {
PerformanceWarning[] enumValues = PerformanceWarning.class.getEnumConstants();
for (PerformanceWarning ev : enumValues) {
@ -112,9 +116,5 @@ public final class PerformanceAlert extends TorrentAlert<performance_alert> {
}
return UNKNOWN;
}
public int getSwig() {
return swigValue;
}
}
}

View File

@ -13,6 +13,10 @@ import com.frostwire.jlibtorrent.swig.picker_log_alert;
*/
public final class PickerLogAlert extends PeerAlert<picker_log_alert> {
PickerLogAlert(picker_log_alert alert) {
super(alert);
}
public static final picker_flags_t PARTIAL_RATIO = picker_log_alert.partial_ratio;
public static final picker_flags_t PRIORITIZE_PARTIALS = picker_log_alert.prioritize_partials;
public static final picker_flags_t RAREST_FIRST_PARTIALS = picker_log_alert.rarest_first_partials;
@ -31,10 +35,6 @@ public final class PickerLogAlert extends PeerAlert<picker_log_alert> {
public static final picker_flags_t END_GAME = picker_log_alert.end_game;
public static final picker_flags_t EXTENT_AFFINITY = picker_log_alert.extent_affinity;
PickerLogAlert(picker_log_alert alert) {
super(alert);
}
/**
* This is a bitmask of which features were enabled for this particular
* pick. The bits are defined in the picker_flags_t enum.

View File

@ -42,12 +42,19 @@ public enum SocketType {
*/
UNKNOWN(-1);
private final int swigValue;
SocketType(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
/**
* @param swigValue the native value
* @return the enum value
@ -61,11 +68,4 @@ public enum SocketType {
}
return UNKNOWN;
}
/**
* @return the native value
*/
public int swig() {
return swigValue;
}
}

View File

@ -75,12 +75,12 @@ public final class StatsAlert extends TorrentAlert<stats_alert> {
*/
NUM_CHANNELS(stats_alert.stats_channel.num_channels.swigValue());
private final int swigValue;
StatsChannel(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
/**
* @return
*/

View File

@ -38,12 +38,16 @@ public final class TrackerAnnounceAlert extends TrackerAlert<tracker_announce_al
UNKNOWN(-1);
private final int swigValue;
TrackerAnnounceEvent(int swigValue) {
this.swigValue = swigValue;
}
private final int swigValue;
public int getSwig() {
return swigValue;
}
public static TrackerAnnounceEvent fromSwig(int swigValue) {
TrackerAnnounceEvent[] enumValues = TrackerAnnounceEvent.class.getEnumConstants();
for (TrackerAnnounceEvent ev : enumValues) {
@ -53,9 +57,5 @@ public final class TrackerAnnounceAlert extends TrackerAlert<tracker_announce_al
}
return UNKNOWN;
}
public int getSwig() {
return swigValue;
}
}
}

View File

@ -9,18 +9,18 @@
package com.frostwire.jlibtorrent.swig;
public class SWIGTYPE_p_boost__system__error_category {
private final transient long swigCPtr;
private transient long swigCPtr;
protected SWIGTYPE_p_boost__system__error_category(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_boost__system__error_category(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_boost__system__error_category() {
swigCPtr = 0;
}
protected SWIGTYPE_p_boost__system__error_category() {
swigCPtr = 0;
}
protected static long getCPtr(SWIGTYPE_p_boost__system__error_category obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(SWIGTYPE_p_boost__system__error_category obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}

View File

@ -9,18 +9,18 @@
package com.frostwire.jlibtorrent.swig;
public class SWIGTYPE_p_boost__system__error_condition {
private final transient long swigCPtr;
private transient long swigCPtr;
protected SWIGTYPE_p_boost__system__error_condition(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_boost__system__error_condition(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_boost__system__error_condition() {
swigCPtr = 0;
}
protected SWIGTYPE_p_boost__system__error_condition() {
swigCPtr = 0;
}
protected static long getCPtr(SWIGTYPE_p_boost__system__error_condition obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(SWIGTYPE_p_boost__system__error_condition obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}

View File

@ -9,18 +9,18 @@
package com.frostwire.jlibtorrent.swig;
public class SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t {
private final transient long swigCPtr;
private transient long swigCPtr;
protected SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t() {
swigCPtr = 0;
}
protected SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t() {
swigCPtr = 0;
}
protected static long getCPtr(SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(SWIGTYPE_p_libtorrent__aux__noexcept_movableT_libtorrent__tcp__endpoint_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}

View File

@ -9,18 +9,18 @@
package com.frostwire.jlibtorrent.swig;
public class SWIGTYPE_p_std__bitsetT_97_t {
private final transient long swigCPtr;
private transient long swigCPtr;
protected SWIGTYPE_p_std__bitsetT_97_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_std__bitsetT_97_t(long cPtr, @SuppressWarnings("unused") boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_std__bitsetT_97_t() {
swigCPtr = 0;
}
protected SWIGTYPE_p_std__bitsetT_97_t() {
swigCPtr = 0;
}
protected static long getCPtr(SWIGTYPE_p_std__bitsetT_97_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(SWIGTYPE_p_std__bitsetT_97_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}

View File

@ -9,55 +9,55 @@
package com.frostwire.jlibtorrent.swig;
public class add_files_listener {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected add_files_listener(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected add_files_listener(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public add_files_listener() {
this(libtorrent_jni.new_add_files_listener(), true);
libtorrent_jni.add_files_listener_director_connect(this, swigCPtr, true, true);
}
protected static long getCPtr(add_files_listener obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(add_files_listener obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_add_files_listener(swigCPtr);
}
swigCPtr = 0;
}
}
protected void swigDirectorDisconnect() {
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
delete();
libtorrent_jni.delete_add_files_listener(swigCPtr);
}
swigCPtr = 0;
}
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.add_files_listener_change_ownership(this, swigCPtr, false);
}
protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.add_files_listener_change_ownership(this, swigCPtr, true);
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.add_files_listener_change_ownership(this, swigCPtr, false);
}
public boolean pred(String p) {
return (getClass() == add_files_listener.class) ? libtorrent_jni.add_files_listener_pred(swigCPtr, this, p) : libtorrent_jni.add_files_listener_predSwigExplicitadd_files_listener(swigCPtr, this, p);
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.add_files_listener_change_ownership(this, swigCPtr, true);
}
public boolean pred(String p) {
return (getClass() == add_files_listener.class) ? libtorrent_jni.add_files_listener_pred(swigCPtr, this, p) : libtorrent_jni.add_files_listener_predSwigExplicitadd_files_listener(swigCPtr, this, p);
}
public add_files_listener() {
this(libtorrent_jni.new_add_files_listener(), true);
libtorrent_jni.add_files_listener_director_connect(this, swigCPtr, true, true);
}
}

View File

@ -9,58 +9,55 @@
package com.frostwire.jlibtorrent.swig;
public class alert_notify_callback {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected alert_notify_callback(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected alert_notify_callback(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public alert_notify_callback() {
this(libtorrent_jni.new_alert_notify_callback(), true);
libtorrent_jni.alert_notify_callback_director_connect(this, swigCPtr, true, true);
}
protected static long getCPtr(alert_notify_callback obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(alert_notify_callback obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_alert_notify_callback(swigCPtr);
}
swigCPtr = 0;
}
}
protected void swigDirectorDisconnect() {
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
delete();
libtorrent_jni.delete_alert_notify_callback(swigCPtr);
}
swigCPtr = 0;
}
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.alert_notify_callback_change_ownership(this, swigCPtr, false);
}
protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.alert_notify_callback_change_ownership(this, swigCPtr, true);
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.alert_notify_callback_change_ownership(this, swigCPtr, false);
}
public void on_alert() {
if (getClass() == alert_notify_callback.class)
libtorrent_jni.alert_notify_callback_on_alert(swigCPtr, this);
else
libtorrent_jni.alert_notify_callback_on_alertSwigExplicitalert_notify_callback(swigCPtr, this);
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.alert_notify_callback_change_ownership(this, swigCPtr, true);
}
public void on_alert() {
if (getClass() == alert_notify_callback.class) libtorrent_jni.alert_notify_callback_on_alert(swigCPtr, this); else libtorrent_jni.alert_notify_callback_on_alertSwigExplicitalert_notify_callback(swigCPtr, this);
}
public alert_notify_callback() {
this(libtorrent_jni.new_alert_notify_callback(), true);
libtorrent_jni.alert_notify_callback_director_connect(this, swigCPtr, true, true);
}
}

View File

@ -9,135 +9,136 @@
package com.frostwire.jlibtorrent.swig;
public class create_torrent {
public final static create_flags_t optimize_alignment = new create_flags_t(libtorrent_jni.create_torrent_optimize_alignment_get(), false);
public final static create_flags_t merkle = new create_flags_t(libtorrent_jni.create_torrent_merkle_get(), false);
public final static create_flags_t modification_time = new create_flags_t(libtorrent_jni.create_torrent_modification_time_get(), false);
public final static create_flags_t symlinks = new create_flags_t(libtorrent_jni.create_torrent_symlinks_get(), false);
public final static create_flags_t mutable_torrent_support = new create_flags_t(libtorrent_jni.create_torrent_mutable_torrent_support_get(), false);
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected create_torrent(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected create_torrent(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public create_torrent(file_storage fs, int piece_size, int pad_file_limit, create_flags_t flags, int alignment) {
this(libtorrent_jni.new_create_torrent__SWIG_0(file_storage.getCPtr(fs), fs, piece_size, pad_file_limit, create_flags_t.getCPtr(flags), flags, alignment), true);
}
protected static long getCPtr(create_torrent obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
public create_torrent(file_storage fs, int piece_size, int pad_file_limit, create_flags_t flags) {
this(libtorrent_jni.new_create_torrent__SWIG_1(file_storage.getCPtr(fs), fs, piece_size, pad_file_limit, create_flags_t.getCPtr(flags), flags), true);
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public create_torrent(file_storage fs, int piece_size, int pad_file_limit) {
this(libtorrent_jni.new_create_torrent__SWIG_2(file_storage.getCPtr(fs), fs, piece_size, pad_file_limit), true);
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_create_torrent(swigCPtr);
}
swigCPtr = 0;
}
}
public create_torrent(file_storage fs, int piece_size) {
this(libtorrent_jni.new_create_torrent__SWIG_3(file_storage.getCPtr(fs), fs, piece_size), true);
}
public create_torrent(file_storage fs, int piece_size, int pad_file_limit, create_flags_t flags, int alignment) {
this(libtorrent_jni.new_create_torrent__SWIG_0(file_storage.getCPtr(fs), fs, piece_size, pad_file_limit, create_flags_t.getCPtr(flags), flags, alignment), true);
}
public create_torrent(file_storage fs) {
this(libtorrent_jni.new_create_torrent__SWIG_4(file_storage.getCPtr(fs), fs), true);
}
public create_torrent(file_storage fs, int piece_size, int pad_file_limit, create_flags_t flags) {
this(libtorrent_jni.new_create_torrent__SWIG_1(file_storage.getCPtr(fs), fs, piece_size, pad_file_limit, create_flags_t.getCPtr(flags), flags), true);
}
public create_torrent(torrent_info ti) {
this(libtorrent_jni.new_create_torrent__SWIG_5(torrent_info.getCPtr(ti), ti), true);
}
public create_torrent(file_storage fs, int piece_size, int pad_file_limit) {
this(libtorrent_jni.new_create_torrent__SWIG_2(file_storage.getCPtr(fs), fs, piece_size, pad_file_limit), true);
}
protected static long getCPtr(create_torrent obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
public create_torrent(file_storage fs, int piece_size) {
this(libtorrent_jni.new_create_torrent__SWIG_3(file_storage.getCPtr(fs), fs, piece_size), true);
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public create_torrent(file_storage fs) {
this(libtorrent_jni.new_create_torrent__SWIG_4(file_storage.getCPtr(fs), fs), true);
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_create_torrent(swigCPtr);
}
swigCPtr = 0;
}
}
public create_torrent(torrent_info ti) {
this(libtorrent_jni.new_create_torrent__SWIG_5(torrent_info.getCPtr(ti), ti), true);
}
public entry generate() {
return new entry(libtorrent_jni.create_torrent_generate(swigCPtr, this), true);
}
public entry generate() {
return new entry(libtorrent_jni.create_torrent_generate(swigCPtr, this), true);
}
public file_storage files() {
return new file_storage(libtorrent_jni.create_torrent_files(swigCPtr, this), false);
}
public file_storage files() {
return new file_storage(libtorrent_jni.create_torrent_files(swigCPtr, this), false);
}
public void set_comment(String str) {
libtorrent_jni.create_torrent_set_comment(swigCPtr, this, str);
}
public void set_comment(String str) {
libtorrent_jni.create_torrent_set_comment(swigCPtr, this, str);
}
public void set_creator(String str) {
libtorrent_jni.create_torrent_set_creator(swigCPtr, this, str);
}
public void set_creator(String str) {
libtorrent_jni.create_torrent_set_creator(swigCPtr, this, str);
}
public void set_hash(int index, sha1_hash h) {
libtorrent_jni.create_torrent_set_hash(swigCPtr, this, index, sha1_hash.getCPtr(h), h);
}
public void set_hash(int index, sha1_hash h) {
libtorrent_jni.create_torrent_set_hash(swigCPtr, this, index, sha1_hash.getCPtr(h), h);
}
public void set_file_hash(int index, sha1_hash h) {
libtorrent_jni.create_torrent_set_file_hash(swigCPtr, this, index, sha1_hash.getCPtr(h), h);
}
public void set_file_hash(int index, sha1_hash h) {
libtorrent_jni.create_torrent_set_file_hash(swigCPtr, this, index, sha1_hash.getCPtr(h), h);
}
public void add_node(string_int_pair node) {
libtorrent_jni.create_torrent_add_node(swigCPtr, this, string_int_pair.getCPtr(node), node);
}
public void add_node(string_int_pair node) {
libtorrent_jni.create_torrent_add_node(swigCPtr, this, string_int_pair.getCPtr(node), node);
}
public void set_priv(boolean p) {
libtorrent_jni.create_torrent_set_priv(swigCPtr, this, p);
}
public void set_priv(boolean p) {
libtorrent_jni.create_torrent_set_priv(swigCPtr, this, p);
}
public boolean priv() {
return libtorrent_jni.create_torrent_priv(swigCPtr, this);
}
public boolean priv() {
return libtorrent_jni.create_torrent_priv(swigCPtr, this);
}
public int num_pieces() {
return libtorrent_jni.create_torrent_num_pieces(swigCPtr, this);
}
public int num_pieces() {
return libtorrent_jni.create_torrent_num_pieces(swigCPtr, this);
}
public int piece_length() {
return libtorrent_jni.create_torrent_piece_length(swigCPtr, this);
}
public int piece_length() {
return libtorrent_jni.create_torrent_piece_length(swigCPtr, this);
}
public int piece_size(int i) {
return libtorrent_jni.create_torrent_piece_size(swigCPtr, this, i);
}
public int piece_size(int i) {
return libtorrent_jni.create_torrent_piece_size(swigCPtr, this, i);
}
public sha1_hash_vector merkle_tree() {
return new sha1_hash_vector(libtorrent_jni.create_torrent_merkle_tree(swigCPtr, this), false);
}
public sha1_hash_vector merkle_tree() {
return new sha1_hash_vector(libtorrent_jni.create_torrent_merkle_tree(swigCPtr, this), false);
}
public void add_similar_torrent(sha1_hash ih) {
libtorrent_jni.create_torrent_add_similar_torrent(swigCPtr, this, sha1_hash.getCPtr(ih), ih);
}
public void add_similar_torrent(sha1_hash ih) {
libtorrent_jni.create_torrent_add_similar_torrent(swigCPtr, this, sha1_hash.getCPtr(ih), ih);
}
public void add_url_seed(String url) {
libtorrent_jni.create_torrent_add_url_seed(swigCPtr, this, url);
}
public void add_url_seed(String url) {
libtorrent_jni.create_torrent_add_url_seed(swigCPtr, this, url);
}
public void add_http_seed(String url) {
libtorrent_jni.create_torrent_add_http_seed(swigCPtr, this, url);
}
public void add_http_seed(String url) {
libtorrent_jni.create_torrent_add_http_seed(swigCPtr, this, url);
}
public void add_tracker(String url, int tier) {
libtorrent_jni.create_torrent_add_tracker(swigCPtr, this, url, tier);
}
public void add_tracker(String url, int tier) {
libtorrent_jni.create_torrent_add_tracker(swigCPtr, this, url, tier);
}
public void add_collection(String c) {
libtorrent_jni.create_torrent_add_collection(swigCPtr, this, c);
}
public void add_collection(String c) {
libtorrent_jni.create_torrent_add_collection(swigCPtr, this, c);
}
public void set_root_cert2(byte_vector pem) {
libtorrent_jni.create_torrent_set_root_cert2(swigCPtr, this, byte_vector.getCPtr(pem), pem);
}
public void set_root_cert2(byte_vector pem) {
libtorrent_jni.create_torrent_set_root_cert2(swigCPtr, this, byte_vector.getCPtr(pem), pem);
}
public final static create_flags_t optimize_alignment = new create_flags_t(libtorrent_jni.create_torrent_optimize_alignment_get(), false);
public final static create_flags_t merkle = new create_flags_t(libtorrent_jni.create_torrent_merkle_get(), false);
public final static create_flags_t modification_time = new create_flags_t(libtorrent_jni.create_torrent_modification_time_get(), false);
public final static create_flags_t symlinks = new create_flags_t(libtorrent_jni.create_torrent_symlinks_get(), false);
public final static create_flags_t mutable_torrent_support = new create_flags_t(libtorrent_jni.create_torrent_mutable_torrent_support_get(), false);
}

View File

@ -9,88 +9,88 @@
package com.frostwire.jlibtorrent.swig;
public class ip_interface {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected ip_interface(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected ip_interface(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public ip_interface() {
this(libtorrent_jni.new_ip_interface(), true);
}
protected static long getCPtr(ip_interface obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(ip_interface obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_ip_interface(swigCPtr);
}
swigCPtr = 0;
}
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_ip_interface(swigCPtr);
}
swigCPtr = 0;
}
}
public void setInterface_address(address value) {
libtorrent_jni.ip_interface_interface_address_set(swigCPtr, this, address.getCPtr(value), value);
}
public address getInterface_address() {
long cPtr = libtorrent_jni.ip_interface_interface_address_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public address getInterface_address() {
long cPtr = libtorrent_jni.ip_interface_interface_address_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public void setInterface_address(address value) {
libtorrent_jni.ip_interface_interface_address_set(swigCPtr, this, address.getCPtr(value), value);
}
public void setNetmask(address value) {
libtorrent_jni.ip_interface_netmask_set(swigCPtr, this, address.getCPtr(value), value);
}
public address getNetmask() {
long cPtr = libtorrent_jni.ip_interface_netmask_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public address getNetmask() {
long cPtr = libtorrent_jni.ip_interface_netmask_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public void setNetmask(address value) {
libtorrent_jni.ip_interface_netmask_set(swigCPtr, this, address.getCPtr(value), value);
}
public void setName(byte_vector value) {
libtorrent_jni.ip_interface_name_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public byte_vector getName() {
long cPtr = libtorrent_jni.ip_interface_name_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public byte_vector getName() {
long cPtr = libtorrent_jni.ip_interface_name_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public void setName(byte_vector value) {
libtorrent_jni.ip_interface_name_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public void setFriendly_name(byte_vector value) {
libtorrent_jni.ip_interface_friendly_name_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public byte_vector getFriendly_name() {
long cPtr = libtorrent_jni.ip_interface_friendly_name_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public byte_vector getFriendly_name() {
long cPtr = libtorrent_jni.ip_interface_friendly_name_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public void setFriendly_name(byte_vector value) {
libtorrent_jni.ip_interface_friendly_name_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public void setDescription(byte_vector value) {
libtorrent_jni.ip_interface_description_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public byte_vector getDescription() {
long cPtr = libtorrent_jni.ip_interface_description_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public byte_vector getDescription() {
long cPtr = libtorrent_jni.ip_interface_description_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public void setDescription(byte_vector value) {
libtorrent_jni.ip_interface_description_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public void setPreferred(boolean value) {
libtorrent_jni.ip_interface_preferred_set(swigCPtr, this, value);
}
public boolean getPreferred() {
return libtorrent_jni.ip_interface_preferred_get(swigCPtr, this);
}
public boolean getPreferred() {
return libtorrent_jni.ip_interface_preferred_get(swigCPtr, this);
}
public void setPreferred(boolean value) {
libtorrent_jni.ip_interface_preferred_set(swigCPtr, this, value);
}
public ip_interface() {
this(libtorrent_jni.new_ip_interface(), true);
}
}

View File

@ -9,88 +9,88 @@
package com.frostwire.jlibtorrent.swig;
public class ip_route {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected ip_route(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected ip_route(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public ip_route() {
this(libtorrent_jni.new_ip_route(), true);
}
protected static long getCPtr(ip_route obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(ip_route obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_ip_route(swigCPtr);
}
swigCPtr = 0;
}
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_ip_route(swigCPtr);
}
swigCPtr = 0;
}
}
public void setDestination(address value) {
libtorrent_jni.ip_route_destination_set(swigCPtr, this, address.getCPtr(value), value);
}
public address getDestination() {
long cPtr = libtorrent_jni.ip_route_destination_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public address getDestination() {
long cPtr = libtorrent_jni.ip_route_destination_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public void setDestination(address value) {
libtorrent_jni.ip_route_destination_set(swigCPtr, this, address.getCPtr(value), value);
}
public void setNetmask(address value) {
libtorrent_jni.ip_route_netmask_set(swigCPtr, this, address.getCPtr(value), value);
}
public address getNetmask() {
long cPtr = libtorrent_jni.ip_route_netmask_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public address getNetmask() {
long cPtr = libtorrent_jni.ip_route_netmask_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public void setNetmask(address value) {
libtorrent_jni.ip_route_netmask_set(swigCPtr, this, address.getCPtr(value), value);
}
public void setGateway(address value) {
libtorrent_jni.ip_route_gateway_set(swigCPtr, this, address.getCPtr(value), value);
}
public address getGateway() {
long cPtr = libtorrent_jni.ip_route_gateway_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public address getGateway() {
long cPtr = libtorrent_jni.ip_route_gateway_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public void setGateway(address value) {
libtorrent_jni.ip_route_gateway_set(swigCPtr, this, address.getCPtr(value), value);
}
public void setSource_hint(address value) {
libtorrent_jni.ip_route_source_hint_set(swigCPtr, this, address.getCPtr(value), value);
}
public address getSource_hint() {
long cPtr = libtorrent_jni.ip_route_source_hint_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public address getSource_hint() {
long cPtr = libtorrent_jni.ip_route_source_hint_get(swigCPtr, this);
return (cPtr == 0) ? null : new address(cPtr, false);
}
public void setSource_hint(address value) {
libtorrent_jni.ip_route_source_hint_set(swigCPtr, this, address.getCPtr(value), value);
}
public void setName(byte_vector value) {
libtorrent_jni.ip_route_name_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public byte_vector getName() {
long cPtr = libtorrent_jni.ip_route_name_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public byte_vector getName() {
long cPtr = libtorrent_jni.ip_route_name_get(swigCPtr, this);
return (cPtr == 0) ? null : new byte_vector(cPtr, false);
}
public void setName(byte_vector value) {
libtorrent_jni.ip_route_name_set(swigCPtr, this, byte_vector.getCPtr(value), value);
}
public void setMtu(int value) {
libtorrent_jni.ip_route_mtu_set(swigCPtr, this, value);
}
public int getMtu() {
return libtorrent_jni.ip_route_mtu_get(swigCPtr, this);
}
public int getMtu() {
return libtorrent_jni.ip_route_mtu_get(swigCPtr, this);
}
public void setMtu(int value) {
libtorrent_jni.ip_route_mtu_set(swigCPtr, this, value);
}
public ip_route() {
this(libtorrent_jni.new_ip_route(), true);
}
}

View File

@ -9,431 +9,431 @@
package com.frostwire.jlibtorrent.swig;
public class libtorrent implements libtorrentConstants {
public static boolean failed_impl(int ev, SWIGTYPE_p_boost__system__error_category cat) {
return libtorrent_jni.failed_impl(ev, SWIGTYPE_p_boost__system__error_category.getCPtr(cat));
}
public static boolean op_eq(error_code lhs, error_code rhs) {
return libtorrent_jni.op_eq__SWIG_1(error_code.getCPtr(lhs), lhs, error_code.getCPtr(rhs), rhs);
}
public static boolean op_lt(error_code lhs, error_code rhs) {
return libtorrent_jni.op_lt__SWIG_1(error_code.getCPtr(lhs), lhs, error_code.getCPtr(rhs), rhs);
}
public static boolean op_ne(error_code lhs, error_code rhs) {
return libtorrent_jni.op_ne(error_code.getCPtr(lhs), lhs, error_code.getCPtr(rhs), rhs);
}
public static error_code make_error_code(errc_t e) {
return new error_code(libtorrent_jni.make_error_code(e.swigValue()), true);
}
public static String version() {
return libtorrent_jni.version();
}
public static String print_error(error_code arg0) {
return libtorrent_jni.print_error(error_code.getCPtr(arg0), arg0);
}
public static torrent_flags_t getSeed_mode() {
long cPtr = libtorrent_jni.seed_mode_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getUpload_mode() {
long cPtr = libtorrent_jni.upload_mode_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getShare_mode() {
long cPtr = libtorrent_jni.share_mode_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getApply_ip_filter() {
long cPtr = libtorrent_jni.apply_ip_filter_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getPaused() {
long cPtr = libtorrent_jni.paused_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getAuto_managed() {
long cPtr = libtorrent_jni.auto_managed_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDuplicate_is_error() {
long cPtr = libtorrent_jni.duplicate_is_error_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getUpdate_subscribe() {
long cPtr = libtorrent_jni.update_subscribe_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getSuper_seeding() {
long cPtr = libtorrent_jni.super_seeding_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getSequential_download() {
long cPtr = libtorrent_jni.sequential_download_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getStop_when_ready() {
long cPtr = libtorrent_jni.stop_when_ready_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getOverride_trackers() {
long cPtr = libtorrent_jni.override_trackers_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getOverride_web_seeds() {
long cPtr = libtorrent_jni.override_web_seeds_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getNeed_save_resume() {
long cPtr = libtorrent_jni.need_save_resume_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDisable_dht() {
long cPtr = libtorrent_jni.disable_dht_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDisable_lsd() {
long cPtr = libtorrent_jni.disable_lsd_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDisable_pex() {
long cPtr = libtorrent_jni.disable_pex_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getNo_verify_files() {
long cPtr = libtorrent_jni.no_verify_files_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getAll() {
long cPtr = libtorrent_jni.all_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDefault_flags() {
long cPtr = libtorrent_jni.default_flags_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static pex_flags_t getPex_encryption() {
long cPtr = libtorrent_jni.pex_encryption_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static pex_flags_t getPex_seed() {
long cPtr = libtorrent_jni.pex_seed_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static pex_flags_t getPex_utp() {
long cPtr = libtorrent_jni.pex_utp_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static pex_flags_t getPex_holepunch() {
long cPtr = libtorrent_jni.pex_holepunch_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static String operation_name(operation_t op) {
return libtorrent_jni.operation_name(op.swigValue());
}
public static stats_metric_vector session_stats_metrics() {
return new stats_metric_vector(libtorrent_jni.session_stats_metrics(), true);
}
public static alert_category_t getError() {
long cPtr = libtorrent_jni.error_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPeer() {
long cPtr = libtorrent_jni.peer_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPort_mapping() {
long cPtr = libtorrent_jni.port_mapping_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getStorage() {
long cPtr = libtorrent_jni.storage_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getTracker() {
long cPtr = libtorrent_jni.tracker_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getConnect() {
long cPtr = libtorrent_jni.connect_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getStatus() {
long cPtr = libtorrent_jni.status_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getIp_block() {
long cPtr = libtorrent_jni.ip_block_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPerformance_warning() {
long cPtr = libtorrent_jni.performance_warning_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getDht() {
long cPtr = libtorrent_jni.dht_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getStats() {
long cPtr = libtorrent_jni.stats_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getSession_log() {
long cPtr = libtorrent_jni.session_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getTorrent_log() {
long cPtr = libtorrent_jni.torrent_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPeer_log() {
long cPtr = libtorrent_jni.peer_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getIncoming_request() {
long cPtr = libtorrent_jni.incoming_request_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getDht_log() {
long cPtr = libtorrent_jni.dht_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getDht_operation() {
long cPtr = libtorrent_jni.dht_operation_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPort_mapping_log() {
long cPtr = libtorrent_jni.port_mapping_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPicker_log() {
long cPtr = libtorrent_jni.picker_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getFile_progress() {
long cPtr = libtorrent_jni.file_progress_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPiece_progress() {
long cPtr = libtorrent_jni.piece_progress_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getUpload() {
long cPtr = libtorrent_jni.upload_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getBlock_progress() {
long cPtr = libtorrent_jni.block_progress_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static String alert_name(int alert_type) {
return libtorrent_jni.alert_name(alert_type);
}
public static int getNum_alert_types() {
return libtorrent_jni.num_alert_types_get();
}
public static String performance_warning_str(performance_alert.performance_warning_t i) {
return libtorrent_jni.performance_warning_str(i.swigValue());
}
public static int default_int_value(int name) {
return libtorrent_jni.default_int_value(name);
}
public static int setting_by_name(string_view name) {
return libtorrent_jni.setting_by_name(string_view.getCPtr(name), name);
}
public static String name_for_setting(int s) {
return libtorrent_jni.name_for_setting(s);
}
public static settings_pack default_settings() {
return new settings_pack(libtorrent_jni.default_settings(), true);
}
public static boolean op_eq(peer_class_type_filter lhs, peer_class_type_filter rhs) {
return libtorrent_jni.op_eq__SWIG_0(peer_class_type_filter.getCPtr(lhs), lhs, peer_class_type_filter.getCPtr(rhs), rhs);
}
public static boolean op_lte(address lhs, address rhs) {
return libtorrent_jni.op_lte(address.getCPtr(lhs), lhs, address.getCPtr(rhs), rhs);
}
public static settings_pack min_memory_usage() {
return new settings_pack(libtorrent_jni.min_memory_usage(), true);
}
public static settings_pack high_performance_seed() {
return new settings_pack(libtorrent_jni.high_performance_seed(), true);
}
public static session_params read_session_params(bdecode_node e, save_state_flags_t flags) {
return new session_params(libtorrent_jni.read_session_params__SWIG_0(bdecode_node.getCPtr(e), e, save_state_flags_t.getCPtr(flags), flags), true);
}
public static session_params read_session_params(bdecode_node e) {
return new session_params(libtorrent_jni.read_session_params__SWIG_1(bdecode_node.getCPtr(e), e), true);
}
public static String make_magnet_uri(torrent_handle handle) {
return libtorrent_jni.make_magnet_uri__SWIG_0(torrent_handle.getCPtr(handle), handle);
}
public static String make_magnet_uri(torrent_info info) {
return libtorrent_jni.make_magnet_uri__SWIG_1(torrent_info.getCPtr(info), info);
}
public static void add_files(file_storage fs, String file, create_flags_t flags) {
libtorrent_jni.add_files__SWIG_0(file_storage.getCPtr(fs), fs, file, create_flags_t.getCPtr(flags), flags);
}
public static void add_files(file_storage fs, String file) {
libtorrent_jni.add_files__SWIG_1(file_storage.getCPtr(fs), fs, file);
}
public static void set_piece_hashes(create_torrent t, String p, error_code ec) {
libtorrent_jni.set_piece_hashes(create_torrent.getCPtr(t), t, p, error_code.getCPtr(ec), ec);
}
public static String generate_fingerprint(String name, int major, int minor, int revision, int tag) {
return libtorrent_jni.generate_fingerprint(name, major, minor, revision, tag);
}
public static byte_vector ed25519_create_seed() {
return new byte_vector(libtorrent_jni.ed25519_create_seed(), true);
}
public static byte_vectors_pair ed25519_create_keypair(byte_vector seed) {
return new byte_vectors_pair(libtorrent_jni.ed25519_create_keypair(byte_vector.getCPtr(seed), seed), true);
}
public static byte_vector ed25519_sign(byte_vector msg, byte_vector pk, byte_vector sk) {
return new byte_vector(libtorrent_jni.ed25519_sign(byte_vector.getCPtr(msg), msg, byte_vector.getCPtr(pk), pk, byte_vector.getCPtr(sk), sk), true);
}
public static boolean ed25519_verify(byte_vector sig, byte_vector msg, byte_vector pk) {
return libtorrent_jni.ed25519_verify(byte_vector.getCPtr(sig), sig, byte_vector.getCPtr(msg), msg, byte_vector.getCPtr(pk), pk);
}
public static byte_vector ed25519_add_scalar_public(byte_vector pk, byte_vector scalar) {
return new byte_vector(libtorrent_jni.ed25519_add_scalar_public(byte_vector.getCPtr(pk), pk, byte_vector.getCPtr(scalar), scalar), true);
}
public static byte_vector ed25519_add_scalar_secret(byte_vector sk, byte_vector scalar) {
return new byte_vector(libtorrent_jni.ed25519_add_scalar_secret(byte_vector.getCPtr(sk), sk, byte_vector.getCPtr(scalar), scalar), true);
}
public static boolean failed_impl(int ev, SWIGTYPE_p_boost__system__error_category cat) {
return libtorrent_jni.failed_impl(ev, SWIGTYPE_p_boost__system__error_category.getCPtr(cat));
}
public static boolean op_eq(error_code lhs, error_code rhs) {
return libtorrent_jni.op_eq__SWIG_1(error_code.getCPtr(lhs), lhs, error_code.getCPtr(rhs), rhs);
}
public static boolean op_lt(error_code lhs, error_code rhs) {
return libtorrent_jni.op_lt__SWIG_1(error_code.getCPtr(lhs), lhs, error_code.getCPtr(rhs), rhs);
}
public static boolean op_ne(error_code lhs, error_code rhs) {
return libtorrent_jni.op_ne(error_code.getCPtr(lhs), lhs, error_code.getCPtr(rhs), rhs);
}
public static error_code make_error_code(errc_t e) {
return new error_code(libtorrent_jni.make_error_code(e.swigValue()), true);
}
public static String version() {
return libtorrent_jni.version();
}
public static String print_error(error_code arg0) {
return libtorrent_jni.print_error(error_code.getCPtr(arg0), arg0);
}
public static torrent_flags_t getSeed_mode() {
long cPtr = libtorrent_jni.seed_mode_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getUpload_mode() {
long cPtr = libtorrent_jni.upload_mode_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getShare_mode() {
long cPtr = libtorrent_jni.share_mode_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getApply_ip_filter() {
long cPtr = libtorrent_jni.apply_ip_filter_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getPaused() {
long cPtr = libtorrent_jni.paused_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getAuto_managed() {
long cPtr = libtorrent_jni.auto_managed_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDuplicate_is_error() {
long cPtr = libtorrent_jni.duplicate_is_error_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getUpdate_subscribe() {
long cPtr = libtorrent_jni.update_subscribe_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getSuper_seeding() {
long cPtr = libtorrent_jni.super_seeding_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getSequential_download() {
long cPtr = libtorrent_jni.sequential_download_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getStop_when_ready() {
long cPtr = libtorrent_jni.stop_when_ready_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getOverride_trackers() {
long cPtr = libtorrent_jni.override_trackers_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getOverride_web_seeds() {
long cPtr = libtorrent_jni.override_web_seeds_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getNeed_save_resume() {
long cPtr = libtorrent_jni.need_save_resume_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDisable_dht() {
long cPtr = libtorrent_jni.disable_dht_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDisable_lsd() {
long cPtr = libtorrent_jni.disable_lsd_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDisable_pex() {
long cPtr = libtorrent_jni.disable_pex_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getNo_verify_files() {
long cPtr = libtorrent_jni.no_verify_files_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getAll() {
long cPtr = libtorrent_jni.all_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static torrent_flags_t getDefault_flags() {
long cPtr = libtorrent_jni.default_flags_get();
return (cPtr == 0) ? null : new torrent_flags_t(cPtr, false);
}
public static pex_flags_t getPex_encryption() {
long cPtr = libtorrent_jni.pex_encryption_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static pex_flags_t getPex_seed() {
long cPtr = libtorrent_jni.pex_seed_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static pex_flags_t getPex_utp() {
long cPtr = libtorrent_jni.pex_utp_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static pex_flags_t getPex_holepunch() {
long cPtr = libtorrent_jni.pex_holepunch_get();
return (cPtr == 0) ? null : new pex_flags_t(cPtr, false);
}
public static String operation_name(operation_t op) {
return libtorrent_jni.operation_name(op.swigValue());
}
public static stats_metric_vector session_stats_metrics() {
return new stats_metric_vector(libtorrent_jni.session_stats_metrics(), true);
}
public static alert_category_t getError() {
long cPtr = libtorrent_jni.error_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPeer() {
long cPtr = libtorrent_jni.peer_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPort_mapping() {
long cPtr = libtorrent_jni.port_mapping_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getStorage() {
long cPtr = libtorrent_jni.storage_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getTracker() {
long cPtr = libtorrent_jni.tracker_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getConnect() {
long cPtr = libtorrent_jni.connect_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getStatus() {
long cPtr = libtorrent_jni.status_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getIp_block() {
long cPtr = libtorrent_jni.ip_block_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPerformance_warning() {
long cPtr = libtorrent_jni.performance_warning_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getDht() {
long cPtr = libtorrent_jni.dht_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getStats() {
long cPtr = libtorrent_jni.stats_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getSession_log() {
long cPtr = libtorrent_jni.session_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getTorrent_log() {
long cPtr = libtorrent_jni.torrent_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPeer_log() {
long cPtr = libtorrent_jni.peer_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getIncoming_request() {
long cPtr = libtorrent_jni.incoming_request_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getDht_log() {
long cPtr = libtorrent_jni.dht_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getDht_operation() {
long cPtr = libtorrent_jni.dht_operation_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPort_mapping_log() {
long cPtr = libtorrent_jni.port_mapping_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPicker_log() {
long cPtr = libtorrent_jni.picker_log_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getFile_progress() {
long cPtr = libtorrent_jni.file_progress_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getPiece_progress() {
long cPtr = libtorrent_jni.piece_progress_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getUpload() {
long cPtr = libtorrent_jni.upload_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static alert_category_t getBlock_progress() {
long cPtr = libtorrent_jni.block_progress_get();
return (cPtr == 0) ? null : new alert_category_t(cPtr, false);
}
public static String alert_name(int alert_type) {
return libtorrent_jni.alert_name(alert_type);
}
public static int getNum_alert_types() {
return libtorrent_jni.num_alert_types_get();
}
public static String performance_warning_str(performance_alert.performance_warning_t i) {
return libtorrent_jni.performance_warning_str(i.swigValue());
}
public static int default_int_value(int name) {
return libtorrent_jni.default_int_value(name);
}
public static int setting_by_name(string_view name) {
return libtorrent_jni.setting_by_name(string_view.getCPtr(name), name);
}
public static String name_for_setting(int s) {
return libtorrent_jni.name_for_setting(s);
}
public static settings_pack default_settings() {
return new settings_pack(libtorrent_jni.default_settings(), true);
}
public static boolean op_eq(peer_class_type_filter lhs, peer_class_type_filter rhs) {
return libtorrent_jni.op_eq__SWIG_0(peer_class_type_filter.getCPtr(lhs), lhs, peer_class_type_filter.getCPtr(rhs), rhs);
}
public static boolean op_lte(address lhs, address rhs) {
return libtorrent_jni.op_lte(address.getCPtr(lhs), lhs, address.getCPtr(rhs), rhs);
}
public static settings_pack min_memory_usage() {
return new settings_pack(libtorrent_jni.min_memory_usage(), true);
}
public static settings_pack high_performance_seed() {
return new settings_pack(libtorrent_jni.high_performance_seed(), true);
}
public static session_params read_session_params(bdecode_node e, save_state_flags_t flags) {
return new session_params(libtorrent_jni.read_session_params__SWIG_0(bdecode_node.getCPtr(e), e, save_state_flags_t.getCPtr(flags), flags), true);
}
public static session_params read_session_params(bdecode_node e) {
return new session_params(libtorrent_jni.read_session_params__SWIG_1(bdecode_node.getCPtr(e), e), true);
}
public static String make_magnet_uri(torrent_handle handle) {
return libtorrent_jni.make_magnet_uri__SWIG_0(torrent_handle.getCPtr(handle), handle);
}
public static String make_magnet_uri(torrent_info info) {
return libtorrent_jni.make_magnet_uri__SWIG_1(torrent_info.getCPtr(info), info);
}
public static void add_files(file_storage fs, String file, create_flags_t flags) {
libtorrent_jni.add_files__SWIG_0(file_storage.getCPtr(fs), fs, file, create_flags_t.getCPtr(flags), flags);
}
public static void add_files(file_storage fs, String file) {
libtorrent_jni.add_files__SWIG_1(file_storage.getCPtr(fs), fs, file);
}
public static void set_piece_hashes(create_torrent t, String p, error_code ec) {
libtorrent_jni.set_piece_hashes(create_torrent.getCPtr(t), t, p, error_code.getCPtr(ec), ec);
}
public static String generate_fingerprint(String name, int major, int minor, int revision, int tag) {
return libtorrent_jni.generate_fingerprint(name, major, minor, revision, tag);
}
public static byte_vector ed25519_create_seed() {
return new byte_vector(libtorrent_jni.ed25519_create_seed(), true);
}
public static byte_vectors_pair ed25519_create_keypair(byte_vector seed) {
return new byte_vectors_pair(libtorrent_jni.ed25519_create_keypair(byte_vector.getCPtr(seed), seed), true);
}
public static byte_vector ed25519_sign(byte_vector msg, byte_vector pk, byte_vector sk) {
return new byte_vector(libtorrent_jni.ed25519_sign(byte_vector.getCPtr(msg), msg, byte_vector.getCPtr(pk), pk, byte_vector.getCPtr(sk), sk), true);
}
public static boolean ed25519_verify(byte_vector sig, byte_vector msg, byte_vector pk) {
return libtorrent_jni.ed25519_verify(byte_vector.getCPtr(sig), sig, byte_vector.getCPtr(msg), msg, byte_vector.getCPtr(pk), pk);
}
public static byte_vector ed25519_add_scalar_public(byte_vector pk, byte_vector scalar) {
return new byte_vector(libtorrent_jni.ed25519_add_scalar_public(byte_vector.getCPtr(pk), pk, byte_vector.getCPtr(scalar), scalar), true);
}
public static byte_vector ed25519_add_scalar_secret(byte_vector sk, byte_vector scalar) {
return new byte_vector(libtorrent_jni.ed25519_add_scalar_secret(byte_vector.getCPtr(sk), sk, byte_vector.getCPtr(scalar), scalar), true);
}
public static byte_vector ed25519_key_exchange(byte_vector pk, byte_vector sk) {
return new byte_vector(libtorrent_jni.ed25519_key_exchange(byte_vector.getCPtr(pk), pk, byte_vector.getCPtr(sk), sk), true);
}
public static byte_vector ed25519_key_exchange(byte_vector pk, byte_vector sk) {
return new byte_vector(libtorrent_jni.ed25519_key_exchange(byte_vector.getCPtr(pk), pk, byte_vector.getCPtr(sk), sk), true);
}
public static void add_files_ex(file_storage fs, String file, add_files_listener listener, create_flags_t flags) {
libtorrent_jni.add_files_ex(file_storage.getCPtr(fs), fs, file, add_files_listener.getCPtr(listener), listener, create_flags_t.getCPtr(flags), flags);
}
public static void add_files_ex(file_storage fs, String file, add_files_listener listener, create_flags_t flags) {
libtorrent_jni.add_files_ex(file_storage.getCPtr(fs), fs, file, add_files_listener.getCPtr(listener), listener, create_flags_t.getCPtr(flags), flags);
}
public static void set_piece_hashes_ex(create_torrent t, String p, set_piece_hashes_listener listener, error_code ec) {
libtorrent_jni.set_piece_hashes_ex(create_torrent.getCPtr(t), t, p, set_piece_hashes_listener.getCPtr(listener), listener, error_code.getCPtr(ec), ec);
}
public static void set_piece_hashes_ex(create_torrent t, String p, set_piece_hashes_listener listener, error_code ec) {
libtorrent_jni.set_piece_hashes_ex(create_torrent.getCPtr(t), t, p, set_piece_hashes_listener.getCPtr(listener), listener, error_code.getCPtr(ec), ec);
}
public static int boost_version() {
return libtorrent_jni.boost_version();
}
public static int boost_version() {
return libtorrent_jni.boost_version();
}
public static String boost_lib_version() {
return libtorrent_jni.boost_lib_version();
}
public static String boost_lib_version() {
return libtorrent_jni.boost_lib_version();
}
public static int openssl_version_number() {
return libtorrent_jni.openssl_version_number();
}
public static int openssl_version_number() {
return libtorrent_jni.openssl_version_number();
}
public static String openssl_version_text() {
return libtorrent_jni.openssl_version_text();
}
public static String openssl_version_text() {
return libtorrent_jni.openssl_version_text();
}
public static int find_metric_idx_s(String name) {
return libtorrent_jni.find_metric_idx_s(name);
}
public static int find_metric_idx_s(String name) {
return libtorrent_jni.find_metric_idx_s(name);
}
public static ip_interface_vector enum_net_interfaces(session s) {
return new ip_interface_vector(libtorrent_jni.enum_net_interfaces(session.getCPtr(s), s), true);
}
public static ip_interface_vector enum_net_interfaces(session s) {
return new ip_interface_vector(libtorrent_jni.enum_net_interfaces(session.getCPtr(s), s), true);
}
public static ip_route_vector enum_routes(session s) {
return new ip_route_vector(libtorrent_jni.enum_routes(session.getCPtr(s), s), true);
}
public static ip_route_vector enum_routes(session s) {
return new ip_route_vector(libtorrent_jni.enum_routes(session.getCPtr(s), s), true);
}
public static void copy_byte_vector_to_char_array(byte_vector source, String target, long target_size) {
libtorrent_jni.copy_byte_vector_to_char_array(byte_vector.getCPtr(source), source, target, target_size);
}
public static void copy_byte_vector_to_char_array(byte_vector source, String target, long target_size) {
libtorrent_jni.copy_byte_vector_to_char_array(byte_vector.getCPtr(source), source, target, target_size);
}
public static address get_gateway(ip_interface iface, ip_route_vector routes) {
return new address(libtorrent_jni.get_gateway(ip_interface.getCPtr(iface), iface, ip_route_vector.getCPtr(routes), routes), true);
}
public static address get_gateway(ip_interface iface, ip_route_vector routes) {
return new address(libtorrent_jni.get_gateway(ip_interface.getCPtr(iface), iface, ip_route_vector.getCPtr(routes), routes), true);
}
public static boolean arm_neon_support() {
return libtorrent_jni.arm_neon_support();
}
public static boolean arm_neon_support() {
return libtorrent_jni.arm_neon_support();
}
public static void set_posix_wrapper(posix_wrapper obj) {
libtorrent_jni.set_posix_wrapper(posix_wrapper.getCPtr(obj), obj);
}
public static void set_posix_wrapper(posix_wrapper obj) {
libtorrent_jni.set_posix_wrapper(posix_wrapper.getCPtr(obj), obj);
}
}

View File

@ -9,10 +9,10 @@
package com.frostwire.jlibtorrent.swig;
public interface libtorrentConstants {
int LIBTORRENT_VERSION_MAJOR = libtorrent_jni.LIBTORRENT_VERSION_MAJOR_get();
int LIBTORRENT_VERSION_MINOR = libtorrent_jni.LIBTORRENT_VERSION_MINOR_get();
int LIBTORRENT_VERSION_TINY = libtorrent_jni.LIBTORRENT_VERSION_TINY_get();
int LIBTORRENT_VERSION_NUM = libtorrent_jni.LIBTORRENT_VERSION_NUM_get();
String LIBTORRENT_VERSION = libtorrent_jni.LIBTORRENT_VERSION_get();
String LIBTORRENT_REVISION = libtorrent_jni.LIBTORRENT_REVISION_get();
public final static int LIBTORRENT_VERSION_MAJOR = libtorrent_jni.LIBTORRENT_VERSION_MAJOR_get();
public final static int LIBTORRENT_VERSION_MINOR = libtorrent_jni.LIBTORRENT_VERSION_MINOR_get();
public final static int LIBTORRENT_VERSION_TINY = libtorrent_jni.LIBTORRENT_VERSION_TINY_get();
public final static int LIBTORRENT_VERSION_NUM = libtorrent_jni.LIBTORRENT_VERSION_NUM_get();
public final static String LIBTORRENT_VERSION = libtorrent_jni.LIBTORRENT_VERSION_get();
public final static String LIBTORRENT_REVISION = libtorrent_jni.LIBTORRENT_REVISION_get();
}

View File

@ -9,75 +9,75 @@
package com.frostwire.jlibtorrent.swig;
public class posix_stat_t {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected posix_stat_t(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected posix_stat_t(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public posix_stat_t() {
this(libtorrent_jni.new_posix_stat_t(), true);
}
protected static long getCPtr(posix_stat_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(posix_stat_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_posix_stat_t(swigCPtr);
}
swigCPtr = 0;
}
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_posix_stat_t(swigCPtr);
}
swigCPtr = 0;
}
}
public void setSize(long value) {
libtorrent_jni.posix_stat_t_size_set(swigCPtr, this, value);
}
public long getSize() {
return libtorrent_jni.posix_stat_t_size_get(swigCPtr, this);
}
public long getSize() {
return libtorrent_jni.posix_stat_t_size_get(swigCPtr, this);
}
public void setSize(long value) {
libtorrent_jni.posix_stat_t_size_set(swigCPtr, this, value);
}
public void setAtime(long value) {
libtorrent_jni.posix_stat_t_atime_set(swigCPtr, this, value);
}
public long getAtime() {
return libtorrent_jni.posix_stat_t_atime_get(swigCPtr, this);
}
public long getAtime() {
return libtorrent_jni.posix_stat_t_atime_get(swigCPtr, this);
}
public void setAtime(long value) {
libtorrent_jni.posix_stat_t_atime_set(swigCPtr, this, value);
}
public void setMtime(long value) {
libtorrent_jni.posix_stat_t_mtime_set(swigCPtr, this, value);
}
public long getMtime() {
return libtorrent_jni.posix_stat_t_mtime_get(swigCPtr, this);
}
public long getMtime() {
return libtorrent_jni.posix_stat_t_mtime_get(swigCPtr, this);
}
public void setMtime(long value) {
libtorrent_jni.posix_stat_t_mtime_set(swigCPtr, this, value);
}
public void setCtime(long value) {
libtorrent_jni.posix_stat_t_ctime_set(swigCPtr, this, value);
}
public long getCtime() {
return libtorrent_jni.posix_stat_t_ctime_get(swigCPtr, this);
}
public long getCtime() {
return libtorrent_jni.posix_stat_t_ctime_get(swigCPtr, this);
}
public void setCtime(long value) {
libtorrent_jni.posix_stat_t_ctime_set(swigCPtr, this, value);
}
public void setMode(int value) {
libtorrent_jni.posix_stat_t_mode_set(swigCPtr, this, value);
}
public int getMode() {
return libtorrent_jni.posix_stat_t_mode_get(swigCPtr, this);
}
public int getMode() {
return libtorrent_jni.posix_stat_t_mode_get(swigCPtr, this);
}
public void setMode(int value) {
libtorrent_jni.posix_stat_t_mode_set(swigCPtr, this, value);
}
public posix_stat_t() {
this(libtorrent_jni.new_posix_stat_t(), true);
}
}

View File

@ -9,71 +9,71 @@
package com.frostwire.jlibtorrent.swig;
public class posix_wrapper {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected posix_wrapper(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected posix_wrapper(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public posix_wrapper() {
this(libtorrent_jni.new_posix_wrapper(), true);
libtorrent_jni.posix_wrapper_director_connect(this, swigCPtr, true, true);
}
protected static long getCPtr(posix_wrapper obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(posix_wrapper obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_posix_wrapper(swigCPtr);
}
swigCPtr = 0;
}
}
protected void swigDirectorDisconnect() {
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
delete();
libtorrent_jni.delete_posix_wrapper(swigCPtr);
}
swigCPtr = 0;
}
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.posix_wrapper_change_ownership(this, swigCPtr, false);
}
protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.posix_wrapper_change_ownership(this, swigCPtr, true);
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.posix_wrapper_change_ownership(this, swigCPtr, false);
}
public int open(String path, int flags, int mode) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_open(swigCPtr, this, path, flags, mode) : libtorrent_jni.posix_wrapper_openSwigExplicitposix_wrapper(swigCPtr, this, path, flags, mode);
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.posix_wrapper_change_ownership(this, swigCPtr, true);
}
public int stat(String path, posix_stat_t buf) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_stat(swigCPtr, this, path, posix_stat_t.getCPtr(buf), buf) : libtorrent_jni.posix_wrapper_statSwigExplicitposix_wrapper(swigCPtr, this, path, posix_stat_t.getCPtr(buf), buf);
}
public int open(String path, int flags, int mode) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_open(swigCPtr, this, path, flags, mode) : libtorrent_jni.posix_wrapper_openSwigExplicitposix_wrapper(swigCPtr, this, path, flags, mode);
}
public int mkdir(String path, int mode) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_mkdir(swigCPtr, this, path, mode) : libtorrent_jni.posix_wrapper_mkdirSwigExplicitposix_wrapper(swigCPtr, this, path, mode);
}
public int stat(String path, posix_stat_t buf) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_stat(swigCPtr, this, path, posix_stat_t.getCPtr(buf), buf) : libtorrent_jni.posix_wrapper_statSwigExplicitposix_wrapper(swigCPtr, this, path, posix_stat_t.getCPtr(buf), buf);
}
public int rename(String oldpath, String newpath) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_rename(swigCPtr, this, oldpath, newpath) : libtorrent_jni.posix_wrapper_renameSwigExplicitposix_wrapper(swigCPtr, this, oldpath, newpath);
}
public int mkdir(String path, int mode) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_mkdir(swigCPtr, this, path, mode) : libtorrent_jni.posix_wrapper_mkdirSwigExplicitposix_wrapper(swigCPtr, this, path, mode);
}
public int remove(String path) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_remove(swigCPtr, this, path) : libtorrent_jni.posix_wrapper_removeSwigExplicitposix_wrapper(swigCPtr, this, path);
}
public int rename(String oldpath, String newpath) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_rename(swigCPtr, this, oldpath, newpath) : libtorrent_jni.posix_wrapper_renameSwigExplicitposix_wrapper(swigCPtr, this, oldpath, newpath);
}
public int remove(String path) {
return (getClass() == posix_wrapper.class) ? libtorrent_jni.posix_wrapper_remove(swigCPtr, this, path) : libtorrent_jni.posix_wrapper_removeSwigExplicitposix_wrapper(swigCPtr, this, path);
}
public posix_wrapper() {
this(libtorrent_jni.new_posix_wrapper(), true);
libtorrent_jni.posix_wrapper_director_connect(this, swigCPtr, true, true);
}
}

View File

@ -9,58 +9,55 @@
package com.frostwire.jlibtorrent.swig;
public class set_piece_hashes_listener {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected set_piece_hashes_listener(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected set_piece_hashes_listener(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public set_piece_hashes_listener() {
this(libtorrent_jni.new_set_piece_hashes_listener(), true);
libtorrent_jni.set_piece_hashes_listener_director_connect(this, swigCPtr, true, true);
}
protected static long getCPtr(set_piece_hashes_listener obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(set_piece_hashes_listener obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_set_piece_hashes_listener(swigCPtr);
}
swigCPtr = 0;
}
}
protected void swigDirectorDisconnect() {
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
delete();
libtorrent_jni.delete_set_piece_hashes_listener(swigCPtr);
}
swigCPtr = 0;
}
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.set_piece_hashes_listener_change_ownership(this, swigCPtr, false);
}
protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.set_piece_hashes_listener_change_ownership(this, swigCPtr, true);
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.set_piece_hashes_listener_change_ownership(this, swigCPtr, false);
}
public void progress(int i) {
if (getClass() == set_piece_hashes_listener.class)
libtorrent_jni.set_piece_hashes_listener_progress(swigCPtr, this, i);
else
libtorrent_jni.set_piece_hashes_listener_progressSwigExplicitset_piece_hashes_listener(swigCPtr, this, i);
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.set_piece_hashes_listener_change_ownership(this, swigCPtr, true);
}
public void progress(int i) {
if (getClass() == set_piece_hashes_listener.class) libtorrent_jni.set_piece_hashes_listener_progress(swigCPtr, this, i); else libtorrent_jni.set_piece_hashes_listener_progressSwigExplicitset_piece_hashes_listener(swigCPtr, this, i);
}
public set_piece_hashes_listener() {
this(libtorrent_jni.new_set_piece_hashes_listener(), true);
libtorrent_jni.set_piece_hashes_listener_director_connect(this, swigCPtr, true, true);
}
}

View File

@ -9,55 +9,55 @@
package com.frostwire.jlibtorrent.swig;
public class swig_plugin {
protected transient boolean swigCMemOwn;
private transient long swigCPtr;
private transient long swigCPtr;
protected transient boolean swigCMemOwn;
protected swig_plugin(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected swig_plugin(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
public swig_plugin() {
this(libtorrent_jni.new_swig_plugin(), true);
libtorrent_jni.swig_plugin_director_connect(this, swigCPtr, true, true);
}
protected static long getCPtr(swig_plugin obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected static long getCPtr(swig_plugin obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
@SuppressWarnings("deprecation")
protected void finalize() {
delete();
}
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_swig_plugin(swigCPtr);
}
swigCPtr = 0;
}
}
protected void swigDirectorDisconnect() {
public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
delete();
libtorrent_jni.delete_swig_plugin(swigCPtr);
}
swigCPtr = 0;
}
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.swig_plugin_change_ownership(this, swigCPtr, false);
}
protected void swigDirectorDisconnect() {
swigCMemOwn = false;
delete();
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.swig_plugin_change_ownership(this, swigCPtr, true);
}
public void swigReleaseOwnership() {
swigCMemOwn = false;
libtorrent_jni.swig_plugin_change_ownership(this, swigCPtr, false);
}
public boolean on_dht_request(string_view query, udp_endpoint source, bdecode_node message, entry response) {
return (getClass() == swig_plugin.class) ? libtorrent_jni.swig_plugin_on_dht_request(swigCPtr, this, string_view.getCPtr(query), query, udp_endpoint.getCPtr(source), source, bdecode_node.getCPtr(message), message, entry.getCPtr(response), response) : libtorrent_jni.swig_plugin_on_dht_requestSwigExplicitswig_plugin(swigCPtr, this, string_view.getCPtr(query), query, udp_endpoint.getCPtr(source), source, bdecode_node.getCPtr(message), message, entry.getCPtr(response), response);
}
public void swigTakeOwnership() {
swigCMemOwn = true;
libtorrent_jni.swig_plugin_change_ownership(this, swigCPtr, true);
}
public boolean on_dht_request(string_view query, udp_endpoint source, bdecode_node message, entry response) {
return (getClass() == swig_plugin.class) ? libtorrent_jni.swig_plugin_on_dht_request(swigCPtr, this, string_view.getCPtr(query), query, udp_endpoint.getCPtr(source), source, bdecode_node.getCPtr(message), message, entry.getCPtr(response), response) : libtorrent_jni.swig_plugin_on_dht_requestSwigExplicitswig_plugin(swigCPtr, this, string_view.getCPtr(query), query, udp_endpoint.getCPtr(source), source, bdecode_node.getCPtr(message), message, entry.getCPtr(response), response);
}
public swig_plugin() {
this(libtorrent_jni.new_swig_plugin(), true);
libtorrent_jni.swig_plugin_director_connect(this, swigCPtr, true, true);
}
}

View File

@ -1,37 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.bdecode_node;
import com.frostwire.jlibtorrent.swig.byte_vector;
import com.frostwire.jlibtorrent.swig.error_code;
import com.frostwire.jlibtorrent.swig.torrent_info;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
/**
* @author gubatron
* @author aldenml
*/
public class BDecodeReadTest {
@Test
public void testRead() throws IOException {
byte[] data = Utils.resourceBytes("test5.torrent");
byte_vector buffer = Vectors.bytes2byte_vector(data);
bdecode_node e = new bdecode_node();
error_code ec = new error_code();
int ret = bdecode_node.bdecode(buffer, e, ec);
assertEquals("failed to decode torrent: " + ec.message(), ret, 0);
ec.clear();
torrent_info ti = new torrent_info(e, ec);
buffer.clear(); // prevents GC
assertEquals("failed to create torrent info: " + ec.message(), ret, 0);
}
}

View File

@ -1,120 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.create_torrent;
import com.frostwire.jlibtorrent.swig.entry;
import com.frostwire.jlibtorrent.swig.entry_vector;
import com.frostwire.jlibtorrent.swig.string_entry_map;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author gubatron
* @author aldenml
*/
public class ChangeTrackersTest {
@Test
public void testChangeTrackersUsingCreateTorrent() throws IOException {
byte[] torrentBytes = Utils.resourceBytes("test4.torrent");
TorrentInfo ti = TorrentInfo.bdecode(torrentBytes);
// do we have any tracker
assertTrue(ti.trackers().size() > 0);
entry e = entry.bdecode(Vectors.bytes2byte_vector(torrentBytes));
string_entry_map m = e.dict();
if (m.has_key("announce")) {
m.erase("announce");
}
if (m.has_key("announce-list")) {
m.erase("announce-list");
}
ti = TorrentInfo.bdecode(Vectors.byte_vector2bytes(e.bencode()));
// did we remove all trackers
assertEquals(ti.trackers().size(), 0);
create_torrent c = new create_torrent(ti.swig());
c.add_tracker("http://a:6969/announce", 0);
c.add_tracker("http://b:6969/announce", 1);
e = c.generate();
ti = TorrentInfo.bdecode(Vectors.byte_vector2bytes(e.bencode()));
ArrayList<AnnounceEntry> trackers = ti.trackers();
// do we have exactly the two added trackers
assertEquals(trackers.size(), 2);
assertEquals(trackers.get(0).url(), "http://a:6969/announce");
assertEquals(trackers.get(1).url(), "http://b:6969/announce");
}
@Test
public void testChangeTrackersLowLevel() throws IOException {
byte[] torrentBytes = Utils.resourceBytes("test4.torrent");
TorrentInfo ti = TorrentInfo.bdecode(torrentBytes);
// do we have any tracker
assertTrue(ti.trackers().size() > 0);
entry e = entry.bdecode(Vectors.bytes2byte_vector(torrentBytes));
string_entry_map m = e.dict();
// remove trackers
if (m.has_key("announce")) {
m.erase("announce");
}
if (m.has_key("announce-list")) {
m.erase("announce-list");
}
// add trackers
String[] tks = new String[]{"http://a:6969/announce", "http://b:6969/announce"};
entry_vector l = new entry_vector();
l.push_back(new entry(tks[0]));
m.set("announce", new entry(l));
entry_vector tl = new entry_vector();
for (int i = 0; i < tks.length; i++) {
l.clear();
l.push_back(new entry(tks[i]));
tl.push_back(new entry(l));
}
m.set("announce-list", new entry(tl));
ti = TorrentInfo.bdecode(Vectors.byte_vector2bytes(e.bencode()));
ArrayList<AnnounceEntry> trackers = ti.trackers();
// do we have exactly the two added trackers
assertEquals(trackers.size(), 2);
assertEquals(trackers.get(0).url(), "http://a:6969/announce");
assertEquals(trackers.get(1).url(), "http://b:6969/announce");
}
@Test
public void testChangeTrackersWithTorrentInfo() throws IOException {
byte[] torrentBytes = Utils.resourceBytes("test4.torrent");
TorrentInfo ti = TorrentInfo.bdecode(torrentBytes);
// do we have any tracker
assertTrue(ti.trackers().size() > 0);
ti.clearTrackers();
// did we remove all trackers
assertEquals(ti.trackers().size(), 0);
ti.addTracker("http://a:6969/announce", 0);
ti.addTracker("http://b:6969/announce", 1);
ArrayList<AnnounceEntry> trackers = ti.trackers();
// do we have exactly the two added trackers
assertEquals(trackers.size(), 2);
assertEquals(trackers.get(0).url(), "http://a:6969/announce");
assertEquals(trackers.get(1).url(), "http://b:6969/announce");
}
}

View File

@ -1,213 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.add_files_listener;
import com.frostwire.jlibtorrent.swig.byte_vector;
import com.frostwire.jlibtorrent.swig.create_flags_t;
import com.frostwire.jlibtorrent.swig.create_torrent;
import com.frostwire.jlibtorrent.swig.entry;
import com.frostwire.jlibtorrent.swig.error_code;
import com.frostwire.jlibtorrent.swig.file_storage;
import com.frostwire.jlibtorrent.swig.set_piece_hashes_listener;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.frostwire.jlibtorrent.swig.libtorrent.add_files_ex;
import static com.frostwire.jlibtorrent.swig.libtorrent.set_piece_hashes_ex;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author gubatron
* @author aldenml
*/
public class CreateTorrentTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Test
public void testFromFile() throws IOException {
final File f = folder.newFile("test.txt");
Utils.writeByteArrayToFile(f, new byte[]{0}, false);
file_storage fs = new file_storage();
add_files_listener l1 = new add_files_listener() {
@Override
public boolean pred(String p) {
assertEquals(f.getAbsolutePath(), p);
return true;
}
};
add_files_ex(fs, f.getAbsolutePath(), l1, new create_flags_t());
create_torrent ct = new create_torrent(fs);
set_piece_hashes_listener l2 = new set_piece_hashes_listener() {
@Override
public void progress(int i) {
assertTrue(i >= 0);
}
};
error_code ec = new error_code();
set_piece_hashes_ex(ct, f.getParent(), l2, ec);
assertEquals(ec.value(), 0);
entry e = ct.generate();
byte_vector buffer = e.bencode();
TorrentInfo ti = TorrentInfo.bdecode(Vectors.byte_vector2bytes(buffer));
assertEquals(1, ti.numFiles());
}
@Test
public void testFromDir() throws IOException {
File dir = folder.newFolder();
File f1 = new File(dir, "test.txt");
Utils.writeByteArrayToFile(f1, new byte[]{0}, false);
File f2 = new File(dir, "test1.txt");
Utils.writeByteArrayToFile(f2, new byte[]{0}, false);
file_storage fs = new file_storage();
add_files_listener l1 = new add_files_listener() {
@Override
public boolean pred(String p) {
return true;
}
};
add_files_ex(fs, dir.getAbsolutePath(), l1, new create_flags_t());
create_torrent ct = new create_torrent(fs);
set_piece_hashes_listener l2 = new set_piece_hashes_listener() {
@Override
public void progress(int i) {
assertTrue(i >= 0);
}
};
error_code ec = new error_code();
set_piece_hashes_ex(ct, dir.getParent(), l2, ec);
assertEquals(ec.value(), 0);
entry e = ct.generate();
byte_vector buffer = e.bencode();
TorrentInfo ti = TorrentInfo.bdecode(Vectors.byte_vector2bytes(buffer));
assertEquals(2, ti.numFiles());
}
@Test
public void testUsingBuilder() throws IOException {
File dir = folder.newFolder();
File f1 = new File(dir, "test.txt");
Utils.writeByteArrayToFile(f1, new byte[]{0}, false);
File f2 = new File(dir, "test1.txt");
Utils.writeByteArrayToFile(f2, new byte[]{0}, false);
TorrentBuilder b = new TorrentBuilder();
TorrentBuilder.Result r = b.path(dir)
.comment("comment")
.creator("creator")
.addUrlSeed("http://urlseed/")
.addHttpSeed("http://httpseed/")
.addNode(new Pair<>("1.1.1.1", 1))
.addTracker("udp://tracker/")
.setPrivate(true)
.addSimilarTorrent(Sha1Hash.min())
.addCollection("collection")
.generate();
TorrentInfo ti = TorrentInfo.bdecode(r.entry().bencode());
assertEquals("comment", ti.comment());
assertEquals("creator", ti.creator());
ArrayList<WebSeedEntry> seeds = ti.webSeeds();
for (WebSeedEntry e : seeds) {
if (e.type() == WebSeedEntry.Type.URL_SEED) {
assertEquals("http://urlseed/", e.url());
}
if (e.type() == WebSeedEntry.Type.HTTP_SEED) {
assertEquals("http://httpseed/", e.url());
}
}
assertEquals("1.1.1.1", ti.nodes().get(0).first);
assertEquals("udp://tracker/", ti.trackers().get(0).url());
assertEquals(true, ti.isPrivate());
assertTrue(ti.similarTorrents().get(0).isAllZeros());
assertEquals("collection", ti.collections().get(0));
assertEquals(2, ti.numFiles());
}
@Test
public void testBuilderListener() throws IOException {
File dir = folder.newFolder();
File f1 = new File(dir, "test.txt");
Utils.writeByteArrayToFile(f1, new byte[]{0, 0}, false);
File f2 = new File(dir, "test1.txt");
Utils.writeByteArrayToFile(f2, new byte[]{0, 0}, false);
final AtomicBoolean b1 = new AtomicBoolean();
final AtomicBoolean b2 = new AtomicBoolean();
TorrentBuilder b = new TorrentBuilder();
TorrentBuilder.Result r = b.path(dir)
.listener(new TorrentBuilder.Listener() {
@Override
public boolean accept(String filename) {
b1.set(true);
return true;
}
@Override
public void progress(int piece, int total) {
b2.set(true);
}
})
.generate();
TorrentInfo ti = TorrentInfo.bdecode(r.entry().bencode());
assertEquals(2, ti.numFiles());
assertTrue(b1.get());
assertTrue(b2.get());
}
/*
@Test
public void testBuilderMerkle() throws IOException {
File dir = folder.newFolder();
File f1 = new File(dir, "test.txt");
Utils.writeByteArrayToFile(f1, new byte[]{0, 0, 0}, false);
File f2 = new File(dir, "test1.txt");
Utils.writeByteArrayToFile(f2, new byte[]{0, 0, 0}, false);
TorrentBuilder b = new TorrentBuilder();
TorrentBuilder.Result r = b.path(dir)
.flags(b.flags() | TorrentBuilder.Flags.MERKLE.swig())
.generate();
TorrentInfo ti = TorrentInfo.bdecode(r.entry().bencode());
assertEquals(2, ti.numFiles());
ArrayList<Sha1Hash> tree = r.merkleTree();
assertTrue(tree.size() >= 0);
ti.merkleTree(tree);
assertEquals(tree.get(0), ti.merkleTree().get(0));
}*/
/*
@Test
public void testMerkleFlag() throws IOException {
TorrentBuilder b = new TorrentBuilder();
assertFalse(b.merkle());
b.merkle(false);
assertFalse(b.merkle());
b.merkle(true);
assertTrue(b.merkle());
b.merkle(true);
assertTrue(b.merkle());
b.merkle(false);
assertFalse(b.merkle());
b.merkle(false);
assertFalse(b.merkle());
}*/
}

View File

@ -1,96 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.entry;
import com.frostwire.jlibtorrent.swig.string_entry_map;
import com.frostwire.jlibtorrent.swig.string_vector;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author gubatron
* @author aldenml
*/
public class EntryTest {
@Test
public void testSimpleCreation() {
Map<String, Object> m = new HashMap<>();
m.put("a", 1);
m.put("b", "b");
m.put("c", new Entry("es"));
Entry e = Entry.fromMap(m);
List<Object> l = new ArrayList<Object>();
l.add("l1");
l.add("l2");
m.put("m", e);
m.put("l", l);
e = Entry.fromMap(m);
assertNotNull(e);
string_entry_map dict = e.swig().dict();
string_vector keys = dict.keys();
for (int i = 0; i < keys.size(); i++) {
String k = keys.get(i);
assertNotNull(dict.get(k).to_string());
}
}
@Test
public void testCreation1() {
//old school using libtorrent's (tedious if i may say) entry api
final entry url_list = new entry();
url_list.list().push_back(new entry("http://server1.com"));
url_list.list().push_back(new entry("http://server2.com"));
final entry swig_entry = new entry();
swig_entry.dict().set("url-list", url_list);
final Entry e = new Entry(swig_entry);
final String oldSchoolBencodedMapString = new String(e.bencode());
//now using Java's collection API
final List<String> urlList = new ArrayList<String>();
urlList.add("http://server1.com");
urlList.add("http://server2.com");
final Map<String, Object> urlListMap = new HashMap<String, Object>();
urlListMap.put("url-list", urlList);
final String javaAPIBencodedMapString = new String(Entry.fromMap(urlListMap).bencode());
final String expectedBencodedList = "d8:url-listl18:http://server1.com18:http://server2.comee";
assertEquals(expectedBencodedList, oldSchoolBencodedMapString);
assertEquals(expectedBencodedList, javaAPIBencodedMapString);
final Map<String, entry> torrentMap = new HashMap<String, entry>();
torrentMap.put("Comment", new entry("Torrent created with FrostWire"));
final Map<String, Object> ccMap = new HashMap<String, Object>();
ccMap.put("attributionAuthor", new entry("FrostWire LLC"));
ccMap.put("attributionTitle", new entry("FrostWire 5.7.7"));
ccMap.put("attributionUrl", "http://www.frostwire.com"); //on purpose not an entry
ccMap.put("licenseUrl", new entry("https://www.gnu.org/licenses/gpl.html"));
final Map<String, Object> openSourceMap = new HashMap<String, Object>();
//works both with an entry object created out of a Map, or straight up with the Map.
//openSourceMap.put("open-source", Entry.fromMap(ccMap).getSwig());
openSourceMap.put("open-source", ccMap);
final Map<String, entry> licenseMap = new HashMap<String, entry>();
licenseMap.put("license", Entry.fromMap(openSourceMap).swig());
final String expectedLicenseBencoded = "d7:licensed11:open-sourced17:attributionAuthor13:FrostWire LLC16:attributionTitle15:FrostWire 5.7.714:attributionUrl24:http://www.frostwire.com10:licenseUrl37:https://www.gnu.org/licenses/gpl.htmleee";
final String bencodedLicenseMap = new String(Entry.fromMap(licenseMap).bencode());
assertEquals(expectedLicenseBencoded, bencodedLicenseMap);
}
}

View File

@ -1,78 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author gubatron
* @author aldenml
*/
public class FetchMagnetTest {
//@Test
public void testRemoveAfterFetch() {
String sha1 = "a83cc13bf4a07e85b938dcf06aa707955687ca7c";
String uri = "magnet:?xt=urn:btih:" + sha1;
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(1);
// the session stats are posted about once per second.
AlertListener l = new AlertListener() {
@Override
public int[] types() {
return new int[]{AlertType.SESSION_STATS.swig(), AlertType.DHT_STATS.swig()};
}
@Override
public void alert(Alert<?> alert) {
if (alert.type().equals(AlertType.SESSION_STATS)) {
s.postDhtStats();
}
if (alert.type().equals(AlertType.DHT_STATS)) {
long nodes = s.stats().dhtNodes();
// wait for at least 10 nodes in the DHT.
if (nodes >= 10) {
signal.countDown();
}
}
}
};
s.addListener(l);
s.start();
s.postDhtStats();
// waiting for nodes in DHT (10 seconds)
boolean r = false;
try {
r = signal.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// ignore
}
assertTrue("DHT bootstrap timeout", r);
// no more trigger of DHT stats
s.removeListener(l);
// Fetching the magnet uri, waiting 30 seconds max
byte[] data = s.fetchMagnet(uri, 30);
assertNotNull("Failed to retrieve the magnet", data);
//TorrentHandle th = s.findTorrent(new Sha1Hash(sha1));
//assertNull(th);
s.stop();
}
}

View File

@ -1,100 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.PieceFinishedAlert;
import com.frostwire.jlibtorrent.alerts.TorrentCheckedAlert;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
/**
* @author gubatron
* @author aldenml
*/
public final class FileProgressTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private static void log(String msg) {
// comment/uncomment for hand debugging
//System.out.println(msg);
}
//@Test
public void testForceRecheck() throws Throwable {
String torrentFilename = "AJC_and_The_Envelope_Pushers_Fallen_Star_FrostClick_FrostWire_MP3_January_16_2017.torrent";
File torrentFile = folder.newFile(torrentFilename);
byte[] data = Utils.resourceBytes(torrentFilename);
Utils.writeByteArrayToFile(torrentFile, data, false);
final SessionManager s = new SessionManager();
final CountDownLatch signalFinished = new CountDownLatch(1);
s.addListener(new AlertListener() {
private boolean forceChecked = false;
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
((AddTorrentAlert) alert).handle().resume();
break;
case PIECE_FINISHED:
int progress = (int) (((PieceFinishedAlert) alert).handle().status().progress() * 100);
// this number represents the current progress of
// the current status (downloading or checking)
log("progress: " + progress);
if (progress > 2 && !forceChecked) {
forceChecked = true;
((PieceFinishedAlert) alert).handle().forceRecheck();
}
break;
case TORRENT_CHECKED:
log("Torrent checked, (forced: " + forceChecked + ")");
if (forceChecked) {
TorrentHandle th = ((TorrentCheckedAlert) alert).handle();
long[] fileProgress = th.fileProgress();
long total = 0;
for (long p : fileProgress) {
total += p;
}
assertNotEquals("At least one file should have some progress", 0, total);
}
break;
case TORRENT_FINISHED:
signalFinished.countDown();
break;
}
}
});
s.start();
TorrentInfo ti = new TorrentInfo(torrentFile);
s.download(ti, torrentFile.getParentFile());
Utils.awaitMinutes(signalFinished, "too much time downloading the torrent", 5);
assertNull(s.lastAlertError());
s.stop();
}
}

View File

@ -1,22 +0,0 @@
package com.frostwire.jlibtorrent;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
/**
* @author gubatron
* @author aldenml
*/
public class FileStorageTest {
@Test
public void testFileName() throws IOException {
byte[] data = Utils.resourceBytes("test5.torrent");
TorrentInfo ti = TorrentInfo.bdecode(data);
String name = ti.files().fileName(0);
assertEquals("frostwire-6.2.3.windows.fusion.exe", name);
}
}

View File

@ -1,90 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.PieceFinishedAlert;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author gubatron
* @author aldenml
*/
public final class GetPiecesTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private static void log(String msg) {
// comment/uncomment for hand debugging
//System.out.println(msg);
}
//@Test
public void testStatusPieces() throws Throwable {
String torrentFilename = "AJC_and_The_Envelope_Pushers_Fallen_Star_FrostClick_FrostWire_MP3_January_16_2017.torrent";
File torrentFile = folder.newFile(torrentFilename);
byte[] data = Utils.resourceBytes(torrentFilename);
Utils.writeByteArrayToFile(torrentFile, data, false);
final SessionManager s = new SessionManager();
final CountDownLatch signalFinished = new CountDownLatch(1);
s.addListener(new AlertListener() {
private boolean forceChecked = false;
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
((AddTorrentAlert) alert).handle().resume();
break;
case PIECE_FINISHED:
int progress = (int) (((PieceFinishedAlert) alert).handle().status().progress() * 100);
// this number represents the current progress of
// the current status (downloading or checking)
log("progress: " + progress);
if (progress > 4 && !forceChecked) {
forceChecked = true;
TorrentHandle th = ((PieceFinishedAlert) alert).handle();
PieceIndexBitfield pieces = th.status(TorrentHandle.QUERY_PIECES).pieces();
log("pieces size: " + pieces.size());
assertTrue(pieces.size() > 0);
assertTrue(pieces.count() > 0);
log("pieces value at 0: " + pieces.getBit(0));
signalFinished.countDown();
}
break;
}
}
});
s.start();
TorrentInfo ti = new TorrentInfo(torrentFile);
s.download(ti, torrentFile.getParentFile());
Utils.awaitMinutes(signalFinished, "too much time downloading the torrent", 5);
assertNull(s.lastAlertError());
s.stop();
}
}

View File

@ -1,78 +0,0 @@
package com.frostwire.jlibtorrent;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created on 12/21/16.
*
* @author aldenml
* @author gubatron
*/
public class IntSeriesTest {
private static void printArray(String name, int[] arr) {
System.out.print(name + " [ ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
if (i != arr.length - 1) {
System.out.print(", ");
}
}
System.out.println(" ]");
}
private static void debugAddElement(IntSeries circular, int elem) {
//System.out.println(">>> Adding " + elem);
circular.add(elem);
//printArray("internal buffer", circular.getBufferCopy());
//printArray(" tail", circular.tail(3));
//System.out.println();
}
@Test
public void addAndGetTest() {
IntSeries series = new IntSeries(3);
assertEquals("addAndGetTest 1", 0, series.size());
debugAddElement(series, 1);
assertEquals("addAndGetTest 2.a", 1, series.size());
assertEquals("addAndGetTest 2.b", 1, series.get(0));
debugAddElement(series, 2);
assertEquals("addAndGetTest 3.a", 2, series.size());
assertEquals("addAndGetTest 3.b", 1, series.get(0));
assertEquals("addAndGetTest 3.c", 2, series.get(1));
debugAddElement(series, 3);
assertEquals("addAndGetTest 4.a", 3, series.size());
assertEquals("addAndGetTest 4.b", 1, series.get(0));
assertEquals("addAndGetTest 4.c", 2, series.get(1));
assertEquals("addAndGetTest 4.d", 3, series.get(2));
debugAddElement(series, 4);
assertEquals("addAndGetTest 5.a", 2, series.get(0));
assertEquals("addAndGetTest 5.b", 3, series.get(1));
assertEquals("addAndGetTest 5.c", 4, series.get(2));
debugAddElement(series, 5);
assertEquals("addAndGetTest 6.a", 3, series.get(0));
assertEquals("addAndGetTest 6.b", 4, series.get(1));
assertEquals("addAndGetTest 6.c", 5, series.get(2));
debugAddElement(series, 6);
assertEquals("addAndGetTest 7.a", 4, series.get(0));
assertEquals("addAndGetTest 7.b", 5, series.get(1));
assertEquals("addAndGetTest 7.c", 6, series.get(2));
debugAddElement(series, 7);
assertEquals("addAndGetTest 8.a", 5, series.get(0));
assertEquals("addAndGetTest 8.b", 6, series.get(1));
assertEquals("addAndGetTest 8.c", 7, series.get(2));
}
}

View File

@ -1,21 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.int_vector;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author aldenml
* @author gubatron
*/
public class PriorityTest {
@Test
public void testArray2vector() {
Priority[] arr = Priority.array(Priority.FOUR, 10);
int_vector vec = Priority.array2vector(arr);
assertEquals(arr.length, vec.size());
}
}

View File

@ -1,22 +0,0 @@
package com.frostwire.jlibtorrent;
import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
/**
* @author gubatron
* @author aldenml
*/
public class Sha1HashTest {
@Test
public void testHashCode() {
byte[] arr = new byte[20];
Arrays.fill(arr, (byte) 2);
Sha1Hash h = new Sha1Hash(arr);
assertEquals(Arrays.hashCode(arr), h.hashCode());
}
}

View File

@ -1,27 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.session_params;
import com.frostwire.jlibtorrent.swig.settings_pack;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class StartPausedSessionTest {
@Test
public void startSessionPausedTest() {
SessionManager sessionManager = new SessionManager();
sessionManager.start(new SessionParams(new session_params(new settings_pack())),
SessionHandle.PAUSED);
assertEquals(sessionManager.isPaused(), true);
sessionManager.stop();
}
@Test
public void startSessionNonPausedTest() {
SessionManager sessionManager = new SessionManager();
sessionManager.start(new SessionParams(new session_params(new settings_pack())));
assertEquals(sessionManager.isPaused(), false);
sessionManager.stop();
}
}

View File

@ -1,25 +0,0 @@
package com.frostwire.jlibtorrent;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* @author gubatron
* @author aldenml
*/
public class StatsMetricTest {
@Test
public void testListStatsMetric() {
List<StatsMetric> metrics = LibTorrent.sessionStatsMetrics();
for (StatsMetric m : metrics) {
assertEquals(m.valueIndex, LibTorrent.findMetricIdx(m.name));
}
assertEquals(-1, LibTorrent.findMetricIdx("anything"));
}
}

View File

@ -1,136 +0,0 @@
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.PieceFinishedAlert;
import com.frostwire.jlibtorrent.alerts.SaveResumeDataAlert;
import com.frostwire.jlibtorrent.alerts.TorrentFinishedAlert;
import com.frostwire.jlibtorrent.alerts.TorrentPausedAlert;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author gubatron
* @author aldenml
*/
public final class StatusDurationTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private long activeDuration = 0;
private Entry resumeData;
private static void log(String msg) {
// comment/uncomment for hand debugging
System.out.println(msg);
}
//@Test
public void testDuration() throws Throwable {
String torrentFilename = "AJC_and_The_Envelope_Pushers_Fallen_Star_FrostClick_FrostWire_MP3_January_16_2017.torrent";
File torrentFile = folder.newFile(torrentFilename);
byte[] data = Utils.resourceBytes(torrentFilename);
Utils.writeByteArrayToFile(torrentFile, data, false);
final SessionManager s = new SessionManager();
final CountDownLatch signal1 = new CountDownLatch(1);
final CountDownLatch signal2 = new CountDownLatch(1);
s.addListener(new AlertListener() {
private boolean paused = false;
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
((AddTorrentAlert) alert).handle().resume();
break;
case PIECE_FINISHED:
int progress = (int) (((PieceFinishedAlert) alert).handle().status().progress() * 100);
// this number represents the current progress of
// the current status (downloading or checking)
log("progress: " + progress);
if (progress > 2 && !paused) {
paused = true;
((PieceFinishedAlert) alert).handle().pause();
}
break;
case TORRENT_PAUSED:
log("Torrent paused");
TorrentHandle th = ((TorrentPausedAlert) alert).handle();
th.saveResumeData();
break;
case SAVE_RESUME_DATA:
// TODO: restore later
resumeData = null;//((SaveResumeDataAlert) alert).resumeData();
TorrentHandle th2 = ((SaveResumeDataAlert) alert).handle();
TorrentStatus status2 = th2.status();
activeDuration = status2.activeDuration();
signal1.countDown();
break;
case TORRENT_FINISHED:
TorrentHandle th1 = ((TorrentFinishedAlert) alert).handle();
TorrentStatus status1 = th1.status();
activeDuration = status1.activeDuration();
signal2.countDown();
break;
}
}
});
s.start();
TorrentInfo ti = new TorrentInfo(torrentFile);
s.download(ti, torrentFile.getParentFile());
Utils.awaitMinutes(signal1, "too much time downloading the torrent 2%", 5);
assertNull(s.lastAlertError());
s.stop();
log("activeDuration: " + activeDuration);
//log(resumeData.toString());
long savedActiveDuration = resumeData.dictionary().get("active_time").integer() * 1000;
assertEquals(activeDuration, savedActiveDuration);
File resumeFile = folder.newFile("resume.data");
Utils.writeByteArrayToFile(resumeFile, resumeData.bencode(), false);
Thread.sleep(10000);
s.start();
long timeMark = System.currentTimeMillis();
s.download(ti, torrentFile.getParentFile(), resumeFile, null, null);
Utils.awaitMinutes(signal2, "too much time downloading the torrent 100%", 5);
assertNull(s.lastAlertError());
log("activeDuration: " + activeDuration);
long t1 = activeDuration - savedActiveDuration; // time active in the 98%
long t2 = System.currentTimeMillis() - timeMark; // approximate time in the 98%
assertTrue(t2 - t1 < 2000); // active time should not be affected by the sleep(10000)
}
}

View File

@ -1,21 +0,0 @@
package com.frostwire.jlibtorrent;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author gubatron
* @author aldenml
*/
public class TcpEndpointTest {
@Test
public void testToString() {
TcpEndpoint endp1 = new TcpEndpoint("1.1.1.1", 80);
assertEquals("1.1.1.1:80", endp1.toString());
TcpEndpoint endp2 = new TcpEndpoint("::1", 80);
assertEquals("[::1]:80", endp2.toString());
}
}

View File

@ -1,359 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.frostwire.jlibtorrent;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertTrue;
public final class Utils {
/**
* The extension separator character.
*
* @since 1.4
*/
public static final char EXTENSION_SEPARATOR = '.';
/**
* The Unix separator character.
*/
private static final char UNIX_SEPARATOR = '/';
/**
* The Windows separator character.
*/
private static final char WINDOWS_SEPARATOR = '\\';
private static final int EOF = -1;
private Utils() {
}
/**
* Gets the name minus the path from a full filename.
* <p>
* This method will handle a file in either Unix or Windows format.
* The text after the last forward or backslash is returned.
* <pre>
* a/b/c.txt --> c.txt
* a.txt --> a.txt
* a/b/c --> c
* a/b/c/ --> ""
* </pre>
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to query, null returns null
* @return the name of the file without the path, or an empty string if none exists
*/
public static String getName(String filename) {
if (filename == null) {
return null;
}
int index = indexOfLastSeparator(filename);
return filename.substring(index + 1);
}
/**
* Gets the base name, minus the full path and extension, from a full filename.
* <p>
* This method will handle a file in either Unix or Windows format.
* The text after the last forward or backslash and before the last dot is returned.
* <pre>
* a/b/c.txt --> c
* a.txt --> a
* a/b/c --> c
* a/b/c/ --> ""
* </pre>
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to query, null returns null
* @return the name of the file without the path, or an empty string if none exists
*/
public static String getBaseName(String filename) {
return removeExtension(getName(filename));
}
//-----------------------------------------------------------------------
/**
* Removes the extension from a filename.
* <p>
* This method returns the textual part of the filename before the last dot.
* There must be no directory separator after the dot.
* <pre>
* foo.txt --> foo
* a\b\c.jpg --> a\b\c
* a\b\c --> a\b\c
* a.b\c --> a.b\c
* </pre>
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to query, null returns null
* @return the filename minus the extension
*/
public static String removeExtension(String filename) {
if (filename == null) {
return null;
}
int index = indexOfExtension(filename);
if (index == -1) {
return filename;
} else {
return filename.substring(0, index);
}
}
/**
* Returns the index of the last extension separator character, which is a dot.
* <p>
* This method also checks that there is no directory separator after the last dot.
* To do this it uses {@link #indexOfLastSeparator(String)} which will
* handle a file in either Unix or Windows format.
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to find the last path separator in, null returns -1
* @return the index of the last separator character, or -1 if there
* is no such character
*/
public static int indexOfExtension(String filename) {
if (filename == null) {
return -1;
}
int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
int lastSeparator = indexOfLastSeparator(filename);
return lastSeparator > extensionPos ? -1 : extensionPos;
}
/**
* Returns the index of the last directory separator character.
* <p>
* This method will handle a file in either Unix or Windows format.
* The position of the last forward or backslash is returned.
* <p>
* The output will be the same irrespective of the machine that the code is running on.
*
* @param filename the filename to find the last path separator in, null returns -1
* @return the index of the last separator character, or -1 if there
* is no such character
*/
public static int indexOfLastSeparator(String filename) {
if (filename == null) {
return -1;
}
int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
return Math.max(lastUnixPos, lastWindowsPos);
}
/**
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
* Use this method instead of <code>toByteArray(InputStream)</code>
* when <code>InputStream</code> size is known
*
* @param input the <code>InputStream</code> to read from
* @param size the size of <code>InputStream</code>
* @return the requested byte array
* @throws java.io.IOException if an I/O error occurs or <code>InputStream</code> size differ from parameter size
* @throws IllegalArgumentException if size is less than zero
* @since 2.1
*/
public static byte[] toByteArray(InputStream input, int size) throws IOException {
if (size < 0) {
throw new IllegalArgumentException("Size must be equal or greater than zero: " + size);
}
if (size == 0) {
return new byte[0];
}
byte[] data = new byte[size];
int offset = 0;
int readed;
while (offset < size && (readed = input.read(data, offset, size - offset)) != EOF) {
offset += readed;
}
if (offset != size) {
throw new IOException("Unexpected readed size. current: " + offset + ", excepted: " + size);
}
return data;
}
/**
* Get contents of an <code>InputStream</code> as a <code>byte[]</code>.
* Use this method instead of <code>toByteArray(InputStream)</code>
* when <code>InputStream</code> size is known.
* <b>NOTE:</b> the method checks that the length can safely be cast to an int without truncation
* before using {@link Utils#toByteArray(java.io.InputStream, int)} to read into the byte array.
* (Arrays can have no more than Integer.MAX_VALUE entries anyway)
*
* @param input the <code>InputStream</code> to read from
* @param size the size of <code>InputStream</code>
* @return the requested byte array
* @throws IOException if an I/O error occurs or <code>InputStream</code> size differ from parameter size
* @throws IllegalArgumentException if size is less than zero or size is greater than Integer.MAX_VALUE
* @see Utils#toByteArray(java.io.InputStream, int)
* @since 2.1
*/
public static byte[] toByteArray(InputStream input, long size) throws IOException {
if (size > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size);
}
return toByteArray(input, (int) size);
}
//-----------------------------------------------------------------------
/**
* Opens a {@link java.io.FileInputStream} for the specified file, providing better
* error messages than simply calling <code>new FileInputStream(file)</code>.
* <p>
* At the end of the method either the stream will be successfully opened,
* or an exception will have been thrown.
* <p>
* An exception is thrown if the file does not exist.
* An exception is thrown if the file object exists but is a directory.
* An exception is thrown if the file exists but cannot be read.
*
* @param file the file to open for input, must not be {@code null}
* @return a new {@link java.io.FileInputStream} for the specified file
* @throws java.io.FileNotFoundException if the file does not exist
* @throws IOException if the file object is a directory
* @throws IOException if the file cannot be read
* @since 1.3
*/
public static FileInputStream openInputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
}
if (file.canRead() == false) {
throw new IOException("File '" + file + "' cannot be read");
}
} else {
throw new FileNotFoundException("File '" + file + "' does not exist");
}
return new FileInputStream(file);
}
/**
* Reads the contents of a file into a byte array.
* The file is always closed.
*
* @param file the file to read, must not be {@code null}
* @return the file contents, never {@code null}
* @throws IOException in case of an I/O error
* @since 1.1
*/
public static byte[] readFileToByteArray(File file) throws IOException {
return Files.bytes(file);
}
public static String toHex(byte[] bytes) {
return Hex.encode(bytes);
}
public static byte[] fromHex(String str) {
return Hex.decode(str);
}
public static FileOutputStream openOutputStream(File file, boolean append) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a directory");
}
if (file.canWrite() == false) {
throw new IOException("File '" + file + "' cannot be written to");
}
} else {
File parent = file.getParentFile();
if (parent != null) {
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new IOException("Directory '" + parent + "' could not be created");
}
}
}
return new FileOutputStream(file, append);
}
public static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException {
OutputStream out = null;
try {
out = openOutputStream(file, append);
out.write(data);
out.close(); // don't swallow close Exception if copy completes normally
} finally {
Files.closeQuietly(out);
}
}
public static byte[] resourceBytes(String path) throws IOException {
ClassLoader classLoader = Utils.class.getClassLoader();
InputStream input = classLoader.getResourceAsStream(path);
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
int n = 0;
byte[] buffer = new byte[1024 * 4];
while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
} finally {
Files.closeQuietly(input);
Files.closeQuietly(output);
}
}
public static File home(String path) {
return new File(System.getProperty("user.home"), path);
}
static void await(CountDownLatch s, String message, long timeout, TimeUnit unit) {
boolean r = false;
try {
r = s.await(timeout, unit);
} catch (InterruptedException e) {
// ignore
}
assertTrue(message, r);
}
static void awaitSeconds(CountDownLatch s, String message, long timeout) {
await(s, message, timeout, TimeUnit.SECONDS);
}
static void awaitMinutes(CountDownLatch s, String message, long timeout) {
await(s, message, timeout, TimeUnit.MINUTES);
}
}

View File

@ -1,52 +0,0 @@
/*
* Created by Angel Leon (@gubatron), Alden Torres (aldenml)
*
* Licensed under the MIT License.
*/
package com.frostwire.jlibtorrent;
import com.frostwire.jlibtorrent.swig.byte_vector;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author aldenml
* @author gubatron
*/
public class VectorsTest {
@Test
public void testByteVector2String() {
byte_vector v = new byte_vector();
v.push_back((byte) 'A');
v.push_back((byte) 'B');
v.push_back((byte) 'C');
assertEquals(Vectors.byte_vector2ascii(v), "ABC");
v.clear();
v.push_back((byte) 'A');
v.push_back((byte) 'B');
v.push_back((byte) 0);
assertEquals(Vectors.byte_vector2ascii(v), "AB");
v.clear();
v.push_back((byte) 0);
v.push_back((byte) 0);
v.push_back((byte) 0);
assertEquals(Vectors.byte_vector2ascii(v), "");
v.clear();
v.push_back((byte) 'A');
v.push_back((byte) 0);
v.push_back((byte) 'B');
assertEquals(Vectors.byte_vector2ascii(v), "A");
v.clear();
v.push_back((byte) 194);
v.push_back((byte) 181);
assertEquals(Vectors.byte_vector2utf8(v), "µ");
}
}

View File

@ -1,152 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.alerts.Alerts;
import com.frostwire.jlibtorrent.alerts.TorrentAlert;
import java.io.File;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
* @author gubatron
* @author aldenml
*/
public final class AlertsSwitch {
public static void main(String[] args) throws Exception {
printForAlerts();
System.out.println("=============================");
printForTorrentAlertsAdapter();
System.out.println("=============================");
printForAlertType();
}
private static void printForAlerts() throws Exception {
Class[] arr = getSwigAlerts();
for (int i = 0; i < arr.length; i++) {
String s = "arr[" + i + "] = new CastLambda() { @Override public Alert cast(alert a) { return new ";
if (arr[i] != null) {
String c = capitalizeAlertTypeName(arr[i].getSimpleName());
s += c + "(cast_to_" + arr[i].getSimpleName() + "(a));";
} else {
s += "GenericAlert(a);";
}
s += "}};";
System.out.println(s);
}
}
private static void printForTorrentAlertsAdapter() throws Exception {
Class[] arr = getSwigAlerts();
for (int i = 0; i < arr.length; i++) {
String s = "arr[" + i + "] = new InvokeLambda() { @Override public void invoke(TorrentAlertAdapter l, Alert a) { ";
if (arr[i] != null) {
String c = capitalizeAlertTypeName(arr[i].getSimpleName());
Class<?> alertClass = Class.forName("com.frostwire.jlibtorrent.alerts." + c);
if (TorrentAlert.class.isAssignableFrom(alertClass)) {
String cc = Character.toLowerCase(c.charAt(0)) + c.substring(1);
cc = cc.replace("Alert", "");
s += "l." + cc + "((" + c + ")a);";
s += "}};";
} else {
s = "arr[" + i + "] = null;";
}
} else {
s = "arr[" + i + "] = null;";
}
System.out.println(s);
}
}
private static void printForAlertType() throws Exception {
Class[] arr = getSwigAlerts();
for (int i = 0; i < arr.length; i++) {
String s = "arr[" + i + "] = ";
if (arr[i] != null) {
String c = arr[i].getSimpleName().toUpperCase();
c = c.replace("_ALERT", "");
s += c + ";";
} else {
s += "UNKNOWN;";
}
System.out.println(s);
}
}
private static Class[] getSwigAlerts() throws Exception {
int n = 0;
Class[] arr = new Class[Alerts.NUM_ALERT_TYPES];
for (Class c : getClasses("com.frostwire.jlibtorrent.swig")) {
if (c.getName().endsWith("_alert")) {
Field f = c.getDeclaredField("alert_type");
int type = f.getInt(null);
arr[type] = c;
n++;
}
}
return arr;
}
private static Class[] getClasses(String packageName) throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
String path = packageName.replace('.', '/');
Enumeration<URL> resources = cl.getResources(path);
List<File> dirs = new ArrayList<>();
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
dirs.add(new File(resource.getFile()));
}
ArrayList<Class> classes = new ArrayList<>();
for (File directory : dirs) {
classes.addAll(findClasses(directory, packageName));
}
return classes.toArray(new Class[classes.size()]);
}
private static List<Class> findClasses(File directory, String packageName) throws Exception {
List<Class> classes = new ArrayList<>();
if (!directory.exists()) {
return classes;
}
File[] files = directory.listFiles();
for (File file : files) {
if (file.isDirectory()) {
classes.addAll(findClasses(file, packageName + "." + file.getName()));
} else if (file.getName().endsWith(".class")) {
classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
}
}
return classes;
}
private static String capitalizeAlertTypeName(String s) {
StringBuilder sb = new StringBuilder(s.length());
boolean capitalize = true;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (capitalize) {
sb.append(Character.toUpperCase(ch));
capitalize = false;
} else if (ch == '_') {
capitalize = true;
} else {
sb.append(ch);
}
}
return sb.toString();
}
}

View File

@ -1,251 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.Ed25519;
import com.frostwire.jlibtorrent.Entry;
import com.frostwire.jlibtorrent.Pair;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.Sha1Hash;
import com.frostwire.jlibtorrent.TcpEndpoint;
import com.frostwire.jlibtorrent.Utils;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.DhtPutAlert;
import com.frostwire.jlibtorrent.alerts.ListenFailedAlert;
import com.frostwire.jlibtorrent.alerts.ListenSucceededAlert;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @author gubatron
* @author aldenml
*/
public final class DhtShell {
public static void main(String[] args) throws Throwable {
AlertListener mainListener = new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
if (type == AlertType.LISTEN_SUCCEEDED) {
ListenSucceededAlert a = (ListenSucceededAlert) alert;
log(a.message());
}
if (type == AlertType.LISTEN_FAILED) {
ListenFailedAlert a = (ListenFailedAlert) alert;
log(a.message());
}
if (type == AlertType.DHT_PUT) {
DhtPutAlert a = (DhtPutAlert) alert;
log(a.message());
}
}
};
SessionManager s = new SessionManager();
s.addListener(mainListener);
s.start();
try {
File f = new File("dht_shell.dat");
if (f.exists()) {
byte[] data = Utils.readFileToByteArray(f);
s.loadState(data);
}
} catch (Throwable e) {
log(e.getMessage());
}
Scanner in = new Scanner(System.in);
while (true) {
System.out.print("$ ");
String line = in.nextLine().trim();
if (is_quit(line)) {
quit(s);
} else if (is_put(line)) {
put(s, line);
} else if (is_get(line)) {
get(s, line);
} else if (is_get_peers(line)) {
get_peers(s, line);
} else if (is_announce(line)) {
announce(s, line);
} else if (is_mkeys(line)) {
mkeys(line);
} else if (is_mput(line)) {
mput(s, line);
} else if (is_mget(line)) {
mget(s, line);
} else if (is_magnet(line)) {
magnet(s, line);
} else if (is_count_nodes(line)) {
count_nodes(s);
} else if (is_invalid(line)) {
invalid(line);
}
}
}
private static void print(String s, boolean dollar) {
System.out.println();
System.out.println(s);
if (dollar) {
System.out.print("$ ");
}
}
private static void print(String s) {
print(s, false);
}
private static void log(String s) {
print(s, true);
}
private static boolean is_quit(String s) {
s = s.split(" ")[0];
return s.equals("quit") || s.equals("exit") || s.equals("stop");
}
private static void quit(SessionManager s) {
print("Exiting...");
byte[] data = s.saveState();
try {
Utils.writeByteArrayToFile(new File("dht_shell.dat"), data, false);
} catch (Throwable e) {
print(e.getMessage());
}
s.stop();
System.exit(0);
}
private static boolean is_put(String s) {
return s.startsWith("put ");
}
private static void put(SessionManager sm, String s) {
String data = s.split(" ")[1];
String sha1 = sm.dhtPutItem(new Entry(data)).toString();
print("Wait for completion of put for key: " + sha1);
}
private static boolean is_get(String s) {
return s.startsWith("get ");
}
private static void get(SessionManager sm, String s) {
String sha1 = s.split(" ")[1];
print("Waiting a max of 20 seconds to get data for key: " + sha1);
Entry data = sm.dhtGetItem(new Sha1Hash(sha1), 20);
print(data.toString());
}
private static boolean is_get_peers(String s) {
return s.startsWith("get_peers ");
}
private static void get_peers(SessionManager sm, String s) {
String sha1 = s.split(" ")[1];
print("Waiting a max of 20 seconds to get peers for key: " + sha1);
ArrayList<TcpEndpoint> peers = sm.dhtGetPeers(new Sha1Hash(sha1), 20);
print(peers.toString());
}
private static boolean is_announce(String s) {
return s.startsWith("announce ");
}
private static void announce(SessionManager sm, String s) {
String sha1 = s.split(" ")[1];
sm.dhtAnnounce(new Sha1Hash(sha1), 9000, 0);
print("Wait for completion of announce for key: " + sha1);
}
private static boolean is_mkeys(String s) {
return s.startsWith("mkeys");
}
private static void mkeys(String s) {
byte[] seed = Ed25519.createSeed();
Pair<byte[], byte[]> keypair = Ed25519.createKeypair(seed);
byte[] publicKey = keypair.first;
byte[] privateKey = keypair.second;
byte[][] keys = new byte[2][];
keys[0] = publicKey;
keys[1] = privateKey;
String msg = "Save this key pair\n";
msg += "Public: " + Utils.toHex(keys[0]) + "\n";
msg += "Private: " + Utils.toHex(keys[1]) + "\n";
print(msg);
}
private static boolean is_mput(String s) {
return s.startsWith("mput ");
}
private static void mput(SessionManager sm, String s) {
String[] arr = s.split(" ");
byte[] publicKey = Utils.fromHex(arr[1]);
byte[] privateKey = Utils.fromHex(arr[2]);
String data = arr[3];
sm.dhtPutItem(publicKey, privateKey, new Entry(data), new byte[0]);
print("Wait for completion of mput for public key: " + arr[1]);
}
private static boolean is_mget(String s) {
return s.startsWith("mget ");
}
private static void mget(SessionManager sm, String s) {
String[] arr = s.split(" ");
byte[] publicKey = Utils.fromHex(arr[1]);
print("Waiting a max of 20 seconds to get mutable data for public key: " + arr[1]);
SessionManager.MutableItem data = sm.dhtGetItem(publicKey, new byte[0], 20);
print(data.item.toString());
}
private static boolean is_magnet(String s) {
return s.startsWith("magnet ");
}
private static void magnet(SessionManager session, String s) {
String sha1 = s.split(" ")[1];
String uri = "magnet:?xt=urn:btih:" + sha1;
print("Waiting a max of 20 seconds to fetch magnet for sha1: " + sha1);
byte[] data = session.fetchMagnet(uri, 20);
print(Entry.bdecode(data).toString());
}
private static boolean is_count_nodes(String s) {
return s.startsWith("count_nodes");
}
private static void count_nodes(SessionManager s) {
log("DHT contains " + s.stats().dhtNodes() + " nodes");
}
private static boolean is_invalid(String s) {
return !s.isEmpty();
}
private static void invalid(String s) {
print("Invalid command: " + s + "\n" + "Try ? for help");
}
}

View File

@ -1,72 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.LibTorrent;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.TorrentInfo;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.BlockFinishedAlert;
import java.io.File;
import java.util.concurrent.CountDownLatch;
/**
* @author gubatron
* @author aldenml
*/
public final class DownloadTorrent {
public static void main(String[] args) throws Throwable {
// comment this line for a real application
args = new String[]{"/Users/aldenml/Downloads/Honey_Larochelle_Hijack_FrostClick_FrostWire_MP3_May_06_2016.torrent"};
File torrentFile = new File(args[0]);
System.out.println("Using libtorrent version: " + LibTorrent.version());
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(1);
s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
System.out.println("Torrent added");
((AddTorrentAlert) alert).handle().resume();
break;
case BLOCK_FINISHED:
BlockFinishedAlert a = (BlockFinishedAlert) alert;
int p = (int) (a.handle().status().progress() * 100);
System.out.println("Progress: " + p + " for torrent name: " + a.torrentName());
System.out.println(s.stats().totalDownload());
break;
case TORRENT_FINISHED:
System.out.println("Torrent finished");
signal.countDown();
break;
}
}
});
s.start();
TorrentInfo ti = new TorrentInfo(torrentFile);
s.download(ti, torrentFile.getParentFile());
signal.await();
s.stop();
}
}

View File

@ -1,61 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.EnumNet;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.swig.ip_route_vector;
import java.util.List;
/**
* @author gubatron
* @author aldenml
*/
public final class EnumNetTest {
public static void main(String[] args) throws Throwable {
SessionManager s = new SessionManager();
s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
System.out.println(alert);
//System.out.println("listen_interfaces: " + s.listenInterfaces());
}
});
s.start();
System.out.println("Enum interfaces");
List<EnumNet.IpInterface> ipInterfaces = EnumNet.enumInterfaces(s);
for (EnumNet.IpInterface iface : ipInterfaces) {
System.out.println(iface);
}
System.out.println("Enum routers");
List<EnumNet.IpRoute> ipRoutes = EnumNet.enumRoutes(s);
for (EnumNet.IpRoute route : ipRoutes) {
System.out.println(route);
}
ip_route_vector ip_routes = new ip_route_vector();
for (EnumNet.IpRoute route : ipRoutes) {
ip_routes.push_back(route.swig());
}
for (EnumNet.IpInterface iface : ipInterfaces) {
System.out.println("Default gateway for iface=" + iface + " -> " + EnumNet.getGateway(s, iface, ip_routes));
}
System.out.println("Press ENTER to exit");
System.in.read();
s.stop();
}
}

View File

@ -1,85 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.Entry;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.SessionParams;
import com.frostwire.jlibtorrent.SettingsPack;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* @author gubatron
* @author aldenml
*/
public final class GetMagnet {
public static void main(String[] args) throws Throwable {
//String uri = "magnet:?xt=urn:btih:86d0502ead28e495c9e67665340f72aa72fe304e&dn=Frostwire.5.3.6.+%5BWindows%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Fopen.demonii.com%3A1337";
String uri = "magnet:?xt=urn:btih:a83cc13bf4a07e85b938dcf06aa707955687ca7c";
final SessionManager s = new SessionManager();
//final SessionManager s = new SessionManager(true);
/*s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
System.out.println(alert);
}
});*/
SettingsPack sp = new SettingsPack();
//sp.listenInterfaces("0.0.0.0:43567");
//sp.listenInterfaces("[::]:43567");
//sp.listenInterfaces("0.0.0.0:43567,[::]:43567");
//sp.setString(settings_pack.string_types.dht_bootstrap_nodes.swigValue(), "router.silotis.us:6881");
//sp.setString(settings_pack.string_types.dht_bootstrap_nodes.swigValue(), "router.bittorrent.com:6881");
//sp.setString(settings_pack.string_types.dht_bootstrap_nodes.swigValue(), "dht.transmissionbt.com:6881");
SessionParams params = new SessionParams(sp);
s.start(params);
final CountDownLatch signal = new CountDownLatch(1);
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
long nodes = s.stats().dhtNodes();
// wait for at least 10 nodes in the DHT.
if (nodes >= 10) {
System.out.println("DHT contains " + nodes + " nodes");
signal.countDown();
timer.cancel();
}
}
}, 0, 1000);
System.out.println("Waiting for nodes in DHT (10 seconds)...");
boolean r = signal.await(40, TimeUnit.SECONDS);
if (!r) {
System.out.println("DHT bootstrap timeout");
System.exit(0);
}
System.out.println("Fetching the magnet uri, please wait...");
byte[] data = s.fetchMagnet(uri, 30);
if (data != null) {
System.out.println(Entry.bdecode(data));
} else {
System.out.println("Failed to retrieve the magnet");
}
s.stop();
}
}

View File

@ -1,93 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author gubatron
* @author aldenml
*/
public final class GetMagnet2 {
public static void main(String[] args) throws Throwable {
final String uri = "magnet:?xt=urn:btih:a83cc13bf4a07e85b938dcf06aa707955687ca7c";
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(1);
// the session stats are posted about once per second.
AlertListener l = new AlertListener() {
@Override
public int[] types() {
return new int[]{AlertType.SESSION_STATS.swig(), AlertType.DHT_STATS.swig()};
}
@Override
public void alert(Alert<?> alert) {
if (alert.type().equals(AlertType.SESSION_STATS)) {
s.postDhtStats();
}
if (alert.type().equals(AlertType.DHT_STATS)) {
long nodes = s.stats().dhtNodes();
// wait for at least 10 nodes in the DHT.
if (nodes >= 10) {
System.out.println("DHT contains " + nodes + " nodes");
signal.countDown();
}
}
}
};
s.addListener(l);
s.start();
s.postDhtStats();
System.out.println("Waiting for nodes in DHT (10 seconds)...");
boolean r = signal.await(10, TimeUnit.SECONDS);
if (!r) {
System.out.println("DHT bootstrap timeout");
System.exit(0);
}
// no more trigger of DHT stats
s.removeListener(l);
System.out.println("Fetching the magnet uri (multi thread), please wait...");
final AtomicInteger counter = new AtomicInteger(0);
for (int i = 0; i < 50; i++) {
final int index = i;
Thread t = new Thread() {
@Override
public void run() {
byte[] data = s.fetchMagnet(uri, 30);
int count = counter.incrementAndGet();
if (data != null) {
System.out.println("Success fetching magnet: " + index + "/" + count);
} else {
System.out.println("Failed to retrieve the magnet: " + index + "/" + count);
}
}
};
t.start();
//t.join();
}
System.out.println("Press ENTER to exit");
System.in.read();
s.stop();
}
}

View File

@ -1,124 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.Priority;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.TorrentHandle;
import com.frostwire.jlibtorrent.TorrentInfo;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.StatsAlert;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Time;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* To test issue https://github.com/frostwire/frostwire-jlibtorrent/issues/180
*
* @author gubatron
* @author aldenml
*/
public final class GetMagnet3 {
public static void main(String[] args) throws Throwable {
// code taken from
// https://github.com/frostwire/frostwire-jlibtorrent/issues/180#issuecomment-345458935
// author proninyaroslav
final String magnet = "<magnet here>";
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(1);
// the session stats are posted about once per second.
AlertListener l = new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
switch (alert.type()) {
case ADD_TORRENT:
System.out.println("Torrent added");
TorrentHandle th = ((AddTorrentAlert) alert).handle();
th.resume();
TorrentInfo ti = th.torrentFile();
Priority[] p = th.filePriorities();
p[0] = Priority.IGNORE;
System.out.println("Expected priorities:");
for (int i = 0; i < ti.numFiles(); i++)
System.out.println(String.format("priority=%-8sfile=%s",
p[i],
ti.files().fileName(i)));
System.out.println();
th.prioritizeFiles(p);
break;
case STATS:
th = ((StatsAlert) alert).handle();
ti = th.torrentFile();
p = th.filePriorities();
System.out.println(String.format("[%s] Current priorities:",
new Time(System.currentTimeMillis())));
for (int i = 0; i < ti.numFiles(); i++)
System.out.println(String.format("priority=%-8sfile=%s",
p[i],
ti.files().fileName(i)));
System.out.println();
break;
case TORRENT_FINISHED:
System.out.println("Torrent finished\n");
break;
}
}
};
s.addListener(l);
s.start();
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
long nodes = s.stats().dhtNodes();
if (nodes >= 10) {
System.out.println("DHT contains " + nodes + " nodes");
signal.countDown();
timer.cancel();
}
}
}, 0, 1000);
System.out.println("Waiting for nodes in DHT (10 seconds)...");
boolean r = signal.await(10, TimeUnit.SECONDS);
if (!r) {
System.out.println("DHT bootstrap timeout");
System.exit(0);
}
System.out.println("Fetching the magnet uri, please wait...");
byte[] data = s.fetchMagnet(magnet, 30, true);
if (data == null) {
System.out.println("data == null");
s.stop();
return;
}
File f = File.createTempFile("test", "torrent");
FileOutputStream fos = new FileOutputStream(f);
fos.write(data);
s.download(new TorrentInfo(f), new File(System.getProperty("user.dir")));
System.in.read();
s.stop();
}
}

View File

@ -1,118 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.Priority;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.TorrentHandle;
import com.frostwire.jlibtorrent.TorrentInfo;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.MetadataReceivedAlert;
import com.frostwire.jlibtorrent.alerts.StatsAlert;
import java.sql.Time;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* To test issue https://github.com/frostwire/frostwire-jlibtorrent/issues/174
*
* @author gubatron
* @author aldenml
*/
public final class GetMagnet4 {
public static void main(String[] args) throws Throwable {
final String magnet = "<magnet here>";
final SessionManager s = new SessionManager();
AlertListener l = new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
switch (alert.type()) {
case ADD_TORRENT:
System.out.println("Torrent added");
TorrentHandle th = ((AddTorrentAlert) alert).handle();
th.resume();
break;
case METADATA_RECEIVED:
th = ((MetadataReceivedAlert) alert).handle();
TorrentInfo ti = th.torrentFile();
Priority[] p = th.filePriorities();
p[0] = Priority.IGNORE;
System.out.println("Expected priorities:");
for (int i = 0; i < ti.numFiles(); i++)
System.out.println(String.format("priority=%-8sfile=%s",
p[i],
ti.files().fileName(i)));
System.out.println();
th.prioritizeFiles(p);
break;
case STATS:
th = ((StatsAlert) alert).handle();
ti = th.torrentFile();
// ti is null while the metadata is not received
if (ti != null) {
p = th.filePriorities();
System.out.println(String.format("[%s] Current priorities:",
new Time(System.currentTimeMillis())));
for (int i = 0; i < ti.numFiles(); i++)
System.out.println(String.format("priority=%-8sfile=%s",
p[i],
ti.files().fileName(i)));
System.out.println();
}
break;
case TORRENT_FINISHED:
System.out.println("Torrent finished\n");
break;
}
}
};
s.addListener(l);
s.start();
waitForNodesInDHT(s);
System.out.println("About to download magnet: " + magnet);
s.download(magnet, null);
System.in.read();
s.stop();
}
private static void waitForNodesInDHT(final SessionManager s) throws InterruptedException {
final CountDownLatch signal = new CountDownLatch(1);
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
long nodes = s.stats().dhtNodes();
if (nodes >= 10) {
System.out.println("DHT contains " + nodes + " nodes");
signal.countDown();
timer.cancel();
}
}
}, 0, 1000);
System.out.println("Waiting for nodes in DHT (10 seconds)...");
boolean r = signal.await(10, TimeUnit.SECONDS);
if (!r) {
System.out.println("DHT bootstrap timeout");
System.exit(0);
}
}
}

View File

@ -1,166 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.Entry;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.TorrentInfo;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.BlockFinishedAlert;
import com.frostwire.jlibtorrent.alerts.DhtErrorAlert;
import com.frostwire.jlibtorrent.alerts.PieceFinishedAlert;
import com.frostwire.jlibtorrent.alerts.StateUpdateAlert;
import com.frostwire.jlibtorrent.alerts.TorrentErrorAlert;
import com.frostwire.jlibtorrent.alerts.TorrentFinishedAlert;
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* To test issue https://github.com/frostwire/frostwire-jlibtorrent/issues/195
*
* @author gubatron
* @author aldenml
*/
public final class GetMagnet5 {
public static void main(String[] args) throws Throwable {
final String magnet = "magnet:?xt=urn:btih:737d38ed01da1df727a3e0521a6f2c457cb812de&dn=HOME+-+a+film+by+Yann+Arthus-Bertrand+%282009%29+%5BEnglish%5D+%5BHD+MP4%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.zer0day.to%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969";
final SessionManager s = new SessionManager();
startdl(magnet, s);
System.in.read();
s.stop();
}
private static void waitForNodesInDHT(final SessionManager s) throws InterruptedException {
final CountDownLatch signal = new CountDownLatch(1);
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
long nodes = s.stats().dhtNodes();
if (nodes >= 10) {
System.out.println("DHT contains " + nodes + " nodes");
signal.countDown();
timer.cancel();
}
}
}, 0, 1000);
System.out.println("Waiting for nodes in DHT (10 seconds)...");
boolean r = signal.await(10, TimeUnit.SECONDS);
if (!r) {
System.out.println("DHT bootstrap timeout");
System.exit(0);
}
}
private static void log(String s) {
System.out.println(s);
}
private static void startdl(String magnetLink, SessionManager sm) throws InterruptedException {
//Torrent dbTorrent = torrentService.findByTorrentName(name);
String link = magnetLink;//dbTorrent.getPathToTorrent();
File saveDir = new File("torrents/");
if (!saveDir.exists()) {
saveDir.mkdirs();
}
final SessionManager s = sm;//storrent.getSessionManager();
AlertListener l = new AlertListener() {
private int grade = 0;
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
//((AddTorrentAlert) alert).handle().setFlags(TorrentFlags.SEQUENTIAL_DOWNLOAD);
((AddTorrentAlert) alert).handle().resume();
break;
case PIECE_FINISHED:
int progress = (int) (((PieceFinishedAlert) alert).handle().status().progress() * 100);
if (grade < progress / 20) {
int index = (int) (((PieceFinishedAlert) alert).pieceIndex());
log("index: " + index);
grade += 1;
s.downloadRate();
log(progress + " % downloaded");
}
System.out.println("PIECE_FINISHED");
break;
case TORRENT_FINISHED:
grade = 0;
((TorrentFinishedAlert) alert).handle().pause();
System.out.println("TORRENT_FINISHED");
break;
case TORRENT_ERROR:
log(((TorrentErrorAlert) alert).what());
log("is paused = " + ((TorrentErrorAlert) alert).handle().status());
break;
case BLOCK_FINISHED:
System.out.println("HERE: " + ((BlockFinishedAlert) alert).handle().status().progress());
progress = (int) (((BlockFinishedAlert) alert).handle().status().progress() * 100);
if (grade < progress / 20) {
int index = (int) (((BlockFinishedAlert) alert).pieceIndex());
log("index: " + index);
grade += 1;
s.downloadRate();
log(progress + " % downloaded");
}
System.out.println("BLOCK_FINISHED");
break;
case STATE_UPDATE:
log(((StateUpdateAlert) alert).message());
break;
case METADATA_RECEIVED:
log("metadata received");
break;
case DHT_ERROR:
log("dht error");
log(((DhtErrorAlert) alert).message());
break;
default:
break;
}
}
};
s.addListener(l);
if (s.isRunning() != true)
s.start();
if (link.startsWith("magnet:?")) {
waitForNodesInDHT(s);
byte[] data = s.fetchMagnet(link, 30);
TorrentInfo ti = TorrentInfo.bdecode(data);
log(Entry.bdecode(data).toString());
log("is valid ? =" + ti.isValid());
s.download(ti, saveDir);
log("torrent added with name = " + ti.name());
//storrent.addTh(s.find(ti.infoHash()), name);
log(s.find(ti.infoHash()).isValid() + " isvalid");
log("torrent added to session");
//this.videoname = ti.name();
int i = 0;
while (i < 20) {
TimeUnit.SECONDS.sleep(1);
log(s.find(ti.infoHash()).status().state() + " state");
log(s.find(ti.infoHash()).status().progress() * 100 + " progress");
i++;
}
}
}
}

View File

@ -1,39 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.PiecesTracker;
import com.frostwire.jlibtorrent.TorrentInfo;
import java.io.File;
/**
* @author gubatron
* @author aldenml
*/
public final class PieceMap {
public static void main(String[] args) throws Throwable {
// comment this line for a real application
args = new String[]{"/Users/aldenml/Downloads/ReSet_Resynthformation_SOSEP051_FrostClick_FrostWire_6_28_2014.torrent"};
File torrentFile = new File(args[0]);
TorrentInfo ti = new TorrentInfo(torrentFile);
int numFiles = ti.numFiles();
int numPieces = ti.numPieces();
System.out.println("Num Pieces: " + numPieces);
PiecesTracker tracker = new PiecesTracker(ti);
for (int i = 0; i < numPieces / 2; i++) {
tracker.setComplete(i, true);
}
for (int i = 0; i < numFiles; i++) {
System.out.println("File index (seq)completed: " + tracker.getSequentialDownloadedBytes(i));
}
}
}

View File

@ -1,50 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.BDecodeNode;
import com.frostwire.jlibtorrent.Entry;
import com.frostwire.jlibtorrent.Plugin;
import com.frostwire.jlibtorrent.SessionHandle;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.UdpEndpoint;
import com.frostwire.jlibtorrent.alerts.Alert;
/**
* @author gubatron
* @author aldenml
*/
public final class PluginTest {
public static void main(String[] args) throws Throwable {
SessionManager s = new SessionManager();
s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
System.out.println(alert);
}
});
s.start();
SessionHandle h = new SessionHandle(s.swig());
h.addExtension(new Plugin() {
@Override
public boolean onDhtRequest(String query, UdpEndpoint source, BDecodeNode message, Entry response) {
System.out.println("DHT MSG: " + query + ", from: " + source);
return false;
}
});
System.out.println("Press ENTER to exit");
System.in.read();
s.stop();
}
}

View File

@ -1,104 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.TorrentInfo;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.BlockFinishedAlert;
import com.frostwire.jlibtorrent.swig.libtorrent;
import com.frostwire.jlibtorrent.swig.posix_stat_t;
import com.frostwire.jlibtorrent.swig.posix_wrapper;
import java.io.File;
import java.util.concurrent.CountDownLatch;
/**
* @author gubatron
* @author aldenml
*/
public final class PosixTest {
public static void main(String[] args) throws Throwable {
posix_wrapper p = new posix_wrapper() {
@Override
public int open(String path, int flags, int mode) {
System.out.println("open: " + path);
return super.open(path, flags, mode);
}
@Override
public int stat(String path, posix_stat_t buf) {
System.out.println("stat: " + path);
return super.stat(path, buf);
}
@Override
public int mkdir(String path, int mode) {
System.out.println("mkdir: " + path);
return super.mkdir(path, mode);
}
@Override
public int rename(String oldpath, String newpath) {
System.out.println("rename: " + newpath);
return super.rename(oldpath, newpath);
}
@Override
public int remove(String path) {
System.out.println("remove: " + path);
return super.remove(path);
}
};
p.swigReleaseOwnership();
libtorrent.set_posix_wrapper(p);
// comment this line for a real application
args = new String[]{"/Users/aldenml/Downloads/Honey_Larochelle_Hijack_FrostClick_FrostWire_MP3_May_06_2016.torrent"};
File torrentFile = new File(args[0]);
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(1);
s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
System.out.println("Torrent added");
((AddTorrentAlert) alert).handle().resume();
break;
case BLOCK_FINISHED:
BlockFinishedAlert a = (BlockFinishedAlert) alert;
int p = (int) (a.handle().status().progress() * 100);
System.out.println("Progress: " + p + " for torrent name: " + a.torrentName());
System.out.println(s.stats().totalDownload());
break;
}
}
});
s.start();
TorrentInfo ti = new TorrentInfo(torrentFile);
s.download(ti, torrentFile.getParentFile());
signal.await();
s.stop();
}
}

View File

@ -1,18 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.LibTorrent;
import com.frostwire.jlibtorrent.StatsMetric;
/**
* @author gubatron
* @author aldenml
*/
public final class PrintMetrics {
public static void main(String[] args) throws Throwable {
for (StatsMetric m : LibTorrent.sessionStatsMetrics()) {
System.out.println(m);
}
}
}

View File

@ -1,23 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.BDecodeNode;
import com.frostwire.jlibtorrent.Utils;
import java.io.File;
/**
* @author gubatron
* @author aldenml
*/
public final class ReadBEncoded {
public static void main(String[] args) throws Throwable {
args = new String[]{"/Users/aldenml/Downloads/303dde355f99c9b903efaeba57e23194a7a6713f.resume"};
byte[] data = Utils.readFileToByteArray(new File(args[0]));
BDecodeNode n = BDecodeNode.bdecode(data);
System.out.println(n);
}
}

View File

@ -1,35 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.TorrentInfo;
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
/**
* @author gubatron
* @author aldenml
*/
public final class ReadTorrent {
public static void main(String[] args) throws Throwable {
args = new String[]{"/Users/aldenml/Downloads/Honey_Larochelle_Hijack_FrostClick_FrostWire_MP3_May_06_2016.torrent"};
File torrentFile = new File(args[0]);
System.out.println("Reading all in memory");
TorrentInfo ti = new TorrentInfo(torrentFile);
System.out.println("info-hash: " + ti.infoHash());
System.out.println(ti.toEntry());
System.out.println("Reading with memory mapped");
FileChannel fc = new RandomAccessFile(args[0], "r").getChannel();
MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
TorrentInfo ti2 = new TorrentInfo(buffer);
System.out.println("info-hash: " + ti2.infoHash());
System.out.println("creator: " + ti2.creator());
System.out.println("comment: " + ti2.comment());
System.out.println(ti2.toEntry());
}
}

View File

@ -1,101 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.Entry;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.TorrentHandle;
import com.frostwire.jlibtorrent.TorrentInfo;
import com.frostwire.jlibtorrent.TorrentStatus;
import com.frostwire.jlibtorrent.Utils;
import com.frostwire.jlibtorrent.Vectors;
import com.frostwire.jlibtorrent.alerts.AddTorrentAlert;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.AlertType;
import com.frostwire.jlibtorrent.alerts.SaveResumeDataAlert;
import com.frostwire.jlibtorrent.alerts.StatsAlert;
import com.frostwire.jlibtorrent.swig.add_torrent_params;
import com.frostwire.jlibtorrent.swig.byte_vector;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
public final class ResumeTest {
public static void main(String[] args) throws Throwable {
File torrentFile = new File("/Users/aldenml/Downloads/FROSTCLICK_FROSTWIRE_CREATIVE_COMMONS_MIXTAPE_VOL_6__MP3__December_2017.torrent");
final SessionManager s = new SessionManager();
final CountDownLatch signal = new CountDownLatch(10);
final CountDownLatch signalResumeData = new CountDownLatch(1);
s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
AlertType type = alert.type();
switch (type) {
case ADD_TORRENT:
System.out.println("Torrent added");
((AddTorrentAlert) alert).handle().resume();
break;
case TORRENT_FINISHED:
System.out.println("Torrent finished");
//((TorrentFinishedAlert) alert).handle().saveResumeData(TorrentHandle.SAVE_INFO_DICT);
break;
case TORRENT_PAUSED:
System.out.println("Torrent paused");
break;
case SAVE_RESUME_DATA:
System.out.println("Torrent saveResumeData");
serializeResumeData((SaveResumeDataAlert) alert);
signalResumeData.countDown();
break;
case STATS:
TorrentHandle th = ((StatsAlert) alert).handle();
if (th.status().isFinished()) {
TorrentStatus ts = th.status();
System.out.println(String.format("seeding time=%d\nactive time=%d\n",
ts.seedingDuration(), ts.activeDuration()));
signal.countDown();
}
break;
}
}
});
s.start();
TorrentInfo ti = new TorrentInfo(torrentFile);
s.download(ti, torrentFile.getParentFile());
signal.await();
// save resume data just before restarting session
s.find(ti.infoHash()).saveResumeData(TorrentHandle.SAVE_INFO_DICT);
signalResumeData.await();
System.out.println(Entry.bdecode(new File("resume.dat")).toString());
s.restart();
s.download(ti, torrentFile.getParentFile(), new File("resume.dat"), null, null);
System.in.read();
s.stop();
}
private static void serializeResumeData(SaveResumeDataAlert alert) {
File resume = new File("resume.dat");
if (resume.exists())
return;
byte_vector data = add_torrent_params.write_resume_data(alert.params().swig()).bencode();
try {
Utils.writeByteArrayToFile(resume, Vectors.byte_vector2bytes(data), false);
} catch (IOException e) {
System.err.println("Error saving resume data");
}
}
}

View File

@ -1,36 +0,0 @@
package com.frostwire.jlibtorrent.demo;
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.SessionManager;
import com.frostwire.jlibtorrent.alerts.Alert;
/**
* @author gubatron
* @author aldenml
*/
public final class SessionTest {
public static void main(String[] args) throws Throwable {
SessionManager s = new SessionManager();
s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}
@Override
public void alert(Alert<?> alert) {
System.out.println(alert);
}
});
s.start();
System.out.println("Press ENTER to exit");
System.in.read();
s.stop();
}
}

Some files were not shown because too many files have changed in this diff Show More