diff --git a/src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorageBase.java b/src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorageBase.java index ba46612e9..b76ff4c8a 100644 --- a/src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorageBase.java +++ b/src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorageBase.java @@ -18,19 +18,21 @@ public class DhtStorageBase implements DhtStorage { private final DhtSettings settings; private final Counters counters; - private final HashMap map; + private final HashMap torrents; + private final TreeMap immutables; public DhtStorageBase(Sha1Hash id, DhtSettings settings) { this.id = id; this.settings = settings; this.counters = new Counters(); - this.map = new HashMap(); + this.torrents = new HashMap(); + this.immutables = new TreeMap(); } @Override public boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry peers) { - TorrentEntry v = map.get(infoHash); + TorrentEntry v = torrents.get(infoHash); if (v == null) { return false; @@ -80,16 +82,16 @@ public boolean getPeers(Sha1Hash infoHash, boolean noseed, boolean scrape, entry @Override public void announcePeer(Sha1Hash infoHash, TcpEndpoint endp, String name, boolean seed) { - TorrentEntry v = map.get(infoHash); + TorrentEntry v = torrents.get(infoHash); if (v == null) { // we don't have this torrent, add it // do we need to remove another one first? - if (!map.isEmpty() && map.size() >= settings.maxTorrents()) { + if (!torrents.isEmpty() && torrents.size() >= settings.maxTorrents()) { // we need to remove some. Remove the ones with the // fewest peers int num_peers = Integer.MAX_VALUE; Sha1Hash candidateKey = null; - for (Map.Entry kv : map.entrySet()) { + for (Map.Entry kv : torrents.entrySet()) { if (kv.getValue().peers.size() > num_peers) { continue; @@ -100,13 +102,13 @@ public void announcePeer(Sha1Hash infoHash, TcpEndpoint endp, String name, boole num_peers = kv.getValue().peers.size(); candidateKey = kv.getKey(); } - map.remove(candidateKey); + torrents.remove(candidateKey); counters.peers -= num_peers; counters.torrents -= 1; } counters.torrents += 1; v = new TorrentEntry(); - map.put(infoHash, v); + torrents.put(infoHash, v); } // the peer announces a torrent name, and we don't have a name @@ -146,7 +148,13 @@ public void announcePeer(Sha1Hash infoHash, TcpEndpoint endp, String name, boole @Override public boolean getImmutableItem(Sha1Hash target, entry item) { - return false; + DhtImmutableItem i = immutables.get(target); + if (i == null) { + return false; + } + + //item.set("v", = bdecode(i->second.value, i->second.value + i->second.size); + return true; } @Override diff --git a/src/main/java/com/frostwire/jlibtorrent/swig/entry.java b/src/main/java/com/frostwire/jlibtorrent/swig/entry.java index 146327061..682216e55 100644 --- a/src/main/java/com/frostwire/jlibtorrent/swig/entry.java +++ b/src/main/java/com/frostwire/jlibtorrent/swig/entry.java @@ -124,6 +124,10 @@ public void set(String key, long value) { libtorrent_jni.entry_set__SWIG_2(swigCPtr, this, key, value); } + public void set(String key, entry value) { + libtorrent_jni.entry_set__SWIG_3(swigCPtr, this, key, entry.getCPtr(value), value); + } + public byte_vector string_bytes() { return new byte_vector(libtorrent_jni.entry_string_bytes(swigCPtr, this), true); } diff --git a/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java b/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java index 8679ba0e5..276f38efd 100644 --- a/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java +++ b/src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java @@ -599,6 +599,7 @@ public class libtorrent_jni { 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_); public final static native void entry_set__SWIG_2(long jarg1, entry jarg1_, String jarg2, long jarg3); + public final static native void entry_set__SWIG_3(long jarg1, entry jarg1_, String jarg2, long jarg3, entry jarg3_); public final static native long entry_string_bytes(long jarg1, entry jarg1_); public final static native long entry_bencode(long jarg1, entry jarg1_); public final static native long entry_bdecode(long jarg1, byte_vector jarg1_); diff --git a/swig/libtorrent.i b/swig/libtorrent.i index 2fb9d7378..256a46e26 100644 --- a/swig/libtorrent.i +++ b/swig/libtorrent.i @@ -940,6 +940,10 @@ namespace libtorrent { $self->operator[](key) = value; } + void set(std::string const& key, libtorrent::entry const& value) { + $self->operator[](key) = value; + } + std::vector string_bytes() { std::string s = $self->string(); return std::vector(s.begin(), s.end()); diff --git a/swig/libtorrent_jni.cpp b/swig/libtorrent_jni.cpp index c0a81a70a..4a956ada2 100644 --- a/swig/libtorrent_jni.cpp +++ b/swig/libtorrent_jni.cpp @@ -1241,6 +1241,9 @@ SWIGINTERN void libtorrent_entry_set__SWIG_1(libtorrent::entry *self,std::string SWIGINTERN void libtorrent_entry_set__SWIG_2(libtorrent::entry *self,std::string const &key,long long const &value){ self->operator[](key) = value; } +SWIGINTERN void libtorrent_entry_set__SWIG_3(libtorrent::entry *self,std::string const &key,libtorrent::entry const &value){ + self->operator[](key) = value; + } SWIGINTERN std::vector< int8_t > libtorrent_entry_string_bytes(libtorrent::entry *self){ std::string s = self->string(); return std::vector(s.begin(), s.end()); @@ -17539,6 +17542,42 @@ SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entr } +SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1set_1_1SWIG_13(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jlong jarg3, jobject jarg3_) { + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + libtorrent::entry *arg3 = 0 ; + + (void)jenv; + (void)jcls; + (void)jarg1_; + (void)jarg3_; + arg1 = *(libtorrent::entry **)&jarg1; + if(!jarg2) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); + return ; + } + const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2_pstr) return ; + std::string arg2_str(arg2_pstr); + arg2 = &arg2_str; + jenv->ReleaseStringUTFChars(jarg2, arg2_pstr); + arg3 = *(libtorrent::entry **)&jarg3; + if (!arg3) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "libtorrent::entry const & reference is null"); + return ; + } + { + try { + libtorrent_entry_set__SWIG_3(arg1,(std::string const &)*arg2,(libtorrent::entry const &)*arg3); + } catch (std::exception& e) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.what()); + } catch (...) { + SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "Unknown exception type"); + } + } +} + + SWIGEXPORT jlong JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_entry_1string_1bytes(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jlong jresult = 0 ; libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; @@ -61984,7 +62023,7 @@ SWIGEXPORT jstring JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_J (void)jenv; (void)jcls; - result = (char *)("25c160b3a20f0e71d58997b18ff7d43ae7054dd5"); + result = (char *)("c6204c2b0e8700611ec9b20fc2782c9fb1d9a806"); if (result) jresult = jenv->NewStringUTF((const char *)result); return jresult; } diff --git a/swig/libtorrent_node.cpp b/swig/libtorrent_node.cpp index f2e0b8aab..ad92b6096 100644 --- a/swig/libtorrent_node.cpp +++ b/swig/libtorrent_node.cpp @@ -2629,6 +2629,9 @@ SWIGINTERN void libtorrent_entry_set__SWIG_1(libtorrent::entry *self,std::string SWIGINTERN void libtorrent_entry_set__SWIG_2(libtorrent::entry *self,std::string const &key,long long const &value){ self->operator[](key) = value; } +SWIGINTERN void libtorrent_entry_set__SWIG_3(libtorrent::entry *self,std::string const &key,libtorrent::entry const &value){ + self->operator[](key) = value; + } SWIGINTERN std::vector< int8_t > libtorrent_entry_string_bytes(libtorrent::entry *self){ std::string s = self->string(); return std::vector(s.begin(), s.end()); @@ -23741,6 +23744,58 @@ static SwigV8ReturnValue _wrap_entry_set__SWIG_2(const SwigV8Arguments &args, V8 } +static SwigV8ReturnValue _wrap_entry_set__SWIG_3(const SwigV8Arguments &args, V8ErrorHandler &SWIGV8_ErrorHandler) +{ + SWIGV8_HANDLESCOPE(); + + v8::Handle jsresult; + libtorrent::entry *arg1 = (libtorrent::entry *) 0 ; + std::string *arg2 = 0 ; + libtorrent::entry *arg3 = 0 ; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 = SWIG_OLDOBJ ; + void *argp3 ; + int res3 = 0 ; + + res1 = SWIG_ConvertPtr(args.Holder(), &argp1,SWIGTYPE_p_libtorrent__entry, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "entry_set" "', argument " "1"" of type '" "libtorrent::entry *""'"); + } + arg1 = (libtorrent::entry *)(argp1); + { + std::string *ptr = (std::string *)0; + res2 = SWIG_AsPtr_std_string(args[0], &ptr); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "entry_set" "', argument " "2"" of type '" "std::string const &""'"); + } + if (!ptr) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "entry_set" "', argument " "2"" of type '" "std::string const &""'"); + } + arg2 = ptr; + } + res3 = SWIG_ConvertPtr(args[1], &argp3, SWIGTYPE_p_libtorrent__entry, 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "entry_set" "', argument " "3"" of type '" "libtorrent::entry const &""'"); + } + if (!argp3) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "entry_set" "', argument " "3"" of type '" "libtorrent::entry const &""'"); + } + arg3 = (libtorrent::entry *)(argp3); + libtorrent_entry_set__SWIG_3(arg1,(std::string const &)*arg2,(libtorrent::entry const &)*arg3); + jsresult = SWIGV8_UNDEFINED(); + + if (SWIG_IsNewObj(res2)) delete arg2; + + + SWIGV8_RETURN(jsresult); + + goto fail; +fail: + SWIGV8_RETURN(SWIGV8_UNDEFINED()); +} + + static SwigV8ReturnValue _wrap_entry__wrap_entry_set(const SwigV8Arguments &args) { SWIGV8_HANDLESCOPE(); @@ -23796,6 +23851,22 @@ static SwigV8ReturnValue _wrap_entry__wrap_entry_set(const SwigV8Arguments &args } + if(args.Length() == 2) { + errorHandler.err.Clear(); +#if (SWIG_V8_VERSION < 0x031903) + jsresult = _wrap_entry_set__SWIG_3(args, errorHandler); + if(errorHandler.err.IsEmpty()) { + SWIGV8_ESCAPE(jsresult); + } +#else + _wrap_entry_set__SWIG_3(args, errorHandler); + if(errorHandler.err.IsEmpty()) { + return; + } +#endif + } + + SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function set."); goto fail; @@ -104346,7 +104417,7 @@ static SwigV8ReturnValue _wrap_JLIBTORRENT_REVISION_SHA1(v8::Local p v8::Handle jsresult; - jsresult = SWIG_FromCharPtr((const char *)"25c160b3a20f0e71d58997b18ff7d43ae7054dd5"); + jsresult = SWIG_FromCharPtr((const char *)"c6204c2b0e8700611ec9b20fc2782c9fb1d9a806"); SWIGV8_RETURN_INFO(jsresult, info);