Coder Social home page Coder Social logo

aldenml / libtorrent4j Goto Github PK

View Code? Open in Web Editor NEW
193.0 11.0 32.0 4.69 MB

libtorrent for java, a swig Java interface for libtorrent

Home Page: http://libtorrent4j.org

License: Other

Java 37.91% Shell 0.32% C++ 60.16% SWIG 1.53% CMake 0.03% Dockerfile 0.05%
bittorrent java cpp library p2p libtorrent peer-to-peer webtorrent dht dht-network android jni swig-binding cpp-bindings torrent swig

libtorrent4j's Introduction

libtorrent4j

macOS Linux Windows Android Codacy Badge Codacy Badge Maven Central

A swig Java interface for libtorrent.

Features
Support for WebTorrent https://webtorrent.io
Sequential downloading
Torrents queueing and prioritizing
Torrent content selection and prioritizing
NAT-PMP and UPnP support
Fast resume support
HTTP proxies and basic authentication
IP filter
Torrents over SSL
lt_donthave extension BEP 54
Magnet URI extension - specify indices to download BEP 53
BitTorrent Protocol v2 BEP 52
DHT Infohash Indexing BEP 51
Tracker Protocol Extension: Scrape BEP 48
Padding files and attributes BEP 47
Multiple-address operation for the DHT BEP 45
Storing arbitrary data in the DHT BEP 44
Read-only DHT Nodes BEP 43
IPv6 extension for DHT BEP 32
uTorrent transport protocol (uTP) BEP 29
Private Torrents BEP 27
Tracker Returns External IP BEP 24
Tracker Returns Compact Peer Lists BEP 23
Extension for Partial Seeds BEP 21
HTTP/FTP Seeding (GetRight-style) BEP 19
Superseeding BEP 16
UDP Tracker Protocol BEP 15
Local Service Discovery (LSD) BEP 14
Multitracker Metadata Extension BEP 12
Peer Exchange (PEX) BEP 11
Extension Protocol BEP 10
Magnet links BEP 9
IPv6 Tracker Extension BEP 7
Distributed hash table (DHT) BEP 5

Using

Download the latest JAR or get the dependency via Maven:

<dependency>
  <groupId>org.libtorrent4j</groupId>
  <artifactId>libtorrent4j</artifactId>
  <version>2.x.x</version>
</dependency>

or Gradle:

compile 'org.libtorrent4j:libtorrent4j:2.x.x'

If you use ProGuard to obfuscate/minify make sure to add the following statement

-keep class org.libtorrent4j.swig.libtorrent_jni {*;}

Note that there are multiple versions of libtorrent4j for different platforms:

libtorrent4j
libtorrent4j-android-<arch>
libtorrent4j-macos
libtorrent4j-linux
libtorrent4j-windows

These are all different artifacts, you need to select according to your architecture.

For examples look at demos and tests.

Architectures supported:

  • Android (armeabi-v7a, arm64-v8a, x86, x86_64)
  • macOS (x86_64)
  • Linux (x86_64)
  • Windows (x86_64)

About stability

This library tracks libtorrent master branch. The branch is very stable, runs a lot of tests, and receives bug fixes quickly.

Android local builds

It's possible to build android binaries locally. The solution is docker based, you need to have Docker installed and running (see https://docs.docker.com/engine/install/).

Go to the folder swig/android-build and perform all the operations inside it.

1 - Build the docker image just one time (takes a long time):

docker build -t lt4j:latest .

2 - Select your architecture and run the build script, for example:

./build-arm.sh

3 - Collect the jars in build/libs at the root of the project. Repeat the step 2) for the desired architectures.

License

Licensed under the terms of the MIT license, available here.

libtorrent4j's People

Contributors

aldenml avatar gubatron avatar proninyaroslav avatar xkevin190 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libtorrent4j's Issues

java.lang.NullPointerException: Attempt to invoke virtual method 'int org.libtorrent4j.alerts.AlertType.ordinal()' on a null object reference

I got a fatal exception, here is the log:
I use version "2.0.3-17"

E/AndroidRuntime: FATAL EXCEPTION: SessionManager-alertsLoop
java.lang.NullPointerException: Attempt to invoke virtual method 'int org.libtorrent4j.alerts.AlertType.ordinal()' on a null object reference
at org.libtorrent4j.SessionManager$5.run(SessionManager.java:1170)
at java.lang.Thread.run(Thread.java:919)

I debug it, and get the alert.type() is 97
then I check the source code in https://github.com/arvidn/libtorrent/blob/RC_2_0/include/libtorrent/alert_types.hpp
There is a alert named "TORRENT_DEFINE_ALERT(file_prio_alert, 97)"
It seems something wrong with the alert type 97

how to split a torrent file when download?

I want to separate a torrent into multiple files, similar to splitting a complete file into N files, so as to facilitate me to operate a single file, may I ask if there is a way to achieve this?
thx.

Unable to download torrent on Android 11 (API 30)

I have a problem when using API level 30. Libtorrent4j seems not working on it. When I start a new session, it doesn't listen to any network. Below are logs from the torrent alert.

LOG - log - start session
LOG - log - version: 2.0.4.0 revision: f9836137a
LOG - log - max-connections: 200 max-files: 32768
LOG - log -  *** session thread init
LOG - log -  done starting session
LOG - log - RECALCULATE UNCHOKE SLOTS: [ peers: 0 eligible-peers: 0 allowed-slots: 8 ]
LOG - log - update listen interfaces: 0.0.0.0:6881,[::]:6881
LOG - log - parsed listen interfaces count: 2, ifaces: 0.0.0.0:6881,[::]:6881
LOG - log - not starting DHT announce timer: m_dht == nullptr
LOG - log -  *** session paused ***
LOG - log - about to stop DHT, running: false
LOG - log - starting DHT, running: false, router lookups: 0

This won't happen when I'm running my app on Android 10 devices or using API 29.

I found this in another discussion. It might help. https://stackoverflow.com/questions/64884994/cannot-bind-netlink-socket-when-targeting-android-api-30

Thanks.

Do you have these boost 1.73.0 build issues too? (error: feature "lto" : "off" "on" "gold" : "composite" "propagated" "link-incompatible")

It seems something changed with boost 1.73 and lto compiler features. I wonder if you're also having issues building with boost 1.73.0, I notice you no longer download the boost libraries from their mirror, instead you clone the repo.

Did you come across this issue?

LIBTORRENT_ROOT = /Users/gubatron/src/libtorrent
/Users/gubatron/src/boost_1_73_0/tools/build/src/build/feature.jam:140: in feature from module feature
error: feature already defined:
error: in feature declaration:
error: feature "lto" : "off" "on" "gold" : "composite" "propagated" "link-incompatible"
Jamfile:56: in load-aux from module Jamfile</Users/gubatron/workspace.frostwire/frostwire-jlibtorrent/swig>
/Users/gubatron/src/boost_1_73_0/tools/build/src/build/project.jam:378: in load-jamfile from module project
/Users/gubatron/src/boost_1_73_0/tools/build/src/build/project.jam:64: in load from module project
/Users/gubatron/src/boost_1_73_0/tools/build/src/build/project.jam:142: in project.find from module project
/Users/gubatron/src/boost_1_73_0/tools/build/src/build-system.jam:618: in load from module build-system
/Users/gubatron/src/boost_1_73_0/tools/build/src/kernel/modules.jam:295: in import from module modules
/Users/gubatron/src/boost_1_73_0/tools/build/src/kernel/bootstrap.jam:139: in boost-build from module
/Users/gubatron/src/boost_1_73_0/boost-build.jam:17: in module scope from module

I suppose it refers to this part of the JamFile back at jlibtorrent

feature lto : off on gold : composite propagated link-incompatible ;
feature.compose <lto>on : <cxxflags>-flto <linkflags>-flto ;
feature.compose <lto>gold : <cxxflags>-flto <linkflags>-flto
    <linkflags>-fuse-ld=gold ;

Sucks how overly complex this C++ world is and how they keep changing and breaking shit.

[Android] POSIX wrapper issues, 1.3.0-alpha-5

Hi. I dare to suggest that most POSIX wrapper methods are not called after adding torrent. At least there is no open, mkdir, opendir. If necessary, I can get strace. They don't appear in the log, which means they are not called. remove works, good news (#45):

(this is magnet link download)
D: [stat] path=/Чернышев А.А. - «Аскольд». Лучший крейсер Порт-Артурской эскадры (2017).pdf
D: [stat] path=/.878a4cbc6d6b19abc8a292eb7e4edb4872a9cd2a.parts
D: [remove] path=/Чернышев А.А. - «Аскольд». Лучший крейсер Порт-Артурской эскадры (2017).pdf
D: [remove] path=/.878a4cbc6d6b19abc8a292eb7e4edb4872a9cd2a.parts
(this is after adding torrent)
D: [stat] path=/saf_root(com.android.externalstorage.documents/tree/1018-230F%3A);/Чернышев А.А. - «Аскольд». Лучший крейсер Порт-Артурской эскадры (2017).pdf
D: [stat] path=/saf_root(com.android.externalstorage.documents/tree/1018-230F%3A);/.878a4cbc6d6b19abc8a292eb7e4edb4872a9cd2a.parts
D: [stat] path=/saf_root(com.android.externalstorage.documents/tree/1018-230F%3A);/

For this reason, I can't download torrent using SAF (Session log):

E: Torrent 878a4cbc6d6b19abc8a292eb7e4edb4872a9cd2a: No such file or directory, code 2 [FILE_OPEN][Чернышев А.А. - «Аскольд». Лучший крейсер Порт-Артурской эскадры (2017).pdf] 

