github.com/anacrolix/torrent@v1.61.0/torrent-stats.go (about)

     1  package torrent
     2  
     3  import (
     4  	"reflect"
     5  )
     6  
     7  // Due to ConnStats, may require special alignment on some platforms. See
     8  // https://github.com/anacrolix/torrent/issues/383.
     9  type TorrentStats struct {
    10  	AllConnStats
    11  	TorrentStatCounters
    12  	TorrentGauges
    13  }
    14  
    15  type AllConnStats struct {
    16  	// Aggregates stats over all connections past and present. Some values may not have much meaning
    17  	// in the aggregate context.
    18  	ConnStats
    19  	WebSeeds  ConnStats
    20  	PeerConns ConnStats
    21  }
    22  
    23  func (me *AllConnStats) Copy() (ret AllConnStats) {
    24  	ret.ConnStats = me.ConnStats.Copy()
    25  	ret.WebSeeds = me.WebSeeds.Copy()
    26  	ret.PeerConns = me.PeerConns.Copy()
    27  	return
    28  }
    29  
    30  // Instantaneous metrics in Torrents, and aggregated for Clients.
    31  type TorrentGauges struct {
    32  	// Ordered by expected descending quantities (if all is well).
    33  	TotalPeers       int
    34  	PendingPeers     int
    35  	ActivePeers      int
    36  	ConnectedSeeders int
    37  	HalfOpenPeers    int
    38  	PiecesComplete   int
    39  }
    40  
    41  func (me *TorrentGauges) Add(agg TorrentGauges) {
    42  	src := reflect.ValueOf(agg)
    43  	dst := reflect.ValueOf(me).Elem()
    44  	for i := 0; i < reflect.TypeFor[TorrentGauges]().NumField(); i++ {
    45  		*dst.Field(i).Addr().Interface().(*int) += src.Field(i).Interface().(int)
    46  	}
    47  }
    48  
    49  type TorrentStatCounters struct {
    50  	BytesHashed Count
    51  }