| 2583 | } |
| 2584 | |
| 2585 | static void json_add_peer(struct lightningd *ld, |
| 2586 | struct json_stream *response, |
| 2587 | struct peer *p, |
| 2588 | const enum log_level *ll) |
| 2589 | { |
| 2590 | struct channel *channel; |
| 2591 | u32 num_channels; |
| 2592 | |
| 2593 | json_object_start(response, NULL); |
| 2594 | json_add_node_id(response, "id", &p->id); |
| 2595 | |
| 2596 | json_add_bool(response, "connected", p->connected == PEER_CONNECTED); |
| 2597 | num_channels = 0; |
| 2598 | list_for_each(&p->channels, channel, list) |
| 2599 | num_channels++; |
| 2600 | json_add_num(response, "num_channels", num_channels); |
| 2601 | |
| 2602 | if (p->connected == PEER_CONNECTED) { |
| 2603 | json_array_start(response, "netaddr"); |
| 2604 | json_add_string(response, NULL, |
| 2605 | fmt_wireaddr_internal(tmpctx, &p->addr)); |
| 2606 | json_array_end(response); |
| 2607 | /* If peer reports our IP remote_addr, add that here */ |
| 2608 | if (p->remote_addr) |
| 2609 | json_add_string(response, "remote_addr", |
| 2610 | fmt_wireaddr(tmpctx, p->remote_addr)); |
| 2611 | } |
| 2612 | |
| 2613 | /* Note: If !PEER_CONNECTED, peer may use different features on reconnect */ |
| 2614 | json_add_hex_talarr(response, "features", p->their_features); |
| 2615 | |
| 2616 | if (ll) |
| 2617 | json_add_log(response, ld->log_book, &p->id, *ll); |
| 2618 | json_object_end(response); |
| 2619 | } |
| 2620 | |
| 2621 | static struct command_result *json_listpeers(struct command *cmd, |
| 2622 | const char *buffer, |
no test coverage detected