OFFTOP: As you can see earlier, without disabled storage option, libtorrent tries to save the magnet to the root:

D: [stat] path=/Чернышев А.А. - «Аскольд». Лучший крейсер Порт-Артурской эскадры (2017).pdf
D: [stat] path=/.878a4cbc6d6b19abc8a292eb7e4edb4872a9cd2a.parts
D: [remove] path=/Чернышев А.А. - «Аскольд». Лучший крейсер Порт-Артурской эскадры (2017).pdf
D: [remove] path=/.878a4cbc6d6b19abc8a292eb7e4edb4872a9cd2a.parts

This is not critical, since I get metadata as the array of bytes.

Segmentation fault on downloading using DownloadTorrent demo code

Hi,

I'm trying to use libtorrent4j on a JVM server and Android. Most smaller torrents download OK. However 100MB+ torrents seem to cause a segmentation fault. eg Downloading the Libreoffice torrent from FossTorrents:

samih@samih-Lenovo-ideapad-520-15IKB:~/src/libtorrent4j$ java -Xmx5120M -verbose:gc -classpath build/libs/libtorrent4j-2.0.4-21.jar:demo/build/libs/demo.jar org.libtorrent4j.demo.DownloadTorrent /home/samih/Downloads/LibreOffice_7.1.5_Win_x64.msi.torrent Progress: 91 for torrent name: LibreOffice_7.1.5_Win_x64.msi
....
Progress: 91 for torrent name: LibreOffice_7.1.5_Win_x64.msi
318073981
Progress: 91 for torrent name: LibreOffice_7.1.5_Win_x64.msi
318073981
Segmentation fault (core dumped)

This is using OpenJDK11 on Ubuntu. Java version as follows:

java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

I can't find the actual core dump file (e.g. hs_err etc). I tried increasing the memory allocated using the Xmx parameters, that doesn't seem to change it. The segmentation fault doesn't always happen at the same time, but it does happen most of the time.

Is there something we can do to get the actual dump to further debug what is going on here?

Thanks!

[Android] An app with POSIX wrapper crashes if launched in debug mode

Hello. This happens in Android Studio (current version 3.4), Android 8.1 and below. Tested on Android 8.1 (arm64, x86), 7.1.1 (x86) and 4.4 (x86). Android 9 hasn't this problem, tested on x86 and x86_64 architecture.

Steps to reproduce:

  1. Launch an app in debug mode
  2. Do some file I/O in libtorrent with default POSIX wrapper (a child class, that calls only super methods, for example super.stat())
  3. Crash occurs:
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 10500 (Thread-15), pid 10377 (retorrent.debug)

A: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
A: LineageOS Version: '15.1-20190224-NIGHTLY-angler'
A: Build fingerprint: 'google/angler/angler:8.1.0/OPM7.181205.001/5080180:user/release-keys'
A: Revision: '0'
A: ABI: 'arm64'
A: pid: 10039, tid: 10230, name: Thread-17  >>> org.proninyaroslav.libretorrent.debug <<<
A: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
A: Cause: null pointer dereference
A:     x0   0000000000000000  x1   0000000000040000  x2   00000077d9d26e30  x3   0000000000000010
A:     x4   00000077d9d26d90  x5   0000000000000000  x6   0000000000000000  x7   00000077dccadfc0
A:     x8   00000077dcbf14a0  x9   0000000000000002  x10  0000000000000002  x11  0000000000000000
A:     x12  00000077dccae140  x13  00000077dccae170  x14  00000000ffffffff  x15  000000000000002b
A:     x16  000000787aa94240  x17  000000787a9e54d0  x18  000000000000002c  x19  00000077da4ea600
A:     x20  0000000000000010  x21  00000077d9d26e30  x22  0000000000000002  x23  0000000000040000
A:     x24  00000077ebe95600  x25  00000077d9d270b0  x26  0000000000000002  x27  0000000000000010
A:     x28  0000000000040000  x29  00000077d9d26d80  x30  00000077dc79342c
A:     sp   00000077d9d26d20  pc   00000077dc724278  pstate 0000000040000000
A: backtrace:
A:     #00 pc 000000000019c278  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #01 pc 000000000020b428  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #02 pc 000000000020dacc  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #03 pc 000000000020bbc8  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #04 pc 000000000020add8  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #05 pc 0000000000186cd8  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #06 pc 0000000000183a1c  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #07 pc 00000000001883c4  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #08 pc 00000000001886dc  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #09 pc 0000000000190f58  /data/app/org.proninyaroslav.libretorrent.debug-_cbSvDDA0hNLvZJd6s96sQ==/lib/arm64/libtorrent4j-1.2.1.0.so
A:     #10 pc 0000000000068e84  /system/lib64/libc.so (__pthread_start(void*)+36)
A:     #11 pc 000000000001ec30  /system/lib64/libc.so (__start_thread+68)
E: Tombstone written to: /data/tombstones/tombstone_39

