Skip to content

Commit

Permalink
Added swig entry constructor for string bytes
Browse files Browse the repository at this point in the history
Refactored swig api for address sha1 hash
  • Loading branch information
aldenml committed Feb 12, 2016
1 parent c487e9a commit 46fc1db
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 228 deletions.
Expand Up @@ -4,10 +4,7 @@
import com.frostwire.jlibtorrent.DhtSettings;
import com.frostwire.jlibtorrent.Sha1Hash;
import com.frostwire.jlibtorrent.TcpEndpoint;
import com.frostwire.jlibtorrent.swig.bloom_filter_256;
import com.frostwire.jlibtorrent.swig.entry;
import com.frostwire.jlibtorrent.swig.entry_list;
import com.frostwire.jlibtorrent.swig.sha1_hash;
import com.frostwire.jlibtorrent.swig.*;

import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -53,7 +50,7 @@ public boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry

for (PeerEntry peer : v.peers) {
sha1_hash iphash = new sha1_hash();
peer.addr.address().swig().hash(iphash);
libtorrent.sha1_hash_address(peer.addr.address().swig(), iphash);
if (peer.seed) {
seeds.set(iphash);
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/frostwire/jlibtorrent/swig/address.java
Expand Up @@ -99,10 +99,6 @@ public boolean op_lt(address a2) {
return libtorrent_jni.address_op_lt(swigCPtr, this, address.getCPtr(a2), a2);
}

public void hash(sha1_hash h) {
libtorrent_jni.address_hash(swigCPtr, this, sha1_hash.getCPtr(h), h);
}

public static int compare(address a1, address a2) {
return libtorrent_jni.address_compare(address.getCPtr(a1), a1, address.getCPtr(a2), a2);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/frostwire/jlibtorrent/swig/entry.java
Expand Up @@ -112,6 +112,10 @@ public short getM_type_queried() {
return libtorrent_jni.entry_m_type_queried_get(swigCPtr, this);
}

public entry(byte_vector string_bytes) {
this(libtorrent_jni.new_entry__SWIG_7(byte_vector.getCPtr(string_bytes), string_bytes), true);
}

public entry get(String key) {
return new entry(libtorrent_jni.entry_get(swigCPtr, this, key), false);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/frostwire/jlibtorrent/swig/libtorrent.java
Expand Up @@ -237,6 +237,14 @@ public static void default_storage_disk_write_access_log(boolean enable) {
libtorrent_jni.default_storage_disk_write_access_log__SWIG_1(enable);
}

public static void sha1_hash_address(address ip, sha1_hash h) {
libtorrent_jni.sha1_hash_address(address.getCPtr(ip), ip, sha1_hash.getCPtr(h), h);
}

public static int write_tcp_endpoint(tcp_endpoint endp, byte_vector out) {
return libtorrent_jni.write_tcp_endpoint(tcp_endpoint.getCPtr(endp), endp, byte_vector.getCPtr(out), out);
}

public static boolean add_files_cb(String p, add_files_listener listener) {
return libtorrent_jni.add_files_cb(p, add_files_listener.getCPtr(listener), listener);
}
Expand Down
Expand Up @@ -595,6 +595,7 @@ public class libtorrent_jni {
public final static native String entry_to_string(long jarg1, entry jarg1_);
public final static native void entry_m_type_queried_set(long jarg1, entry jarg1_, short jarg2);
public final static native short entry_m_type_queried_get(long jarg1, entry jarg1_);
public final static native long new_entry__SWIG_7(long jarg1, byte_vector jarg1_);
public final static native long entry_get(long jarg1, entry jarg1_, String jarg2);
public final static native void entry_set__SWIG_0(long jarg1, entry jarg1_, String jarg2, String jarg3);
public final static native void entry_set__SWIG_1(long jarg1, entry jarg1_, String jarg2, long jarg3, byte_vector jarg3_);
Expand Down Expand Up @@ -2877,7 +2878,6 @@ public class libtorrent_jni {
public final static native boolean address_is_unspecified(long jarg1, address jarg1_);
public final static native boolean address_is_multicast(long jarg1, address jarg1_);
public final static native boolean address_op_lt(long jarg1, address jarg1_, long jarg2, address jarg2_);
public final static native void address_hash(long jarg1, address jarg1_, long jarg2, sha1_hash jarg2_);
public final static native int address_compare(long jarg1, address jarg1_, long jarg2, address jarg2_);
public final static native void delete_address(long jarg1);
public final static native long new_address_v4__SWIG_0();
Expand Down Expand Up @@ -2979,6 +2979,8 @@ public class libtorrent_jni {
public final static native void dht_sign_mutable_item(long jarg1, byte_vector jarg1_, String jarg2, int jarg3, long jarg4, byte_vector jarg4_, long jarg5, byte_vector jarg5_, long jarg6, byte_vector jarg6_);
public final static native boolean default_storage_disk_write_access_log__SWIG_0();
public final static native void default_storage_disk_write_access_log__SWIG_1(boolean jarg1);
public final static native void sha1_hash_address(long jarg1, address jarg1_, long jarg2, sha1_hash jarg2_);
public final static native int write_tcp_endpoint(long jarg1, tcp_endpoint jarg1_, long jarg2, byte_vector jarg2_);
public final static native void delete_add_files_listener(long jarg1);
public final static native boolean add_files_listener_pred(long jarg1, add_files_listener jarg1_, String jarg2);
public final static native boolean add_files_listener_predSwigExplicitadd_files_listener(long jarg1, add_files_listener jarg1_, String jarg2);
Expand Down
22 changes: 22 additions & 0 deletions swig/libtorrent.h
Expand Up @@ -15,6 +15,8 @@

#include <libtorrent/buffer.hpp>
#include <libtorrent/utp_stream.hpp>
#include <libtorrent/socket_io.hpp>

#include <libtorrent/kademlia/dht_tracker.hpp>
#include <libtorrent/kademlia/node_entry.hpp>
#include <libtorrent/kademlia/node.hpp>
Expand Down Expand Up @@ -161,6 +163,26 @@ void default_storage_disk_write_access_log(bool enable) {
return default_storage::disk_write_access_log(enable);
}

void sha1_hash_address(boost::asio::ip::address const& ip, libtorrent::sha1_hash& h)
{
if (ip.is_v6())
{
address_v6::bytes_type b = ip.to_v6().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
}
else
{
address_v4::bytes_type b = ip.to_v4().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
}
}

int write_tcp_endpoint(tcp::endpoint const& endp, std::vector<int8_t>& out) {
std::vector<int8_t>::iterator it = out.begin();
libtorrent::detail::write_endpoint(endp, it);
return it - out.begin();
}

class add_files_listener {
public:
virtual ~add_files_listener() {
Expand Down
14 changes: 4 additions & 10 deletions swig/libtorrent.i
Expand Up @@ -633,16 +633,6 @@ namespace boost {
return *$self < a2;
}

void hash(libtorrent::sha1_hash& h) {
if ($self->is_v6()) {
address_v6::bytes_type b = $self->to_v6().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
} else {
address_v4::bytes_type b = $self->to_v4().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
}
}

static int compare(const address& a1, const address& a2) {
return a1 == a2 ? 0 : (a1 < a2 ? -1 : 1);
}
Expand Down Expand Up @@ -894,6 +884,10 @@ namespace libtorrent {
};

%extend entry {
entry(std::vector<int8_t> const& string_bytes) {
return new entry(std::string(string_bytes.begin(), string_bytes.end()));
}

entry& get(std::string const& key) {
return $self->operator[](key);
}
Expand Down
131 changes: 95 additions & 36 deletions swig/libtorrent_jni.cpp
Expand Up @@ -1226,6 +1226,9 @@ SWIGINTERN void std_vector_Sl_std_pair_Sl_std_string_Sc_dht_extension_handler_li
else
throw std::out_of_range("vector index out of range");
}
SWIGINTERN libtorrent::entry *new_libtorrent_entry__SWIG_7(std::vector< int8_t > const &string_bytes){
return new entry(std::string(string_bytes.begin(), string_bytes.end()));
}
SWIGINTERN libtorrent::entry &libtorrent_entry_get(libtorrent::entry *self,std::string const &key){
return self->operator[](key);
}
Expand Down Expand Up @@ -1472,15 +1475,6 @@ SWIGINTERN libtorrent::hasher &libtorrent_hasher_update(libtorrent::hasher *self
SWIGINTERN bool boost_asio_ip_address_op_lt(boost::asio::ip::address *self,boost::asio::ip::address const &a2){
return *self < a2;
}
SWIGINTERN void boost_asio_ip_address_hash(boost::asio::ip::address *self,libtorrent::sha1_hash &h){
if (self->is_v6()) {
address_v6::bytes_type b = self->to_v6().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
} else {
address_v4::bytes_type b = self->to_v4().to_bytes();
h = hasher(reinterpret_cast<char*>(&b[0]), b.size()).final();
}
}
SWIGINTERN int boost_asio_ip_address_compare(boost::asio::ip::address const &a1,boost::asio::ip::address const &a2){
return a1 == a2 ? 0 : (a1 < a2 ? -1 : 1);
}
Expand Down Expand Up @@ -17362,6 +17356,33 @@ SWIGEXPORT jshort JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_en
}


SWIGEXPORT jlong JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_new_1entry_1_1SWIG_17(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
std::vector< int8_t > *arg1 = 0 ;
libtorrent::entry *result = 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(std::vector< int8_t > **)&jarg1;
if (!arg1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "std::vector< int8_t > const & reference is null");
return 0;
}
{
try {
result = (libtorrent::entry *)new_libtorrent_entry__SWIG_7((std::vector< signed char > const &)*arg1);
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
}
}
*(libtorrent::entry **)&jresult = result;
return jresult;
}


SWIGEXPORT jlong JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
jlong jresult = 0 ;
libtorrent::entry *arg1 = (libtorrent::entry *) 0 ;
Expand Down Expand Up @@ -59802,32 +59823,6 @@ SWIGEXPORT jboolean JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_
}


SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_address_1hash(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
boost::asio::ip::address *arg1 = (boost::asio::ip::address *) 0 ;
libtorrent::sha1_hash *arg2 = 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
arg1 = *(boost::asio::ip::address **)&jarg1;
arg2 = *(libtorrent::sha1_hash **)&jarg2;
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "libtorrent::sha1_hash & reference is null");
return ;
}
{
try {
boost_asio_ip_address_hash(arg1,*arg2);
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
}
}
}


SWIGEXPORT jint JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_address_1compare(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
jint jresult = 0 ;
boost::asio::ip::address *arg1 = 0 ;
Expand Down Expand Up @@ -61654,7 +61649,7 @@ SWIGEXPORT jstring JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_J

(void)jenv;
(void)jcls;
result = (char *)("8bc38bfd5c6b2db415447aa051ca875c8f6d4e13");
result = (char *)("c487e9a3e3d3dc5b324a6199b93e2efeb7a72060");
if (result) jresult = jenv->NewStringUTF((const char *)result);
return jresult;
}
Expand Down Expand Up @@ -62243,6 +62238,70 @@ SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_defa
}


SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_sha1_1hash_1address(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
boost::asio::ip::address *arg1 = 0 ;
libtorrent::sha1_hash *arg2 = 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
arg1 = *(boost::asio::ip::address **)&jarg1;
if (!arg1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "boost::asio::ip::address const & reference is null");
return ;
}
arg2 = *(libtorrent::sha1_hash **)&jarg2;
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "libtorrent::sha1_hash & reference is null");
return ;
}
{
try {
sha1_hash_address((boost::asio::ip::address const &)*arg1,*arg2);
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
}
}
}


SWIGEXPORT jint JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_write_1tcp_1endpoint(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
jint jresult = 0 ;
tcp::endpoint *arg1 = 0 ;
std::vector< int8_t > *arg2 = 0 ;
int result;

(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
arg1 = *(tcp::endpoint **)&jarg1;
if (!arg1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "tcp::endpoint const & reference is null");
return 0;
}
arg2 = *(std::vector< int8_t > **)&jarg2;
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "std::vector< int8_t > & reference is null");
return 0;
}
{
try {
result = (int)write_tcp_endpoint((tcp::endpoint const &)*arg1,*arg2);
} catch (std::exception& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what());
} catch (...) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type");
}
}
jresult = (jint)result;
return jresult;
}


SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_delete_1add_1files_1listener(JNIEnv *jenv, jclass jcls, jlong jarg1) {
add_files_listener *arg1 = (add_files_listener *) 0 ;

Expand Down

0 comments on commit 46fc1db

Please sign in to comment.