| 2224 | AUTODATA(json_command, &disconnect_command); |
| 2225 | |
| 2226 | static struct command_result *json_getinfo(struct command *cmd, |
| 2227 | const char *buffer, |
| 2228 | const jsmntok_t *obj UNNEEDED, |
| 2229 | const jsmntok_t *params) |
| 2230 | { |
| 2231 | struct json_stream *response; |
| 2232 | struct peer *peer; |
| 2233 | struct channel *channel; |
| 2234 | unsigned int pending_channels = 0, active_channels = 0, |
| 2235 | inactive_channels = 0, num_peers = 0; |
| 2236 | size_t count_announceable; |
| 2237 | |
| 2238 | if (!param(cmd, buffer, params, NULL)) |
| 2239 | return command_param_failed(); |
| 2240 | |
| 2241 | response = json_stream_success(cmd); |
| 2242 | json_add_node_id(response, "id", &cmd->ld->id); |
| 2243 | json_add_string(response, "alias", (const char *)cmd->ld->alias); |
| 2244 | json_add_hex_talarr(response, "color", cmd->ld->rgb); |
| 2245 | |
| 2246 | /* Add some peer and channel stats */ |
| 2247 | list_for_each(&cmd->ld->peers, peer, list) { |
| 2248 | num_peers++; |
| 2249 | |
| 2250 | list_for_each(&peer->channels, channel, list) { |
| 2251 | if (channel->state == CHANNELD_AWAITING_LOCKIN |
| 2252 | || channel->state == DUALOPEND_AWAITING_LOCKIN |
| 2253 | || channel->state == DUALOPEND_OPEN_INIT) { |
| 2254 | pending_channels++; |
| 2255 | } else if (channel_active(channel)) { |
| 2256 | active_channels++; |
| 2257 | } else { |
| 2258 | inactive_channels++; |
| 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | json_add_num(response, "num_peers", num_peers); |
| 2263 | json_add_num(response, "num_pending_channels", pending_channels); |
| 2264 | json_add_num(response, "num_active_channels", active_channels); |
| 2265 | json_add_num(response, "num_inactive_channels", inactive_channels); |
| 2266 | |
| 2267 | /* Add network info */ |
| 2268 | if (cmd->ld->listen) { |
| 2269 | /* These are the addresses we're announcing */ |
| 2270 | count_announceable = tal_count(cmd->ld->announceable); |
| 2271 | json_array_start(response, "address"); |
| 2272 | for (size_t i = 0; i < count_announceable; i++) |
| 2273 | json_add_address(response, NULL, cmd->ld->announceable+i); |
| 2274 | |
| 2275 | /* Currently, IP discovery will only be announced by gossipd, |
| 2276 | * if we don't already have usable addresses. |
| 2277 | * See `create_node_announcement` in `gossip_generation.c`. */ |
| 2278 | if (count_announceable == 0) { |
| 2279 | if (cmd->ld->discovered_ip_v4 != NULL && |
| 2280 | !wireaddr_arr_contains( |
| 2281 | cmd->ld->announceable, |
| 2282 | cmd->ld->discovered_ip_v4)) |
| 2283 | json_add_address(response, NULL, |
nothing calls this directly
no test coverage detected