| 165 | } |
| 166 | |
| 167 | static const struct pubkey *path_to_node(const tal_t *ctx, |
| 168 | struct command *cmd, |
| 169 | struct gossmap *gossmap, |
| 170 | struct plugin *plugin, |
| 171 | const char *buf, |
| 172 | const jsmntok_t *listpeers, |
| 173 | const struct pubkey *local_id, |
| 174 | const struct pubkey *dst_key) |
| 175 | { |
| 176 | struct route_hop *r; |
| 177 | const struct dijkstra *dij; |
| 178 | const struct gossmap_node *src; |
| 179 | const struct gossmap_node *dst; |
| 180 | struct pubkey *nodes; |
| 181 | struct gossmap_localmods *mods; |
| 182 | struct node_id local_nodeid, dst_nodeid; |
| 183 | |
| 184 | node_id_from_pubkey(&local_nodeid, local_id); |
| 185 | node_id_from_pubkey(&dst_nodeid, dst_key); |
| 186 | mods = gossmods_from_listpeers(tmpctx, cmd->plugin, gossmap, &local_nodeid, buf, listpeers); |
| 187 | |
| 188 | gossmap_apply_localmods(gossmap, mods); |
| 189 | dst = gossmap_find_node(gossmap, &dst_nodeid); |
| 190 | if (!dst) |
| 191 | goto fail; |
| 192 | |
| 193 | /* If we don't exist in gossip, routing can't happen. */ |
| 194 | src = gossmap_find_node(gossmap, &local_nodeid); |
| 195 | if (!src) |
| 196 | goto fail; |
| 197 | |
| 198 | dij = dijkstra(tmpctx, gossmap, dst, AMOUNT_MSAT(0), 0, |
| 199 | can_carry_onionmsg, route_score_shorter, NULL); |
| 200 | |
| 201 | r = route_from_dijkstra(tmpctx, gossmap, dij, src, AMOUNT_MSAT(0), 0); |
| 202 | if (!r) |
| 203 | goto fail; |
| 204 | |
| 205 | nodes = tal_arr(ctx, struct pubkey, tal_count(r) + 1); |
| 206 | nodes[0] = *local_id; |
| 207 | plugin_log(plugin, LOG_DBG, "Found path to %s: %s(us)", |
| 208 | fmt_node_id(tmpctx, &dst_nodeid), |
| 209 | fmt_pubkey(tmpctx, local_id)); |
| 210 | for (size_t i = 0; i < tal_count(r); i++) { |
| 211 | if (!pubkey_from_node_id(&nodes[i+1], &r[i].node_id)) { |
| 212 | plugin_err(plugin, "Could not convert nodeid %s", |
| 213 | fmt_node_id(tmpctx, &r[i].node_id)); |
| 214 | } |
| 215 | plugin_log(plugin, LOG_DBG, "-> %s", |
| 216 | fmt_node_id(tmpctx, &r[i].node_id)); |
| 217 | } |
| 218 | |
| 219 | gossmap_remove_localmods(gossmap, mods); |
| 220 | return nodes; |
| 221 | |
| 222 | fail: |
| 223 | gossmap_remove_localmods(gossmap, mods); |
| 224 | return NULL; |
no test coverage detected