Class LibTorrent

java.lang.Object
com.frostwire.jlibtorrent.LibTorrent

public final class LibTorrent extends Object
System information and version utilities for libtorrent and jlibtorrent.

LibTorrent provides access to library version information, dependency versions, platform capabilities, and session metrics. This is useful for logging, debugging, feature detection, and reporting.

Version Information:

 // Get version info for debugging and logs
 System.out.println("LibTorrent version: " + LibTorrent.version());
 System.out.println("LibTorrent version num: " + LibTorrent.versionNum());
 System.out.println("LibTorrent revision: " + LibTorrent.revision());

 System.out.println("JLibTorrent version: " + LibTorrent.jlibtorrentVersion());

 System.out.println("Boost version: " + LibTorrent.boostVersion());
 System.out.println("OpenSSL version: " + LibTorrent.opensslVersion());

 // Output example:
 // LibTorrent version: 2.0.5
 // LibTorrent version num: 131589
 // LibTorrent revision: c2012b084c6654d681720ea0693d87a48bc95b14
 // JLibTorrent version: 2.0.12.9
 // Boost version: 1_78_0
 // OpenSSL version: OpenSSL 1.1.1n  15 Mar 2022
 

Platform Detection and Capabilities:

 // Check for ARM NEON support (ARM optimization)
 if (LibTorrent.hasArmNeonSupport()) {
     System.out.println("Running on ARM with NEON support");
 } else {
     System.out.println("Not running ARM NEON platform");
 }
 

Session Metrics Discovery:

 // Get all available metrics for session statistics
 List<StatsMetric> metrics = LibTorrent.sessionStatsMetrics();

 System.out.println("Available session metrics: " + metrics.size());
 for (StatsMetric metric : metrics) {
     System.out.println("  " + metric.name() + " (index " + metric.valueIndex() + ")");
 }

 // Example output (first few):
 // Available session metrics: 150+
 //   net.sent_payload_bytes (index 0)
 //   net.recv_payload_bytes (index 1)
 //   net.sent_bytes (index 2)
 //   net.recv_bytes (index 3)
 //   net.read_bytes (index 4)
 //   ...
 

Metrics Lookup:

 // Find metric index by name
 int downloadIndex = LibTorrent.findMetricIdx("net.recv_payload_bytes");
 int uploadIndex = LibTorrent.findMetricIdx("net.sent_payload_bytes");

 if (downloadIndex >= 0 && uploadIndex >= 0) {
     System.out.println("Found download metric at index: " + downloadIndex);
     System.out.println("Found upload metric at index: " + uploadIndex);

     // Use these indices with SessionStatsAlert.values()
     // to get actual metric values from session statistics
 } else {
     System.out.println("Metric not found");
 }
 

Using Metrics with Session Statistics:

 // Get session metrics
 List<StatsMetric> metrics = LibTorrent.sessionStatsMetrics();

 // Post session stats request
 sm.postSessionStats();

 // In your alert listener for SessionStatsAlert:
 // SessionStatsAlert alert = ...;
 // long[] values = alert.values();

 // Look up a metric
 int idx = LibTorrent.findMetricIdx("net.recv_payload_bytes");
 if (idx >= 0) {
     long bytesReceived = values[idx];
     System.out.println("Downloaded: " + bytesReceived + " bytes");
 }
 

Typical Use Case - Version Reporting:

 // Log library versions on startup
 String versionInfo = String.format(
     "JLibTorrent %s (libtorrent %s, Boost %s, OpenSSL %s)",
     LibTorrent.jlibtorrentVersion(),
     LibTorrent.version(),
     LibTorrent.boostVersion(),
     LibTorrent.opensslVersion()
 );
 System.out.println(versionInfo);

 // Report capabilities
 if (LibTorrent.hasArmNeonSupport()) {
     System.out.println("Platform: ARM with NEON optimization");
 }
 
See Also:
  • Method Details

    • versionNum

      public static int versionNum()
      The version number as reported by libtorrent
      Returns:
      the version number
    • version

      public static String version()
      The version string as reported by libtorrent
      Returns:
      the version string
    • revision

      public static String revision()
      The git revision of libtorrent the native library is using.

      This is not the internal revision libtorrent reports, since that string is updated from time to time. This library can be using an up to date revision, this string is manually hardcoded in each version of jlibtorrent. See libtorrentConstants.LIBTORRENT_REVISION for the libtorrent string.

      Returns:
      the git revision
    • boostVersionNum

      public static int boostVersionNum()
    • boostVersion

      public static String boostVersion()
    • opensslVersionNum

      public static int opensslVersionNum()
    • opensslVersion

      public static String opensslVersion()
    • jlibtorrentVersion

      public static String jlibtorrentVersion()
    • sessionStatsMetrics

      public static List<StatsMetric> sessionStatsMetrics()
      This free function returns the list of available metrics exposed by libtorrent's statistics API. Each metric has a name and a *value index*. The value index is the index into the array in session_stats_alert where this metric's value can be found when the session stats is sampled (by calling post_session_stats()).
      Returns:
      the list of all metrics
    • findMetricIdx

      public static int findMetricIdx(String name)
      given a name of a metric, this function returns the counter index of it, or -1 if it could not be found. The counter index is the index into the values array returned by session_stats_alert.
      Parameters:
      name - the name of the metric
      Returns:
      the index of the metric
    • hasArmNeonSupport

      public static boolean hasArmNeonSupport()
      If the native library is an ARM architecture variant, returns true if the running platform has NEON support.
      Returns:
      true if the running platform has NEON support