Skip to content

Commit

Permalink
New DHT announce method with custom port and flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Nov 18, 2014
1 parent 0840a3b commit 3ec95e7
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/com/frostwire/jlibtorrent/DHT.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public void getPeers(String sha1) {
s.dhtGetPeers(new Sha1Hash(sha1));
}

public void announce(String sha1, int port, int flags) {
s.dhtAnnounce(new Sha1Hash(sha1), port, flags);
}

public void announce(String sha1) {
s.dhtAnnounce(new Sha1Hash(sha1));
}
Expand Down
4 changes: 4 additions & 0 deletions src/com/frostwire/jlibtorrent/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,10 @@ public void dhtGetPeers(Sha1Hash infoHash) {
s.dht_get_peers(infoHash.getSwig());
}

public void dhtAnnounce(Sha1Hash infoHash, int port, int flags) {

This comment has been minimized.

Copy link
@gubatron

gubatron Nov 19, 2014

Collaborator

what flags can be used here?

This comment has been minimized.

This comment has been minimized.

Copy link
@gubatron

gubatron Nov 19, 2014

Collaborator

thanks

s.dht_announce(infoHash.getSwig(), port, flags);
}

public void dhtAnnounce(Sha1Hash infoHash) {
s.dht_announce(infoHash.getSwig());
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/frostwire/jlibtorrent/demo/DhtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void alert(Alert<?> alert) {

Thread.sleep(4000);

dht.announce("47d0502ead28e495c9e67665340f72aa72fe304");
dht.announce("47d0502ead28e495c9e67665340f72aa72fe304", 9999, 0);

System.out.println("Waiting 15 seconds");
Thread.sleep(15000);
Expand Down
3 changes: 2 additions & 1 deletion src/com/frostwire/jlibtorrent/swig/libtorrent_jni.java
Original file line number Diff line number Diff line change
Expand Up @@ -3478,7 +3478,8 @@ public class libtorrent_jni {
public final static native void session_dht_put_item__SWIG_1(long jarg1, session jarg1_, long jarg2, char_vector jarg2_, long jarg3, char_vector jarg3_, long jarg4, entry jarg4_, String jarg5);
public final static native void session_dht_put_item__SWIG_2(long jarg1, session jarg1_, long jarg2, char_vector jarg2_, long jarg3, char_vector jarg3_, long jarg4, entry jarg4_);
public final static native void session_dht_get_peers(long jarg1, session jarg1_, long jarg2, sha1_hash jarg2_);
public final static native void session_dht_announce(long jarg1, session jarg1_, long jarg2, sha1_hash jarg2_);
public final static native void session_dht_announce__SWIG_0(long jarg1, session jarg1_, long jarg2, sha1_hash jarg2_, int jarg3, int jarg4);
public final static native void session_dht_announce__SWIG_1(long jarg1, session jarg1_, long jarg2, sha1_hash jarg2_);
public final static native int plus_one(int jarg1);
public final static native int minus_one(int jarg1);
public final static native int ip_filter_blocked_get();
Expand Down
6 changes: 5 additions & 1 deletion src/com/frostwire/jlibtorrent/swig/session.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,12 @@ public void dht_get_peers(sha1_hash info_hash) {
libtorrent_jni.session_dht_get_peers(swigCPtr, this, sha1_hash.getCPtr(info_hash), info_hash);
}

public void dht_announce(sha1_hash info_hash, int port, int flags) {
libtorrent_jni.session_dht_announce__SWIG_0(swigCPtr, this, sha1_hash.getCPtr(info_hash), info_hash, port, flags);
}

public void dht_announce(sha1_hash info_hash) {
libtorrent_jni.session_dht_announce(swigCPtr, this, sha1_hash.getCPtr(info_hash), info_hash);
libtorrent_jni.session_dht_announce__SWIG_1(swigCPtr, this, sha1_hash.getCPtr(info_hash), info_hash);
}

public enum save_state_flags_t {
Expand Down
38 changes: 35 additions & 3 deletions swig/libtorrent_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,10 @@ SWIGINTERN void libtorrent_session_dht_put_item__SWIG_1(libtorrent::session *sel
SWIGINTERN void libtorrent_session_dht_get_peers(libtorrent::session *self,libtorrent::sha1_hash const &info_hash){
dht_get_peers(self, info_hash);
}
SWIGINTERN void libtorrent_session_dht_announce(libtorrent::session *self,libtorrent::sha1_hash const &info_hash){
SWIGINTERN void libtorrent_session_dht_announce__SWIG_0(libtorrent::session *self,libtorrent::sha1_hash const &info_hash,int port,int flags){
dht_announce(self, info_hash, port, flags);
}
SWIGINTERN void libtorrent_session_dht_announce__SWIG_1(libtorrent::session *self,libtorrent::sha1_hash const &info_hash){
dht_announce(self, info_hash);
}
SWIGINTERN int libtorrent_lazy_entry_bdecode(std::vector< char > &buffer,libtorrent::lazy_entry &e,libtorrent::error_code &ec){
Expand Down Expand Up @@ -67336,7 +67339,36 @@ SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_sess
}


SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_session_1dht_1announce(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_session_1dht_1announce_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jint jarg3, jint jarg4) {
libtorrent::session *arg1 = (libtorrent::session *) 0 ;
libtorrent::sha1_hash *arg2 = 0 ;
int arg3 ;
int arg4 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg2_;
arg1 = *(libtorrent::session **)&jarg1;
arg2 = *(libtorrent::sha1_hash **)&jarg2;
if (!arg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "libtorrent::sha1_hash const & reference is null");
return ;
}
arg3 = (int)jarg3;
arg4 = (int)jarg4;
{
try {
libtorrent_session_dht_announce__SWIG_0(arg1,(libtorrent::sha1_hash const &)*arg2,arg3,arg4);
} catch (...) {
translate_cpp_exception(jenv);
return ;
}
}
}


SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_session_1dht_1announce_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
libtorrent::session *arg1 = (libtorrent::session *) 0 ;
libtorrent::sha1_hash *arg2 = 0 ;

Expand All @@ -67352,7 +67384,7 @@ SWIGEXPORT void JNICALL Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_sess
}
{
try {
libtorrent_session_dht_announce(arg1,(libtorrent::sha1_hash const &)*arg2);
libtorrent_session_dht_announce__SWIG_1(arg1,(libtorrent::sha1_hash const &)*arg2);
} catch (...) {
translate_cpp_exception(jenv);
return ;
Expand Down
11 changes: 8 additions & 3 deletions swig/session_extend.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,18 @@ void dht_get_peers(session* s, sha1_hash const& info_hash) {
ta->start();
}

void dht_announce(session* s, sha1_hash const& info_hash) {
void dht_announce(session* s, sha1_hash const& info_hash, int port, int flags) {

boost::shared_ptr<aux::session_impl> s_impl = *s.*result<session_m_impl>::ptr;
boost::intrusive_ptr<dht::dht_tracker> s_dht_tracker = s_impl->m_dht;
const reference_wrapper<libtorrent::dht::node_impl> node = boost::ref(*s_dht_tracker.*result<dht_tracker_m_dht>::ptr);

int port = s->listen_port();
node.get().announce(info_hash, port, flags, boost::bind(&dht_get_peers_fun, _1, s_impl, info_hash));
}

void dht_announce(session* s, sha1_hash const& info_hash) {

int port = s->listen_port();

int flags = 0;
// if we allow incoming uTP connections, set the implied_port
Expand All @@ -139,5 +144,5 @@ void dht_announce(session* s, sha1_hash const& info_hash) {
// likely more accurate when behind a NAT
if (s->settings().enable_incoming_utp) flags |= dht::dht_tracker::flag_implied_port;

node.get().announce(info_hash, port, flags, boost::bind(&dht_get_peers_fun, _1, s_impl, info_hash));
dht_announce(s, info_hash, port, flags);
}
4 changes: 4 additions & 0 deletions swig/session_extend.i
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ namespace libtorrent {
dht_get_peers($self, info_hash);
}

void dht_announce(sha1_hash const& info_hash, int port, int flags) {
dht_announce($self, info_hash, port, flags);
}

void dht_announce(sha1_hash const& info_hash) {
dht_announce($self, info_hash);
}
Expand Down

0 comments on commit 3ec95e7

Please sign in to comment.