MCPcopy Create free account
hub / github.com/ElementsProject/lightning / local_connected

Function local_connected

plugins/topology.c:299–345  ·  view source on GitHub ↗

We record which local channels are valid; we could record which are * invalid, but our testsuite has some weirdness where it has local * channels in the store it knows nothing about. */

Source from the content-addressed store, hash-verified

297 * invalid, but our testsuite has some weirdness where it has local
298 * channels in the store it knows nothing about. */
299static struct node_map *local_connected(const tal_t *ctx,
300 const char *buf,
301 const jsmntok_t *result)
302{
303 size_t i;
304 const jsmntok_t *t, *peers = json_get_member(buf, result, "peers");
305 struct node_map *connected = tal(ctx, struct node_map);
306
307 node_map_init(connected);
308
309 json_for_each_arr(i, t, peers) {
310 const jsmntok_t *chans, *c;
311 struct node_id id;
312 bool is_connected, normal_chan;
313 const char *err;
314 size_t j;
315
316 err = json_scan(tmpctx, buf, t,
317 "{id:%,connected:%}",
318 JSON_SCAN(json_to_node_id, &id),
319 JSON_SCAN(json_to_bool, &is_connected));
320 if (err)
321 plugin_err(plugin, "Bad listpeers response (%s): %.*s",
322 err,
323 json_tok_full_len(result),
324 json_tok_full(buf, result));
325
326 if (!is_connected)
327 continue;
328
329 /* Must also have a channel in CHANNELD_NORMAL */
330 normal_chan = false;
331 chans = json_get_member(buf, t, "channels");
332 json_for_each_arr(j, c, chans) {
333 if (json_tok_streq(buf,
334 json_get_member(buf, c, "state"),
335 "CHANNELD_NORMAL"))
336 normal_chan = true;
337 }
338
339 if (normal_chan)
340 node_map_add(connected,
341 tal_dup(connected, struct node_id, &id));
342 }
343
344 return connected;
345}
346
347/* We want to combine local knowledge to we know which are actually inactive! */
348static struct command_result *listpeers_done(struct command *cmd,

Callers 1

listpeers_doneFunction · 0.85

Calls 6

plugin_errFunction · 0.70
json_get_memberFunction · 0.50
json_scanFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50
json_tok_streqFunction · 0.50

Tested by

no test coverage detected