Skip to content

Commit

Permalink
update to libtorrent master HEAD, version 2.0.1-9 (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml authored Dec 30, 2020
1 parent 0467913 commit 48a98dc
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
sudo apt install libssl-dev
sudo apt install ninja-build
- name: cmake
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build -G "Ninja" swig
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_STANDARD=17 -B build -G "Ninja" swig
- name: build
run: cmake --build build --config Release --parallel 2
- name: strip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
brew reinstall boost
HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@1.1
- name: cmake
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build -G "CodeBlocks - Unix Makefiles" swig
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_STANDARD=17 -B build -G "CodeBlocks - Unix Makefiles" swig
env:
OPENSSL_ROOT_DIR: /usr/local/opt/openssl
- name: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: cmake
run: |
$env:BOOST_ROOT=$env:BOOST_ROOT_1_72_0
cmake -DCMAKE_BUILD_TYPE=Release -B build -G "Visual Studio 16 2019" -A x64 swig
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -B build -G "Visual Studio 16 2019" -A x64 swig
- name: build
run: cmake --build build --config Release --parallel 2
- name: dependencies
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = "org.libtorrent4j"
version = "2.0.1-8"
version = "2.0.1-9"

java {
// using java 8 for android compatibility
Expand Down
22 changes: 22 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
2.0.1-9

* using libtorrent master
* lt:fix loading of DHT node ID from previous session on startup
* lt:use getrandom(), when available, and fall back to /dev/urandom
* lt:allow not setting a creation date in create_torrent (but default to
current timestamp). Provide more prominent shortcuts to ask a torrent_info
about whether it has v1 and v2 metadata
* lt:pull out cached_block_entry::blocks_in_piece from bitfield, since it's
immutable and may be read from multiple threads without holding any mutex.
Other fields in the bitfields may be updated under a mutex, which would
race with blocks_in_fields otherwise
* lt:fix data race in storage::m_settings
* lt:remove invalid asserts, which introduce a data race
* lt:remove use of global variable in ut_pex (and a data race along with it)
* lt:fix data race in block cache
* lt:fix time_now_string to not use a global variable for the returned string
* lt:magnet link parameters names are case insensitive
* lt:mitigate a class of tracker SSRF where tracker URLs come preloaded with
bittorrent tracker query string arguments, like info_hash, event, etc
* lt:source code cleanup, performance and stability

2.0.1-8

* using libtorrent master
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/libtorrent4j/InfoHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,34 @@
public class InfoHash
extends SwigObject<info_hash_t> {

/**
* The default constructor creates an object that has neither a v1 or v2
* hash.
*/
public InfoHash() {
super(new info_hash_t());
}

public InfoHash(info_hash_t ih) {
super(ih);
}

/**
* Returns true if the corresponding info hash is present in this
* object.
*/
public boolean hasV1() {
return h.has_v1();
}

/**
* Returns true if the corresponding info hash is present in this
* object.
*/
public boolean hasV2() {
return h.has_v2();
}

public Sha1Hash getBest() {
return new Sha1Hash(h.get_best());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/libtorrent4j/LibTorrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static String version() {
* @return the git revision
*/
public static String revision() {
return "d5b27eeacb573d5b6c7b30357c8d27ef1231b7eb";
return "a597f5824b0a8c8fe5be43d9a78c0a35c7260f6e";
}

public static String boostVersion() {
Expand All @@ -61,7 +61,7 @@ public static String opensslVersion() {
* @return libtorrent4j version.
*/
public static String libtorrent4jVersion() {
return "2.0.1-8";
return "2.0.1-9";
}

/**
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/libtorrent4j/TorrentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class TorrentBuilder {

private String comment;
private String creator;
private Long creationDate;
private List<String> urlSeeds;
private List<Pair<String, Integer>> nodes;
private List<Pair<String, Integer>> trackers;
Expand Down Expand Up @@ -163,6 +164,31 @@ public TorrentBuilder creator(String value) {
return this;
}

/**
* The "creation time" field. Defaults to the system clock at the
* time of construction.
*
* The timestamp is specified in seconds, posix time. If the creation
* date is set to 0, the "creation date" field will be omitted from
* the generated torrent.
*/
public long creationDate() {
return creationDate;
}

/**
* Set the "creation time" field. Defaults to the system clock at the
* time of construction.
*
* The timestamp is specified in seconds, posix time. If the creation
* date is set to 0, the "creation date" field will be omitted from
* the generated torrent.
*/
public TorrentBuilder creationDate(long timestamp) {
this.creationDate = timestamp;
return this;
}

/**
*
*/
Expand Down Expand Up @@ -451,6 +477,9 @@ public void progress(int i) {
if (creator != null) {
t.set_creator(creator);
}
if (creationDate != null) {
t.set_creation_date(creationDate);
}
for (String s : urlSeeds) {
t.add_url_seed(s);
}
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/org/libtorrent4j/TorrentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,42 @@ public int numPieces() {
}

/**
* returns the info-hash of the torrent.
*
* Returns the info-hash of the torrent.
*
* For BitTorrent v2 support, use `infoHash()` to get an object that
* may hold both a v1 and v2 info-hash.
*/
public Sha1Hash infoHash() {
return new Sha1Hash(ti.info_hash());
}

/**
* Returns an object that may hold both a v1 and v2 info-hash.
*/
public InfoHash infoHashes() {
return new InfoHash(ti.info_hashes());
}

/**
* Returns whether this torrent has v1 metadata.
*
* Hybrid torrents have both. This is a shortcut for
* `infoHashes().hasV1()`.
*/
public boolean hasV1() {
return ti.v1();
}

/**
* Returns whether this torrent has v2 metadata.
*
* Hybrid torrents have both. This is a shortcut for
* `infoHashes().hasV2()`.
*/
public boolean hasV2() {
return ti.v2();
}

/**
* If you need index-access to files you can use this method
* to access files using indices.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/libtorrent4j/swig/create_torrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public void set_creator(String str) {
libtorrent_jni.create_torrent_set_creator(swigCPtr, this, str);
}

public void set_creation_date(long timestamp) {
libtorrent_jni.create_torrent_set_creation_date(swigCPtr, this, timestamp);
}

public void set_hash(int index, sha1_hash h) {
libtorrent_jni.create_torrent_set_hash(swigCPtr, this, index, sha1_hash.getCPtr(h), h);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/libtorrent4j/swig/libtorrent_jni.java
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,8 @@ public class libtorrent_jni {
public final static native int torrent_info_end_piece(long jarg1, torrent_info jarg1_);
public final static native long torrent_info_info_hash(long jarg1, torrent_info jarg1_);
public final static native long torrent_info_info_hashes(long jarg1, torrent_info jarg1_);
public final static native boolean torrent_info_v1(long jarg1, torrent_info jarg1_);
public final static native boolean torrent_info_v2(long jarg1, torrent_info jarg1_);
public final static native int torrent_info_num_files(long jarg1, torrent_info jarg1_);
public final static native long torrent_info_map_block(long jarg1, torrent_info jarg1_, int jarg2, long jarg3, int jarg4);
public final static native long torrent_info_map_file(long jarg1, torrent_info jarg1_, int jarg2, long jarg3, int jarg4);
Expand Down Expand Up @@ -3225,6 +3227,7 @@ public class libtorrent_jni {
public final static native long create_torrent_files(long jarg1, create_torrent jarg1_);
public final static native void create_torrent_set_comment(long jarg1, create_torrent jarg1_, String jarg2);
public final static native void create_torrent_set_creator(long jarg1, create_torrent jarg1_, String jarg2);
public final static native void create_torrent_set_creation_date(long jarg1, create_torrent jarg1_, long jarg2);
public final static native void create_torrent_set_hash(long jarg1, create_torrent jarg1_, int jarg2, long jarg3, sha1_hash jarg3_);
public final static native void create_torrent_add_node(long jarg1, create_torrent jarg1_, long jarg2, string_int_pair jarg2_);
public final static native void create_torrent_set_priv(long jarg1, create_torrent jarg1_, boolean jarg2);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/libtorrent4j/swig/torrent_info.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public info_hash_t info_hashes() {
return new info_hash_t(libtorrent_jni.torrent_info_info_hashes(swigCPtr, this), false);
}

public boolean v1() {
return libtorrent_jni.torrent_info_v1(swigCPtr, this);
}

public boolean v2() {
return libtorrent_jni.torrent_info_v2(swigCPtr, this);
}

public int num_files() {
return libtorrent_jni.torrent_info_num_files(swigCPtr, this);
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/libtorrent4j/CreateTorrentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void testUsingBuilder() throws IOException {
TorrentBuilder.Result r = b.path(dir)
.comment("comment")
.creator("creator")
.creationDate(1000)
.addUrlSeed("http://urlseed/")
.addNode(new Pair<>("1.1.1.1", 1))
.addTracker("udp://tracker/")
Expand All @@ -109,6 +110,7 @@ public void testUsingBuilder() throws IOException {
TorrentInfo ti = TorrentInfo.bdecode(r.entry().bencode());
assertEquals("comment", ti.comment());
assertEquals("creator", ti.creator());
assertEquals(1000, ti.creationDate());

ArrayList<WebSeedEntry> seeds = ti.webSeeds();
for (WebSeedEntry e : seeds) {
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/libtorrent4j/InfoHashTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.libtorrent4j;

import org.junit.Test;

import static org.junit.Assert.assertFalse;

/**
* @author aldenml
*/
public class InfoHashTest {

@Test
public void testDefaultConstructor() {
InfoHash ih = new InfoHash();

assertFalse(ih.hasV1());
assertFalse(ih.hasV2());
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/libtorrent4j/TorrentInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.nio.MappedByteBuffer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* @author aldenml
Expand All @@ -23,5 +25,8 @@ public void testNewFromBuffer() throws IOException {
TorrentInfo ti = new TorrentInfo((MappedByteBuffer) bb);
assertEquals("83e37aea34581ce105af93c0955e7c7d4194ae47", ti.infoHash().toHex());
assertEquals("FrostWire 6.2.4 build 179", ti.creator());

assertTrue(ti.hasV1());
assertFalse(ti.hasV2());
}
}
2 changes: 1 addition & 1 deletion swig/deps/libtorrent
Submodule libtorrent updated 84 files
+9 −9 .cirrus.yml
+5 −0 .github/workflows/docs.yml
+36 −33 .github/workflows/linux.yml
+0 −28 .github/workflows/macos.yml
+49 −0 .github/workflows/python.yml
+43 −5 CMakeLists.txt
+9 −0 ChangeLog
+1 −0 Jamfile
+1 −1 Makefile
+4 −0 README.rst
+0 −10 bindings/python/Jamfile
+252 −111 bindings/python/setup.py
+2 −2 bindings/python/src/alert.cpp
+1 −1 bindings/python/src/converters.cpp
+17 −5 bindings/python/src/session.cpp
+4 −0 examples/CMakeLists.txt
+1 −0 examples/Jamfile
+1 −2 fuzzers/tools/generate_initial_corpus.py
+2 −12 include/libtorrent/aux_/numeric_cast.hpp
+1 −1 include/libtorrent/aux_/peer_list.hpp
+8 −2 include/libtorrent/aux_/string_util.hpp
+1 −1 include/libtorrent/bencode.hpp
+3 −0 include/libtorrent/config.hpp
+6 −0 include/libtorrent/create_torrent.hpp
+2 −2 include/libtorrent/http_stream.hpp
+6 −6 include/libtorrent/i2p_stream.hpp
+6 −0 include/libtorrent/parse_url.hpp
+2 −2 include/libtorrent/socks5_stream.hpp
+12 −2 include/libtorrent/torrent_info.hpp
+3 −3 include/libtorrent/upnp.hpp
+14 −0 simulation/test_tracker.cpp
+2 −2 src/announce_entry.cpp
+1 −1 src/bt_peer_connection.cpp
+7 −1 src/create_torrent.cpp
+3 −3 src/entry.cpp
+2 −2 src/error_code.cpp
+2 −2 src/escape_string.cpp
+1 −1 src/file.cpp
+7 −4 src/file_storage.cpp
+3 −3 src/generate_peer_id.cpp
+1 −1 src/http_parser.cpp
+15 −3 src/http_tracker_connection.cpp
+0 −6 src/i2p_stream.cpp
+5 −5 src/identify_client.cpp
+3 −3 src/kademlia/dht_storage.cpp
+3 −1 src/kademlia/node.cpp
+13 −13 src/magnet_uri.cpp
+25 −3 src/parse_url.cpp
+6 −6 src/path.cpp
+6 −3 src/random.cpp
+3 −2 src/read_resume_data.cpp
+14 −9 src/string_util.cpp
+2 −4 src/torrent.cpp
+23 −11 src/torrent_info.cpp
+1 −1 src/torrent_peer.cpp
+1 −1 src/udp_socket.cpp
+1 −1 src/udp_tracker_connection.cpp
+0 −23 src/ut_pex.cpp
+5 −5 src/web_peer_connection.cpp
+2 −2 src/write_resume_data.cpp
+1 −1 src/xml_parse.cpp
+4 −0 test/CMakeLists.txt
+2 −0 test/Jamfile
+1 −1 test/dht_server.cpp
+2 −2 test/peer_server.cpp
+12 −12 test/setup_transfer.cpp
+1 −1 test/test_alert_manager.cpp
+102 −0 test/test_create_torrent.cpp
+1 −1 test/test_dht.cpp
+1 −1 test/test_fast_extension.cpp
+15 −0 test/test_file_storage.cpp
+21 −0 test/test_http_parser.cpp
+3 −3 test/test_listen_socket.cpp
+15 −0 test/test_magnet.cpp
+1 −1 test/test_privacy.cpp
+5 −5 test/test_ssl.cpp
+1 −1 test/test_storage.cpp
+17 −4 test/test_string.cpp
+6 −0 test/test_torrent_info.cpp
+3 −3 test/test_utils.cpp
+4 −2 test/test_utils.hpp
+14 −14 test/udp_tracker.cpp
+6 −6 tools/run_tests.sh
+1 −3 tools/set_version.py
73 changes: 73 additions & 0 deletions swig/libtorrent_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31909,6 +31909,56 @@ SWIGEXPORT jlong JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_torrent_1inf
}


SWIGEXPORT jboolean JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_torrent_1info_1v1(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jboolean jresult = 0 ;
libtorrent::torrent_info *arg1 = (libtorrent::torrent_info *) 0 ;
bool result;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(libtorrent::torrent_info **)&jarg1;
{
try {
result = (bool)((libtorrent::torrent_info const *)arg1)->v1();
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
return 0;
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
return 0;
}
}
jresult = (jboolean)result;
return jresult;
}


SWIGEXPORT jboolean JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_torrent_1info_1v2(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jboolean jresult = 0 ;
libtorrent::torrent_info *arg1 = (libtorrent::torrent_info *) 0 ;
bool result;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(libtorrent::torrent_info **)&jarg1;
{
try {
result = (bool)((libtorrent::torrent_info const *)arg1)->v2();
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
return 0;
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
return 0;
}
}
jresult = (jboolean)result;
return jresult;
}


SWIGEXPORT jint JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_torrent_1info_1num_1files(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jint jresult = 0 ;
libtorrent::torrent_info *arg1 = (libtorrent::torrent_info *) 0 ;
Expand Down Expand Up @@ -74837,6 +74887,29 @@ SWIGEXPORT void JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_create_1torre
}


SWIGEXPORT void JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_create_1torrent_1set_1creation_1date(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
libtorrent::create_torrent *arg1 = (libtorrent::create_torrent *) 0 ;
std::time_t arg2 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(libtorrent::create_torrent **)&jarg1;
arg2 = (std::time_t)jarg2;
{
try {
(arg1)->set_creation_date(arg2);
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
return ;
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
return ;
}
}
}


SWIGEXPORT void JNICALL Java_org_libtorrent4j_swig_libtorrent_1jni_create_1torrent_1set_1hash(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, int jarg2, jlong jarg3, jobject jarg3_) {
libtorrent::create_torrent *arg1 = (libtorrent::create_torrent *) 0 ;
piece_index_t arg2 ;
Expand Down

0 comments on commit 48a98dc

Please sign in to comment.