-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved SessionStats. Working DhtRouter test.
- Loading branch information
Showing
11 changed files
with
142 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
package com.frostwire.jlibtorrent; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author gubatron | ||
* @author aldenml | ||
*/ | ||
public final class SessionStats { | ||
|
||
private static final int dhtNodesIdx = LibTorrent.findMetricIdx("dht.dht_nodes"); | ||
private static final StatsMetric[] statsMetrics = LibTorrent.sessionStatsMetrics(); | ||
|
||
private final long[] statsValues; | ||
private final long dhtNodes; | ||
|
||
SessionStats(long[] statsValues) { | ||
SessionStats(long[] statsValues, long dhtNodes) { | ||
this.statsValues = statsValues; | ||
this.dhtNodes = dhtNodes; | ||
} | ||
|
||
private Map<String, Long> getNonZeroValues() { | ||
if (statsValues == null) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
HashMap<String, Long> m = new HashMap<String, Long>(); | ||
|
||
for (StatsMetric sm : statsMetrics) { | ||
long value = statsValues[sm.getValueIndex()]; | ||
if (value != 0) { | ||
m.put(sm.getName(), value); | ||
} | ||
} | ||
|
||
return Collections.unmodifiableMap(m); | ||
} | ||
|
||
public long getDHTNodes() { | ||
return statsValues != null ? statsValues[dhtNodesIdx] : 0; | ||
return dhtNodes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.frostwire.jlibtorrent.alerts; | ||
|
||
import com.frostwire.jlibtorrent.DHTLookup; | ||
import com.frostwire.jlibtorrent.DHTRoutingBucket; | ||
import com.frostwire.jlibtorrent.swig.dht_lookup_vector; | ||
import com.frostwire.jlibtorrent.swig.dht_routing_bucket_vector; | ||
import com.frostwire.jlibtorrent.swig.dht_stats_alert; | ||
|
||
/** | ||
* Contains current DHT state. Posted in response to {@link com.frostwire.jlibtorrent.Session#postDHTStats()}. | ||
* | ||
* @author gubatron | ||
* @author aldenml | ||
*/ | ||
public final class DhtStatsAlert extends AbstractAlert<dht_stats_alert> { | ||
|
||
public DhtStatsAlert(dht_stats_alert alert) { | ||
super(alert); | ||
} | ||
|
||
public DHTLookup[] getActiveRequests() { | ||
dht_lookup_vector v = alert.getActive_requests(); | ||
|
||
int size = (int) v.size(); | ||
DHTLookup[] arr = new DHTLookup[size]; | ||
|
||
for (int i = 0; i < size; i++) { | ||
arr[i] = new DHTLookup(v.get(i)); | ||
} | ||
|
||
return arr; | ||
} | ||
|
||
public DHTRoutingBucket[] getRoutingTable() { | ||
dht_routing_bucket_vector v = alert.getRouting_table(); | ||
|
||
int size = (int) v.size(); | ||
DHTRoutingBucket[] arr = new DHTRoutingBucket[size]; | ||
|
||
for (int i = 0; i < size; i++) { | ||
arr[i] = new DHTRoutingBucket(v.get(i)); | ||
} | ||
|
||
return arr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters