Expose peer and piece state to web UI
This commit is contained in:
parent
f4f4e86be4
commit
6ae72907b0
6 changed files with 213 additions and 11 deletions
|
|
@ -213,6 +213,16 @@ static json_t *torrent_json(torrent_task *task) {
|
|||
json_integer(task->stats.pieces_done));
|
||||
json_object_set_new(result, "total_pieces",
|
||||
json_integer(task->stats.total_pieces));
|
||||
json_t *piece_states = json_array();
|
||||
if (piece_states) {
|
||||
uint32_t state_count = task->stats.piece_state_count;
|
||||
if (state_count > NAUT_SWARM_MAX_PIECE_STATS)
|
||||
state_count = NAUT_SWARM_MAX_PIECE_STATS;
|
||||
for (uint32_t i = 0; i < state_count; i++)
|
||||
json_array_append_new(piece_states,
|
||||
json_integer(task->stats.piece_states[i]));
|
||||
json_object_set_new(result, "piece_states", piece_states);
|
||||
}
|
||||
json_object_set_new(result, "peers",
|
||||
json_integer(task->stats.peers_active));
|
||||
json_object_set_new(result, "peers_discovered",
|
||||
|
|
@ -221,6 +231,31 @@ static json_t *torrent_json(torrent_task *task) {
|
|||
json_integer(task->stats.peers_connecting));
|
||||
json_object_set_new(result, "peers_failed",
|
||||
json_integer(task->stats.peers_failed));
|
||||
json_t *peer_list = json_array();
|
||||
if (peer_list) {
|
||||
uint32_t peer_count = task->stats.peer_count;
|
||||
if (peer_count > NAUT_SWARM_MAX_PEER_STATS)
|
||||
peer_count = NAUT_SWARM_MAX_PEER_STATS;
|
||||
for (uint32_t i = 0; i < peer_count; i++) {
|
||||
const naut_swarm_peer_stats *peer =
|
||||
&task->stats.peer_stats[i];
|
||||
json_t *item = json_pack(
|
||||
"{s:s,s:i,s:s,s:s,s:s,s:f,s:f,s:I,s:I,s:I,s:I}",
|
||||
"ip", peer->ip,
|
||||
"port", (int)peer->port,
|
||||
"client", peer->client,
|
||||
"connection", peer->connection,
|
||||
"flags", peer->flags,
|
||||
"progress", peer->progress,
|
||||
"relevance", peer->relevance,
|
||||
"downloaded", (json_int_t)peer->downloaded,
|
||||
"uploaded", (json_int_t)peer->uploaded,
|
||||
"dlspeed", (json_int_t)peer->dlspeed,
|
||||
"upspeed", (json_int_t)peer->upspeed);
|
||||
if (item) json_array_append_new(peer_list, item);
|
||||
}
|
||||
json_object_set_new(result, "peer_list", peer_list);
|
||||
}
|
||||
json_object_set_new(result, "elapsed_seconds",
|
||||
json_real(task->stats.elapsed_seconds));
|
||||
json_object_set_new(result, "pending_moves",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue