Skip to content

Commit

Permalink
Added peer info in torrent stat
Browse files Browse the repository at this point in the history
  • Loading branch information
glblduh committed May 25, 2022
1 parent 67964c9 commit eeb784b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ func apiTorrentStats(w http.ResponseWriter, r *http.Request) {
tstats.UploadSpeed = v.UlSpeedReadable
tstats.Progress = calcTorrentProgress(v.Torrent)

/* Setting the peers info */
for _, peer := range v.Torrent.PeerConns() {
tstats.Peers = append(tstats.Peers, apiTorrentStatsPeersInfo{
PeerAddr: peer.Peer.RemoteAddr.String(),
PeerClient: peer.Peer.PeerClientName.Load().(string),
})
}

/* Setting the files available in the torrent */
for _, tf := range v.Torrent.Files() {
tfname := tf.DisplayPath()
Expand Down
6 changes: 6 additions & 0 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type (
ActivePeers int `json:"activepeers"`
PendingPeers int `json:"pendingpeers"`
HalfOpenPeers int `json:"halfopenpeers"`
Peers []apiTorrentStatsPeersInfo `json:"peers"`
DownloadSpeed string `json:"downloadspeed"`
UploadSpeed string `json:"uploadspeed"`
Progress string `json:"progress"`
Expand All @@ -164,4 +165,9 @@ type (
Stream string `json:"stream,omitempty"`
Download string `json:"download,omitempty"`
}

apiTorrentStatsPeersInfo struct {
PeerAddr string `json:"peeraddr"`
PeerClient string `json:"peercli"`
}
)

0 comments on commit eeb784b

Please sign in to comment.