UnsatisfiedLinkError when matching State.CHECKING_RESUME_DATA enum in switch block

Version: 2.0.1-7
OS: Android

Usage example: https://github.com/proninyaroslav/libretorrent/blob/fdfbd604e66c988c6d9aeef771b9a4eabaa3db22/app/src/main/java/org/proninyaroslav/libretorrent/core/model/session/TorrentDownloadImpl.java#L1344

Stack trace:

Rejecting re-init on previously-failed class java.lang.Class<org.proninyaroslav.libretorrent.core.model.session.TorrentDownloadImpl$1>: java.lang.UnsatisfiedLinkError: No implementation found for int org.libtorrent4j.swig.libtorrent_jni.torrent_status_checking_resume_data_get() (tried Java_org_libtorrent4j_swig_libtorrent_1jni_torrent_1status_1checking_1resume_1data_1get and Java_org_libtorrent4j_swig_libtorrent_1jni_torrent_1status_1checking_1resume_1data_1get__)
        at int org.libtorrent4j.swig.libtorrent_jni.torrent_status_checking_resume_data_get() (libtorrent_jni.java:-2)
        at void org.libtorrent4j.swig.torrent_status$state_t.<clinit>() (torrent_status.java:594)
        at void org.libtorrent4j.TorrentStatus$State.<clinit>() (TorrentStatus.java:711)
        at org.libtorrent4j.TorrentStatus$State[] org.libtorrent4j.TorrentStatus$State.values() (TorrentStatus.java:705)
        at void org.proninyaroslav.libretorrent.core.model.session.TorrentDownloadImpl$1.<clinit>() (TorrentDownloadImpl.java:1346)
        at void org.proninyaroslav.libretorrent.core.model.session.TorrentDownloadImpl$InnerListener.alert(org.libtorrent4j.alerts.Alert) (TorrentDownloadImpl.java:210)
        at void org.libtorrent4j.SessionManager.fireAlert(org.libtorrent4j.alerts.Alert, int) (SessionManager.java:1042)
        at void org.libtorrent4j.SessionManager.access$1200(org.libtorrent4j.SessionManager, org.libtorrent4j.alerts.Alert, int) (SessionManager.java:62)
        at void org.libtorrent4j.SessionManager$5.run() (SessionManager.java:1201)
        at void java.lang.Thread.run() (Thread.java:923)

Migrate to libtorrent4j

Hi. Do I understand correctly that jlibtorrent is dead and I should switch to libtorrent4j? As far as I understand the code base remains the same and it will not cause problems?

Bug: Impossible to create a torrent

@aldenml libtorrent version (or branch): 2.0

platform/architecture: Android

I have a problem.
These lines give an error
byte[] result = builder.generate().entry().bencode();
TorrentInfo torrentInfo = new TorrentInfo(result);

error:
java.lang.IllegalArgumentException: Can't decode data: the v1 and v2 file metadata does not match
at org.libtorrent4j.TorrentInfo.bdecode0(TorrentInfo.java:674)
at org.libtorrent4j.TorrentInfo.(TorrentInfo.java:46)

So what to do? I need to get torrentInfo from byte[]

Create Torrent (Bittorrent V2 - Hybrid) with pre calculated piece hashes

Hey Alden,

I have a scenario where I have pre calculated piece hashes for a particular file (using SHA-256).
Now I want to be able to create a torrent file using the existing piece hashes.
I saw the tests and only see examples to create torrents using either file, directory or the TorrentBuilder. But I'm not sure any of these methods would allow me to pass/set my own piece hashes.
Could you please advice if there is a workaround for my use case?

Thanks in advance!

libtorrent doesn't call remove() in POSIX wrapper

Hi. I tried to implement a POSIX wrapper, as done in frostwire. The only difference is that I use a fake path to access Storage Access Framework (which I decode in the wrapper).
In general, this works fine, except that it's not possible to delete a file on the SD card that is accessible via the fake path. If the path is real (for example, /storage/emulated/0) then the files are deleted.
I checked and it turned out that the remove(String path) method isn't called by libtorrent in the POSIX wrapper. I assume libtorrent is trying to delete the file bypassing the POSIX wrapper, but since I use the fake path for SAF, it fails. Perhaps this is a bug?

[TorrentBuilder] Incorrect work with Storage Access Framework

Hi. As I said earlier, I use POSIX wrapper to work with SAF. There is one bug, if I put SAF's path to TorrentBuilder (for example com.android.externalstorage.documents/tree/0FED-1B0/):

java.io.IOException: content total size can't be 0
        at org.libtorrent4j.TorrentBuilder.generate(TorrentBuilder.java:488)

although the dir isn't empty. Before this exception, the only call of stat("com.android.externalstorage.documents/tree/0FED-1B0/") method happens and no more calls before and after this:

