Class PeerInfo

java.lang.Object
com.frostwire.jlibtorrent.PeerInfo

public class PeerInfo extends Object
Statistics and information for a single connected peer.

PeerInfo provides a snapshot of statistics for a peer you're connected to while downloading a torrent. It includes data transfer rates, protocol information, peer identification, connection state, and download progress.

Getting Peer Information:

 TorrentHandle th = ...;  // Get from download

 // Get list of all peers we're connected to
 List<PeerInfo> peers = th.peerInfo();

 System.out.println("Connected to " + peers.size() + " peers");

 for (PeerInfo peer : peers) {
     System.out.println("Peer: " + peer.ip());
     System.out.println("  Client: " + peer.client());
     System.out.println("  Progress: " + (peer.progress() * 100) + "%");
     System.out.println("  Download speed: " + (peer.downSpeed() / 1024) + " KB/s");
     System.out.println("  Upload speed: " + (peer.upSpeed() / 1024) + " KB/s");
     System.out.println("  Total downloaded: " + peer.totalDownload() + " bytes");
     System.out.println("  Total uploaded: " + peer.totalUpload() + " bytes");
 }
 

Peer Statistics and Metrics:

 for (PeerInfo peer : peers) {
     // Transfer statistics (payload only, no protocol overhead)
     long downloaded = peer.totalDownload();  // Bytes from this peer
     long uploaded = peer.totalUpload();      // Bytes to this peer

     // Current speeds (updated ~1x per second)
     int downBps = peer.downSpeed();  // Bytes per second
     int upBps = peer.upSpeed();      // Bytes per second

     // Progress: how much of the torrent does this peer have?
     float progress = peer.progress();  // 0.0 to 1.0
     float progressPpm = peer.progressPpm();  // Parts per million (more precise)
     System.out.println("Peer has " + (progress * 100) + "% of torrent");

     // Peer identification
     String ip = peer.ip();           // IP address:port
     String client = peer.client();   // Client software version
     System.out.println(ip + " running " + client);
 }
 

Peer Connection Information:

 for (PeerInfo peer : peers) {
     // Connection state flags
     int flags = peer.flags();
     // Flags indicate: chocking state, optimistic unchoke, snubbed, etc.

     // Where did we learn about this peer?
     byte source = peer.source();
     // Bit flags: DHT, PEX (peer exchange), tracker, etc.

     // Connection type
     ConnectionType type = peer.connectionType();
     System.out.println("Connection: " + type);  // e.g., STANDARD_BEP
 }
 

Analyzing Peer Performance:

 // Find fastest peers
 List<PeerInfo> peers = th.peerInfo();

 // Sort by download speed
 List<PeerInfo> fastestPeers = peers.stream()
     .sorted((a, b) -> Integer.compare(b.downSpeed(), a.downSpeed()))
     .limit(5)
     .collect(Collectors.toList());

 System.out.println("Top 5 fastest peers:");
 for (PeerInfo peer : fastestPeers) {
     System.out.println("  " + peer.ip() + " @ " +
         (peer.downSpeed() / 1024 / 1024) + " MB/s");
 }

 // Find peers with most progress
 List<PeerInfo> completePeers = peers.stream()
     .filter(p -> p.progress() > 0.99)  // 99%+ complete
     .collect(Collectors.toList());

 System.out.println("Seeders (complete): " + completePeers.size());
 

Peer Quality Assessment:

 for (PeerInfo peer : peers) {
     // Assess peer quality
     int downBps = peer.downSpeed();
     float progress = peer.progress();
     long totalDownloaded = peer.totalDownload();

     // Peers that have sent us data are valuable
     boolean useful = totalDownloaded > 0;

     // Complete peers (seeders) are especially valuable
     boolean isSeeder = progress > 0.99;

     // Fast peers should be prioritized
     boolean isFast = downBps > (1024 * 100);  // > 100 KB/s

     if (isSeeder && isFast) {
         System.out.println("Premium seeder: " + peer.ip());
     }
 }
 

