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

Function uniquify_node_ids

connectd/queries.c:85–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85static void uniquify_node_ids(struct node_id **ids)
86{
87 size_t dst, src;
88
89 /* BOLT #7:
90 * - SHOULD avoid sending duplicate `node_announcements` in
91 * response to a single `query_short_channel_ids`.
92 */
93 /* ccan/asort is a typesafe qsort wrapper: like most ccan modules
94 * it eschews exposing 'void *' pointers and ensures that the
95 * callback function and its arguments match types correctly. */
96 asort(*ids, tal_count(*ids), pubkey_order, NULL);
97
98 /* Compact the array */
99 for (dst = 0, src = 0; src < tal_count(*ids); src++) {
100 if (dst && node_id_eq(&(*ids)[dst-1], &(*ids)[src]))
101 continue;
102 (*ids)[dst++] = (*ids)[src];
103 }
104
105 /* And trim to length, so tal_count() gives correct answer. */
106 tal_resize(ids, dst);
107}
108
109/* We are fairly careful to avoid the peer DoSing us with channel queries:
110 * this routine creates messages about a single short_channel_id, unless

Callers 1

Calls 1

node_id_eqFunction · 0.85

Tested by

no test coverage detected