@Override
public int stat(String path, posix_stat_t buf)
{
    if (isFileSystemPath(path))
        return super.stat(path, buf);

    SafFileSystem.FakePath fakePath = ...;

    SafFileSystem.Stat stat = fs.stat(fakePath);
    if (stat == null) {
        ...
    }

    int S_ISDIR = stat.isDir ? 0040000 : 0;
    int S_IFREG = 0100000;

    buf.setMode(S_ISDIR | S_IFREG);
    buf.setSize(stat.length);
    int t = (int)(stat.lastModified / 1000);
    buf.setAtime(t);
    buf.setMtime(t);
    buf.setCtime(t);

    return 0;
}

Also fs.stat() returns length = 512 and isDir = true for SAF dir com.android.externalstorage.documents/tree/0FED-1B0/. I made it similar to the code example from Frostwire: AndroidPlatform.java#L137. For the non-SAF path, I call super.stat() and it works fine. It seems to me that the problem is in the override method code.

crash on ubuntu,version 1.2.2.0

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5ad5a2c185, pid=18419, tid=0x00007f5abb7fe700
#
# JRE version: OpenJDK Runtime Environment (8.0_222-b10) (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
# Java VM: OpenJDK 64-Bit Server VM (25.222-b10 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libtorrent4j-1.2.2.0.so+0x425185]  aesni_ecb_encrypt+0x1a5
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /opt/seed/hs_err_pid18419.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

Some questions about 1.3.0-alpha-3

  1. There are no following methods and fields and I also didn't find a replacement for them:

    • add_torrent_params::set_disabled_storage
    • AnnounceEndpoint::{fails, isWorking, updating, message}
    • libtorrent::generate_fingerprint
    • libtorrent::read_session_params
    • peer_info::getPieces
    • SessionManager::saveState (and in SessionHandle)
    • SettingsPack::{broadcastLSD, cacheSize}
    • settings_pack::bool_types::upnp_ignore_nonrouters
    • TorrentBuilder::OPTIMIZE_ALIGNMENT
  2. Should I use InfoHash::getBest instead of InfoHash::getV1? As far as I understand, now a torrent may not contain SHA-1?

  3. I also get error when building gradle:

