Skip to content

Commit

Permalink
Better API for dht storage counters
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 10, 2016
1 parent d37d105 commit fa64e5d
Show file tree
Hide file tree
Showing 10 changed files with 687 additions and 520 deletions.
15 changes: 8 additions & 7 deletions src/main/java/com/frostwire/jlibtorrent/plugins/DhtStorage.java
Expand Up @@ -27,11 +27,12 @@ public interface DhtStorage {

void tick();

long numTorrents();

long numPeers();

long numImmutableData();

long numMutableData();
Counters counters();

final class Counters {
int torrents;
int peers;
int immutable_data;
int mutable_data;
}
}
Expand Up @@ -14,10 +14,12 @@ public final class MemoryDhtStorage implements DhtStorage {

private final Sha1Hash id;
private final DhtSettings settings;
private final Counters counters;

public MemoryDhtStorage(Sha1Hash id, DhtSettings settings) {
this.id = id;
this.settings = settings;
this.counters = new Counters();
}

@Override
Expand Down Expand Up @@ -61,22 +63,7 @@ public void tick() {
}

@Override
public long numTorrents() {
return 0;
}

@Override
public long numPeers() {
return 0;
}

@Override
public long numImmutableData() {
return 0;
}

@Override
public long numMutableData() {
return 0;
public Counters counters() {
return counters;
}
}
Expand Up @@ -66,22 +66,13 @@ public void tick() {
}

@Override
public long num_torrents() {
return s.numTorrents();
}

@Override
public long num_peers() {
return s.numPeers();
}

@Override
public long num_immutable_data() {
return s.numImmutableData();
}

@Override
public long num_mutable_data() {
return s.numMutableData();
public swig_dht_storage_counters swig_counters() {
DhtStorage.Counters counters = s.counters();
swig_dht_storage_counters c = new swig_dht_storage_counters();
c.setTorrents(counters.torrents);
c.setPeers(counters.peers);
c.setImmutable_data(counters.immutable_data);
c.setMutable_data(counters.mutable_data);
return c;
}
}
33 changes: 14 additions & 19 deletions src/main/java/com/frostwire/jlibtorrent/swig/libtorrent_jni.java
Expand Up @@ -3058,6 +3058,16 @@ public class libtorrent_jni {
public final static native long new_swig_storage_constructor();
public final static native void swig_storage_constructor_director_connect(swig_storage_constructor obj, long cptr, boolean mem_own, boolean weak_global);
public final static native void swig_storage_constructor_change_ownership(swig_storage_constructor obj, long cptr, boolean take_or_release);
public final static native void swig_dht_storage_counters_torrents_set(long jarg1, swig_dht_storage_counters jarg1_, int jarg2);
public final static native int swig_dht_storage_counters_torrents_get(long jarg1, swig_dht_storage_counters jarg1_);
public final static native void swig_dht_storage_counters_peers_set(long jarg1, swig_dht_storage_counters jarg1_, int jarg2);
public final static native int swig_dht_storage_counters_peers_get(long jarg1, swig_dht_storage_counters jarg1_);
public final static native void swig_dht_storage_counters_immutable_data_set(long jarg1, swig_dht_storage_counters jarg1_, int jarg2);
public final static native int swig_dht_storage_counters_immutable_data_get(long jarg1, swig_dht_storage_counters jarg1_);
public final static native void swig_dht_storage_counters_mutable_data_set(long jarg1, swig_dht_storage_counters jarg1_, int jarg2);
public final static native int swig_dht_storage_counters_mutable_data_get(long jarg1, swig_dht_storage_counters jarg1_);
public final static native long new_swig_dht_storage_counters();
public final static native void delete_swig_dht_storage_counters(long jarg1);
public final static native boolean swig_dht_storage_get_peers(long jarg1, swig_dht_storage jarg1_, long jarg2, sha1_hash jarg2_, boolean jarg3, boolean jarg4, long jarg5, entry jarg5_);
public final static native boolean swig_dht_storage_get_peersSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_, long jarg2, sha1_hash jarg2_, boolean jarg3, boolean jarg4, long jarg5, entry jarg5_);
public final static native void swig_dht_storage_announce_peer(long jarg1, swig_dht_storage jarg1_, long jarg2, sha1_hash jarg2_, long jarg3, tcp_endpoint jarg3_, String jarg4, boolean jarg5);
Expand All @@ -3074,14 +3084,8 @@ public class libtorrent_jni {
public final static native void swig_dht_storage_put_mutable_itemSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_, long jarg2, sha1_hash jarg2_, long jarg3, byte_vector jarg3_, long jarg4, byte_vector jarg4_, long jarg5, long jarg6, byte_vector jarg6_, long jarg7, byte_vector jarg7_, long jarg8, address jarg8_);
public final static native void swig_dht_storage_tick(long jarg1, swig_dht_storage jarg1_);
public final static native void swig_dht_storage_tickSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_torrents(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_torrentsSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_peers(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_peersSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_immutable_data(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_immutable_dataSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_mutable_data(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_num_mutable_dataSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_swig_counters(long jarg1, swig_dht_storage jarg1_);
public final static native long swig_dht_storage_swig_countersSwigExplicitswig_dht_storage(long jarg1, swig_dht_storage jarg1_);
public final static native void delete_swig_dht_storage(long jarg1);
public final static native long new_swig_dht_storage();
public final static native void swig_dht_storage_director_connect(swig_dht_storage obj, long cptr, boolean mem_own, boolean weak_global);
Expand Down Expand Up @@ -3387,17 +3391,8 @@ public static void SwigDirector_swig_dht_storage_put_mutable_item(swig_dht_stora
public static void SwigDirector_swig_dht_storage_tick(swig_dht_storage jself) {
jself.tick();
}
public static long SwigDirector_swig_dht_storage_num_torrents(swig_dht_storage jself) {
return jself.num_torrents();
}
public static long SwigDirector_swig_dht_storage_num_peers(swig_dht_storage jself) {
return jself.num_peers();
}
public static long SwigDirector_swig_dht_storage_num_immutable_data(swig_dht_storage jself) {
return jself.num_immutable_data();
}
public static long SwigDirector_swig_dht_storage_num_mutable_data(swig_dht_storage jself) {
return jself.num_mutable_data();
public static long SwigDirector_swig_dht_storage_swig_counters(swig_dht_storage jself) {
return swig_dht_storage_counters.getCPtr(jself.swig_counters());
}
public static long SwigDirector_swig_dht_storage_constructor_create(swig_dht_storage_constructor jself, long id, long settings) {
return swig_dht_storage.getCPtr(jself.create(new sha1_hash(id, false), new dht_settings(settings, false)));
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/com/frostwire/jlibtorrent/swig/swig_dht_storage.java
Expand Up @@ -82,20 +82,8 @@ public void tick() {
if (getClass() == swig_dht_storage.class) libtorrent_jni.swig_dht_storage_tick(swigCPtr, this); else libtorrent_jni.swig_dht_storage_tickSwigExplicitswig_dht_storage(swigCPtr, this);
}

public long num_torrents() {
return (getClass() == swig_dht_storage.class) ? libtorrent_jni.swig_dht_storage_num_torrents(swigCPtr, this) : libtorrent_jni.swig_dht_storage_num_torrentsSwigExplicitswig_dht_storage(swigCPtr, this);
}

public long num_peers() {
return (getClass() == swig_dht_storage.class) ? libtorrent_jni.swig_dht_storage_num_peers(swigCPtr, this) : libtorrent_jni.swig_dht_storage_num_peersSwigExplicitswig_dht_storage(swigCPtr, this);
}

public long num_immutable_data() {
return (getClass() == swig_dht_storage.class) ? libtorrent_jni.swig_dht_storage_num_immutable_data(swigCPtr, this) : libtorrent_jni.swig_dht_storage_num_immutable_dataSwigExplicitswig_dht_storage(swigCPtr, this);
}

public long num_mutable_data() {
return (getClass() == swig_dht_storage.class) ? libtorrent_jni.swig_dht_storage_num_mutable_data(swigCPtr, this) : libtorrent_jni.swig_dht_storage_num_mutable_dataSwigExplicitswig_dht_storage(swigCPtr, this);
public swig_dht_storage_counters swig_counters() {
return new swig_dht_storage_counters((getClass() == swig_dht_storage.class) ? libtorrent_jni.swig_dht_storage_swig_counters(swigCPtr, this) : libtorrent_jni.swig_dht_storage_swig_countersSwigExplicitswig_dht_storage(swigCPtr, this), true);
}

public swig_dht_storage() {
Expand Down
@@ -0,0 +1,74 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.8
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

package com.frostwire.jlibtorrent.swig;

public class swig_dht_storage_counters {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected swig_dht_storage_counters(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}

protected static long getCPtr(swig_dht_storage_counters obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}

protected void finalize() {
delete();
}

public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
libtorrent_jni.delete_swig_dht_storage_counters(swigCPtr);
}
swigCPtr = 0;
}
}

public void setTorrents(int value) {
libtorrent_jni.swig_dht_storage_counters_torrents_set(swigCPtr, this, value);
}

public int getTorrents() {
return libtorrent_jni.swig_dht_storage_counters_torrents_get(swigCPtr, this);
}

public void setPeers(int value) {
libtorrent_jni.swig_dht_storage_counters_peers_set(swigCPtr, this, value);
}

public int getPeers() {
return libtorrent_jni.swig_dht_storage_counters_peers_get(swigCPtr, this);
}

public void setImmutable_data(int value) {
libtorrent_jni.swig_dht_storage_counters_immutable_data_set(swigCPtr, this, value);
}

public int getImmutable_data() {
return libtorrent_jni.swig_dht_storage_counters_immutable_data_get(swigCPtr, this);
}

public void setMutable_data(int value) {
libtorrent_jni.swig_dht_storage_counters_mutable_data_set(swigCPtr, this, value);
}

public int getMutable_data() {
return libtorrent_jni.swig_dht_storage_counters_mutable_data_get(swigCPtr, this);
}

public swig_dht_storage_counters() {
this(libtorrent_jni.new_swig_dht_storage_counters(), true);
}

}
33 changes: 15 additions & 18 deletions swig/libtorrent.h
Expand Up @@ -320,6 +320,14 @@ storage_interface* swig_storage_constructor_cb(libtorrent::storage_params const&

//------ DHT storage extension -----------------------------

struct swig_dht_storage_counters
{
boost::int32_t torrents;
boost::int32_t peers;
boost::int32_t immutable_data;
boost::int32_t mutable_data;
};

struct swig_dht_storage : dht::dht_storage_interface
{
virtual bool get_peers(libtorrent::sha1_hash const& info_hash
Expand Down Expand Up @@ -394,29 +402,18 @@ struct swig_dht_storage : dht::dht_storage_interface

dht::dht_storage_counters counters() const {
dht::dht_storage_counters c;
c.torrents = num_torrents();
c.peers = num_peers();
c.immutable_data = num_immutable_data();
c.mutable_data = num_mutable_data();
swig_dht_storage_counters sc = swig_counters();
c.torrents = sc.torrents;
c.peers = sc.peers;
c.immutable_data = sc.immutable_data;
c.mutable_data = sc.mutable_data;
return c;
}

virtual size_t num_torrents() const {
return 0;
virtual swig_dht_storage_counters swig_counters() const {
return swig_dht_storage_counters();
}

virtual size_t num_peers() const {
return 0;
}

virtual size_t num_immutable_data() const {
return 0;
}

virtual size_t num_mutable_data() const {
return 0;
}

virtual ~swig_dht_storage() {}
};

Expand Down

0 comments on commit fa64e5d

Please sign in to comment.