| 2857 | } |
| 2858 | |
| 2859 | static void json_add_peer(struct lightningd *ld, |
| 2860 | struct json_stream *response, |
| 2861 | struct peer *p, |
| 2862 | const enum log_level *ll) |
| 2863 | { |
| 2864 | struct channel *channel; |
| 2865 | u32 num_channels; |
| 2866 | |
| 2867 | json_object_start(response, NULL); |
| 2868 | json_add_node_id(response, "id", &p->id); |
| 2869 | |
| 2870 | json_add_bool(response, "connected", p->connected == PEER_CONNECTED); |
| 2871 | num_channels = 0; |
| 2872 | list_for_each(&p->channels, channel, list) |
| 2873 | num_channels++; |
| 2874 | json_add_num(response, "num_channels", num_channels); |
| 2875 | |
| 2876 | if (p->connected == PEER_CONNECTED) { |
| 2877 | json_array_start(response, "netaddr"); |
| 2878 | json_add_string(response, NULL, |
| 2879 | fmt_wireaddr_internal(tmpctx, &p->addr)); |
| 2880 | json_array_end(response); |
| 2881 | /* If peer reports our IP remote_addr, add that here */ |
| 2882 | if (p->remote_addr) |
| 2883 | json_add_string(response, "remote_addr", |
| 2884 | fmt_wireaddr(tmpctx, p->remote_addr)); |
| 2885 | } |
| 2886 | |
| 2887 | /* Note: If !PEER_CONNECTED, peer may use different features on reconnect */ |
| 2888 | json_add_hex_talarr(response, "features", p->their_features); |
| 2889 | |
| 2890 | if (ll) |
| 2891 | json_add_log(response, ld->log_book, &p->id, *ll); |
| 2892 | json_object_end(response); |
| 2893 | } |
| 2894 | |
| 2895 | static struct command_result *json_listpeers(struct command *cmd, |
| 2896 | const char *buffer, |
no test coverage detected