error: cannot access AnnounceEndpoint
import org.libtorrent4j.AnnounceEndpoint;
                       ^
  bad class file: /home/yaroslav/data/.gradle/caches/transforms-2/files-2.1/b37e8e65b5152dcc31630689db47a240/jetified-libtorrent4j-1.3.0-alpha-3.jar(org/libtorrent4j/AnnounceEndpoint.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

Android projects use Java 8. Using Java 11 is very problematic:

> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> javax/xml/bind/JAXBException

libtorrent4j is still maintained?

I had a torrent which was not working with the latest version of libtorrent4j.
With the latest version of frostwire-jlibtorrent the torrent was working fine.
Will there be new versions of libtorrent4j?
I can send details about the not working torrent via email.

Bug: Can't create large torrents

@aldenml When I create a torrent larger than 2Gb I always get an error:

2021-03-03 13:47:00.030 27601-30156 E/AndroidRuntime: FATAL EXCEPTION: Thread-18
    Process: com.media.library, PID: 27601
    java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 595096 bytes
        at org.libtorrent4j.swig.libtorrent_jni.set_piece_hashes_ex(Native Method)
        at org.libtorrent4j.swig.libtorrent.set_piece_hashes_ex(libtorrent.java:429)
        at org.libtorrent4j.TorrentBuilder.generate(TorrentBuilder.java:469)
        at com.media.library.fragments.PlayerFragment$16.lambda$createTorrent$0$PlayerFragment$16(PlayerFragment.java:5282)
        at com.media.library.fragments.-$$Lambda$PlayerFragment$16$Bx-DssT8DXdkHlD1wM3dKsXC5Sc.run(Unknown Source:4)
        at java.lang.Thread.run(Thread.java:764)

Disk writes after download complete?

Hey @aldenml,

I have the following scenario for my application:

  1. Download a torrent using libtorrent4j and keep the SessionManager active (keep seeding).
  2. Read the downloaded file from disk and create a stream from it.

This works fine for smaller files like 10 MB or 100 MB.

However, for larger files, I see intermittent exceptions while reading the stream.

I do not observe this when I stop the session (no seeding) before reading the file to stream.

I feel this might be because the stream and session manager are both accessing the file together?

Question: Does the session manager still write to the file after download has finished? Currently I use the TORRENT_FINISHED alert to determine when to return control back to the code to create the stream.

As a work around, I'm stopping the session once the download completes and then restart it after the stream has been created. But I'm sure there could be a better way to handle this.

Appreciate your help!

[TorrentBuilder] crash when creating a large torrent with POSIX wrapper

Hello. Crash happens if I create a torrent with a fairly large number of files (as an example, I created a torrent of the /storage/emulated/0 dir of my device, which contains more than 100 files). Without POSIX wrapper, a torrent is successfully created, but the following exception occurs with enabled POSIX wrapper. Important note: I use the default POSIX wrapper, that is, I call only super methods in my child class, for example super.stat().

java.io.IOException: Try again
        at org.libtorrent4j.TorrentBuilder.generate(TorrentBuilder.java:507)

If I create a torrent with fewer files (for example 1 or 10) then everything happens fine.

[Android] Operation not supported on transport endpoint, code 95

I started migrating to a newer libtorrent4j version with Android 11 support and I'm getting the following error. Tested on API 25 - 31:

I: Peer fingerprint: -Lr3200-
I: User agent: LibreTorrent 3.2
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
E: Session error: Operation not supported on transport endpoint, code 95
I: [SESSION_LOG] update listen interfaces: 0.0.0.0:46849,[::]:46849
I: [SESSION_LOG] parsed listen interfaces count: 2, ifaces: 0.0.0.0:46849,[::]:46849
I: [SESSION_LOG] about to stop DHT, running: false
I: [SESSION_LOG] starting DHT, running: false, router lookups: 0
I: [SESSION_LOG] external address updated for 0.0.0.0:46849 [ new-ip: 37.235.201.30 type: 2 last-voter: 185.157.221.247 ]

It doesn't seem to affect downloads, i can still download torrents.

Full log: LibreTorrent - Debug_log_11-21-2021_18-57-17.txt

[Android] UnsatisfiedLinkError: dlopen failed: cannot locate symbol fseeko64

I think this error is related to this issue #125

Library version: 2.0.2-11
Android version: 6.0.1
Device: Samsung Galaxy On7
Arch: armeabi-v7a

Full bug report: ACRA-report.txt
Stack trace:

java.lang.LinkageError: Look for your architecture binary instructions at: https:\/\/github.com\/aldenml\/libtorrent4j
	at org.libtorrent4j.swig.libtorrent_jni.<clinit>(libtorrent_jni.java:28)
	at org.libtorrent4j.swig.libtorrent_jni.alert_error_notification_get(Native Method)
	at org.libtorrent4j.swig.alert.<clinit>(alert.java:494)
	at org.libtorrent4j.alerts.AlertType.<clinit>(AlertType.java:11)
	at org.libtorrent4j.SessionManager.<clinit>(SessionManager.java:67)
	at org.proninyaroslav.libretorrent.core.model.TorrentEngine.<init>(TorrentEngine.java:138)
	at org.proninyaroslav.libretorrent.core.model.TorrentEngine.getInstance(TorrentEngine.java:122)
	at org.proninyaroslav.libretorrent.core.model.TorrentInfoProvider.getInstance(TorrentInfoProvider.java:81)
	at org.proninyaroslav.libretorrent.ui.main.MainActivity.onCreate(MainActivity.java:145)
	at android.app.Activity.performCreate(Activity.java:6904)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
	at android.app.ActivityThread.access$1100(ActivityThread.java:229)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:148)
	at android.app.ActivityThread.main(ActivityThread.java:7331)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "fseeko64" referenced by "\/data\/app\/org.proninyaroslav.libretorrent-1\/lib\/arm\/libtorrent4j.so"...
	at java.lang.Runtime.loadLibrary(Runtime.java:372)
	at java.lang.System.loadLibrary(System.java:1076)
	at org.libtorrent4j.swig.libtorrent_jni.<clinit>(libtorrent_jni.java:23)
	... 20 more

Restrict announce on multiple interfaces

Hi Alden,

Is there a way to restrict the libtorrent4j client to not announce on multiple addresses?
Basically I'm seeing multiple simultaneous announces on the tracker and want to restrict the client to not do so.
Maybe there is a settings_pack value that I can set?

Appreciate your help!

java.lang.UnsatisfiedLinkError: libtorrent4j.jar: %1 is not a valid Win32 application.

When I try to run the demo on Window10, it has this error:
java.lang.UnsatisfiedLinkError: libtorrent4j.jar: %1 is not a valid Win32 application.

And when I run the demo on Linux, it has this error:
OpenJDK 64-Bit Server VM warning: You have loaded library /home/hicloud/libtorrent4j-2.0.4-22-RC1.jar which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c ', or link it with '-z noexecstack'.
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/hicloud/libtorrent4j-2.0.4-22-RC1.jar: /home/hicloud/libtorrent4j-2.0.4-22-RC1.jar: invalid ELF header (Possible cause: endianness mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817)
at java.lang.Runtime.load0(Runtime.java:810)
at java.lang.System.load(System.java:1088)
at com.company.Main.main(Main.java:57)

Where is wrong?

TorrentFlags.NEED_SAVE_RESUME doesn't work properly

Hi. Perhaps this flag works in a different way, but after adding the torrent, it doesn't trigger the SAVE_RESUME_DATA alert (I use latest libtorrentj version). I made an example to check it:

File torrentFile = new File("path_to_torrent");

SessionManager s = new SessionManager();
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");
                break;
            case SAVE_RESUME_DATA:
                System.out.println("Do save resume");
                break;
        }
    }
});

s.start();

TorrentInfo ti = new TorrentInfo(torrentFile);

add_torrent_params p = add_torrent_params.create_instance();
p.set_ti(ti.swig());
p.setSave_path(torrentFile.getParent());

torrent_flags_t f = p.getFlags();
f = f.or_(TorrentFlags.NEED_SAVE_RESUME);
f = f.and_(TorrentFlags.PAUSED.inv());
p.setFlags(f);

s.swig().async_add_torrent(p);

System.in.read();

terminating with uncaught exception of type boost::system::system_error: invalid torrent handle used

F/libc (26599): /buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type boost::system::system_error: invalid torrent handle used" failed
F/libc (26599): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 26653 (SessionManager-), pid 26599 (opts.smart.swan)


Build fingerprint: 'Android/sdk_phone_x86/generic_x86:10/QPP6.190730.005.B1/5775370:userdebug/test-keys'
Revision: '0'
ABI: 'x86'
Timestamp: 2020-12-01 09:22:07+0000
pid: 26599, tid: 26653, name: SessionManager- >>> com.smart.swan <<<
uid: 10114
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: '/buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type boost::system::system_error: invalid torrent handle used" failed'
eax 00000000 ebx 000067e7 ecx 0000681d edx 00000006
edi f368533e esi c2e03950
ebp f47ecad0 esp c2e038f8 eip f47ecad9
backtrace:
#00 pc 00000ad9 [vdso] (__kernel_vsyscall+9)
#1 pc 00092328 /apex/com.android.runtime/lib/bionic/libc.so (syscall+40) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
#2 pc 000ad651 /apex/com.android.runtime/lib/bionic/libc.so (abort+193) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
#3 pc 000adb88 /apex/com.android.runtime/lib/bionic/libc.so (__assert2+56) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
#4 pc 008fffa4 /data/app/com.smart.swan-cxgLKcs2HSi3Rl03G8oruw==/lib/x86/libtorrent4j.so

and pause
public void pauseManually(TorrentHandle th) {
th.pause();
}
but alert listener not listen anything like this
case STATE_CHANGED:
StateChangedAlert stateChangedAlert = ((StateChangedAlert) alert);
TorrentStatus.State prevState = stateChangedAlert.getPrevState();
TorrentStatus.State state = stateChangedAlert.getState();
sendState(id, state);
break;

how to download some piece first ?

hello ,
I want to download some fragments first, for example, I want to download 2-20 blocks first. How can I set up and deal with the download of these fragments first. Thank you.

i try to use
ht = torrent_handle
th.piecePriority(1, TOP_PRIORITY);
th.setPieceDeadline(1, 1000);
but ,I don’t quite understand the meaning of these functions, what do these mean, if you can give me an example, thank you

[Android][POSIX wrapper] Native crash if open() function returns -1

Hello. This happens if you remove a torrent while downloading. At this point, a POSIX call to open() occurs, which returns -1 because the required file doesn't exist.
As I understand it, the reason for the crash is to return -1 from open() function. I simulated it artificially:

@Override
public int open(String path, int flags, int mode) {
    return -1;
}

and it also led to the crash

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 7306 (Thread-45), pid 7191 (retorrent.debug)

Tested on Android 9 and 10.

[Android][POSIX wrapper] Add `renameat` syscall to support file moving

Hi. One of my application users informed me that he was unable to move the torrent to external storage. I decided to make strace and as it turned out, libtorrent uses the renameat system call to move files:

renameat(AT_FDCWD, 
"/storage/emulated/0/CCleaner v5.63.7540 RePack+Portable by Dodakaedr/Silent unpack Business.cmd", AT_FDCWD, 
"/saf_root(com.android.externalstorage.documents/tree/home%3A);/CCleaner v5.63.7540 RePack+Portable by Dodakaedr/Silent unpack Business.cmd") 
= -1 ENOENT (No such file or directory)

This call is not in posix_wrapper. I tested this on libtorrent4j 1.2.3.0 and 1.3.0-alpha-5.

GLIBC_2.29' not found

I tried the latest version libtorrent4j-2.0.1-7. It didn't start :(
I got this error message on my Ubuntu 18.04 system:

/lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found

Older systems are no longer supported?

help !!! how to setup a special client name?

please help me !!! how to setup a special client name ?
i found :
add_torrent_params p = new add_torrent_params();
p.setUserdata(new client_data_t());

but how to set a special name like 'xxx client'

thx a lot.

crash when call SessionManager.start() on Samsung devices

I got the log。What's the cause of this problem? or is it possible you give me the so file without symbols striped so I can debug it myself?

