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

Function gossmods_from_listpeers

plugins/establish_onion_path.c:114–165  ·  view source on GitHub ↗

We add fake channels to gossmap to represent current outgoing connections. * This allows dijkstra to find transient connections as well. */

Source from the content-addressed store, hash-verified

112/* We add fake channels to gossmap to represent current outgoing connections.
113 * This allows dijkstra to find transient connections as well. */
114static struct gossmap_localmods *
115gossmods_from_listpeers(const tal_t *ctx,
116 struct plugin *plugin,
117 const struct gossmap *gossmap,
118 const struct node_id *self,
119 const char *buf,
120 const jsmntok_t *toks)
121{
122 struct gossmap_localmods *mods = gossmap_localmods_new(ctx);
123 const jsmntok_t *peers, *peer;
124 size_t i;
125
126 peers = json_get_member(buf, toks, "peers");
127 json_for_each_arr(i, peer, peers) {
128 bool connected;
129 struct node_id peer_id;
130 const char *err;
131 u8 *features = NULL;
132 struct short_channel_id_dir fake_scidd;
133 bool enabled = true;
134
135 err = json_scan(tmpctx, buf, peer,
136 "{connected:%,"
137 "id:%,"
138 "features?:%}",
139 JSON_SCAN(json_to_bool, &connected),
140 JSON_SCAN(json_to_node_id, &peer_id),
141 JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &features));
142 if (err) {
143 plugin_err(plugin, "Bad listpeers.peers %zu: %s", i, err);
144 }
145
146 if (!feature_offered(features, OPT_ONION_MESSAGES))
147 continue;
148
149 if (!connected) {
150 /* Discard any channels we have with that. */
151 local_mods_remove_channels(mods, gossmap, self, &peer_id);
152 continue;
153 }
154
155 /* Add a fake channel */
156 fake_scidd.scid.u64 = i;
157 fake_scidd.dir = node_id_idx(self, &peer_id);
158
159 gossmap_local_addchan(mods, self, &peer_id, fake_scidd.scid,
160 AMOUNT_MSAT(1000), NULL);
161 gossmap_local_updatechan(mods, &fake_scidd, &enabled,
162 NULL, NULL, NULL, NULL, NULL);
163 }
164 return mods;
165}
166
167static const struct pubkey *path_to_node(const tal_t *ctx,
168 struct command *cmd,

Callers 1

path_to_nodeFunction · 0.85

Calls 9

gossmap_localmods_newFunction · 0.85
json_get_memberFunction · 0.85
feature_offeredFunction · 0.85
node_id_idxFunction · 0.85
gossmap_local_addchanFunction · 0.85
gossmap_local_updatechanFunction · 0.85
plugin_errFunction · 0.70
json_scanFunction · 0.50

Tested by

no test coverage detected