Performance Notes: - TorrentHandle.peerInfo() is a synchronous call (may block slightly) - Call infrequently or cache results if performance is critical - Updated approximately once per second by libtorrent - For efficient batch updates, use SessionManager.postTorrentUpdates()

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The kind of connection this is.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
     
     
    protected int
     
    protected int
     
    protected String
     
    protected float
     
    protected int
     
    protected byte
     
    protected long
     
    protected long
     
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PeerInfo(com.frostwire.jlibtorrent.swig.peer_info p)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    This describes the software at the other end of the connection.
    The kind of connection this peer uses.
    int
    The current download speed we have to and from this peer (including any protocol messages).
    int
    Tells you in which state the peer is in.
    protected void
    init(com.frostwire.jlibtorrent.swig.peer_info p)
    NOTE: use this with care and only if necessary.
    ip()
    The IP-address to this peer.
    float
    The progress of the peer in the range [0, 1].
    int
    Indicates the download progress of the peer in the range [0, 1000000] (parts per million).
    byte
    A combination of flags describing from which sources this peer was received.
    long
    The total number of bytes downloaded from this peer.
    long
    The total number of bytes uploaded to this peer.
    int
    The current upload speed we have to and from this peer (including any protocol messages).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • client

      protected String client
    • totalDownload

      protected long totalDownload
    • totalUpload

      protected long totalUpload
    • flags

      protected int flags
    • source

      protected byte source
    • upSpeed

      protected int upSpeed
    • downSpeed

      protected int downSpeed
    • connectionType

      protected PeerInfo.ConnectionType connectionType
    • progress

      protected float progress
    • progressPpm

      protected int progressPpm
    • ip

      protected String ip
  • Constructor Details

    • PeerInfo

      public PeerInfo(com.frostwire.jlibtorrent.swig.peer_info p)
  • Method Details

    • client

      public String client()
      This describes the software at the other end of the connection. In some cases this information is not available, then it will contain a string that may give away something about which software is running in the other end. In the case of a web seed, the server type and version will be a part of this string.
      Returns:
      the client string
    • totalDownload

      public long totalDownload()
      The total number of bytes downloaded from this peer. These numbers do not include the protocol chatter, but only the payload data.
      Returns:
      number of bytes downloaded
    • totalUpload

      public long totalUpload()
      The total number of bytes uploaded to this peer. These numbers do not include the protocol chatter, but only the payload data.
      Returns:
      number of bytes uploaded
    • flags

      public int flags()
      Tells you in which state the peer is in. It is set to any combination of the peer_flags_t flags.
      Returns:
      the flags as an integer
    • source

      public byte source()
      A combination of flags describing from which sources this peer was received. A combination of the peer_source_flags_t flags.
      Returns:
      the flags as a byte
    • upSpeed

      public int upSpeed()
      The current upload speed we have to and from this peer (including any protocol messages). Updated about once per second
      Returns:
      current upload speed we have to and from this peer
    • downSpeed

      public int downSpeed()
      The current download speed we have to and from this peer (including any protocol messages). Updated about once per second
      Returns:
      current download speed we have to and from this peer
    • connectionType

      public PeerInfo.ConnectionType connectionType()
      The kind of connection this peer uses.
      Returns:
      the connection type
    • progress

      public float progress()
      The progress of the peer in the range [0, 1]. This is always 0 when floating point operations are disabled, instead use ``progress_ppm``.
      Returns:
      the progress of the peer in the range [0, 1]
    • progressPpm

      public int progressPpm()
      Indicates the download progress of the peer in the range [0, 1000000] (parts per million).
      Returns:
      the download progress of the peer in the range [0, 1000000]
    • ip

      public String ip()
      The IP-address to this peer.
      Returns:
      a string representing the endpoint.
    • init

      protected void init(com.frostwire.jlibtorrent.swig.peer_info p)
      NOTE: use this with care and only if necessary.
      Parameters:
      p - the native object