pid: 6747, tid: 6747 >>> com.xxoo.intl:DownloadService <<<
signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr c38d98e8
r0 0000003f r1 ffbf8dd4 r2 00000000 r3 c3b63000
r4 c3f2b4c0 r5 c3f2b4c0 r6 c56bcb34 r7 00000000
r8 e5195c2c r9 c3f7f300 10 e5195c34 fp ffbf8db0
ip c3acf0f4 sp ffbf8d90 lr c3928770 pc c38d98e8 cpsr 200f0010
d0 0000000000000000 d1 0000000000000000
d2 0000008000000080 d3 0000008000000080
d4 0c0f0e0d0c0f0e0d d5 0c0f0e0d0c0f0e0d
d6 1190d8f7b17491a8 d7 62174e39c8cb868d
d8 0000000000000000 d9 0000000000000000
d10 0000000000000000 d11 0000000000000000
d12 0000000000000000 d13 0000000000000000
d14 0000000000000000 d15 0000000000000000
d16 0000000000000000 d17 0000000000000000
d18 0000000000000000 d19 5cc91b6900000000
d20 edbd8ac1edbd8ac1 d21 edbd8ac1edbd8ac1
d22 0000090900000018 d23 0000008000000080
d24 0000000000ffffeb d25 0000000001000000
d26 0000000000000000 d27 0000000000000001
d28 0000000000000000 d29 0000000001000000
d30 412176649172527a d31 9f9e9d9c9b9a9998
scr 60000011

#00 pc 0038a8e8 /data/app/com.xxoo.intl-wL4hMkbYp6Z3ba4GlKMPUw==/lib/arm/libtorrent4j-1.2.0.22.so
#1 pc 003d9770 /data/app/com.xxoo.intl-wL4hMkbYp6Z3ba4GlKMPUw==/lib/arm/libtorrent4j-1.2.0.22.so

all threads dump:
[DEBUG] enter dumpAllThreadsIntoFileFunc, fd: 118, overridedMalloc: 0
[DEBUG] dumpArtThreadsInternal: 118
[DEBUG] found JavaVMExt: 0xe52698c0, index: 90, string: 4
[DEBUG] aborting: 0xe50bb320, 0
[DEBUG] Dump: 0x0, DumpState: 0xe4fb406d, DumpJavaStack: 0xe4fb7689
[DEBUG] currentThread: 0xe51f9000, pid: 6925
[DEBUG] ThreadList: 0xe521e000
[DEBUG] ForEach: 0xe4fc9ddd
[DEBUG] cerr: 0xd68abda0
[DEBUG] ForEach begin
[DEBUG] thread 0xe51f9000 dumping ...
"main" prio=5 tid=1 Native
| group="" sCount=0 dsCount=0 flags=0 obj=0x74fe1160 self=0xe51f9000
| sysTid=6747 nice=0 cgrp=default sched=0/0 handle=0xe986c4a8
| state=? schedstat=( 0 0 0 ) utm=0 stm=0 core=0 HZ=100
| stack=0xff3fe000-0xff400000 stackSize=8MB
| held mutexes=
at org.libtorrent4j.swig.libtorrent_jni.new_session__SWIG_0(libtorrent_jni.java)
at org.libtorrent4j.swig.session.(session.java:39)
at org.libtorrent4j.SessionManager.start(SessionManager.java:97)
........

Downgrade minimum supported Android API version

Hi. Is it technically possible to lower the minimum API to at least 19 or 22 or 23? Yes, their number is decreasing, but they still make up a significant percentage of devices, especially 22, not to mention 23.

Restrict peer communication to subnet

Hey Alden,

Is there a way to restrict peer communication to a particular subnet.
For my use case, I want the client (peer) to block any communication with another peer not within a subnet.
I found "listen_interfaces" and "outgoing_interfaces" looking at the libtorrent documentation.
Is there a way for me to initialize the SessionManager specifically for a subnet?

Bug

Fatal Exception: java.lang.LinkageError: Look for your architecture binary instructions at: https://github.com/aldenml/libtorrent4j
at org.libtorrent4j.swig.libtorrent_jni.(libtorrent_jni.java:71)
at org.libtorrent4j.swig.libtorrent_jni.alert_error_notification_get(libtorrent_jni.java)
at org.libtorrent4j.swig.alert.(alert.java:2)
at org.libtorrent4j.alerts.AlertType.(AlertType.java:2)
at org.libtorrent4j.SessionManager.(SessionManager.java)
at com.pitorrent.client.torrent.core.model.TorrentEngine.(TorrentEngine.java:76)
at com.pitorrent.client.torrent.core.model.TorrentEngine.getInstance(TorrentEngine.java:13)
at com.pitorrent.client.torrent.core.model.TorrentInfoProvider.getInstance(TorrentInfoProvider.java:13)
at com.pitorrent.client.torrent.ui.main.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

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

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.