| 454 | } |
| 455 | |
| 456 | static struct blinded_path *make_reply_path(const tal_t *ctx, |
| 457 | struct plugin *plugin, |
| 458 | const struct sent *sent, |
| 459 | const struct pubkey *path, |
| 460 | struct secret *reply_secret) |
| 461 | { |
| 462 | struct pubkey *ids; |
| 463 | |
| 464 | assert(tal_count(path) > 0); |
| 465 | |
| 466 | randbytes(reply_secret, sizeof(struct secret)); |
| 467 | |
| 468 | if (sent->dev_reply_path) { |
| 469 | ids = sent->dev_reply_path; |
| 470 | } else if (tal_count(path) == 1) { |
| 471 | /* Talking to ourselves? Reverse is the same */ |
| 472 | ids = tal_dup_talarr(tmpctx, struct pubkey, path); |
| 473 | } else { |
| 474 | size_t nhops = tal_count(path), start; |
| 475 | struct node_id second_last; |
| 476 | |
| 477 | /* Usually we have path A->B->C and we make |
| 478 | * reply B->A. But if B is not public, |
| 479 | * we need to use the full thing. |
| 480 | * |
| 481 | * This happens when we connect directly to the |
| 482 | * head of a blinded path, but we're not a public |
| 483 | * node. |
| 484 | */ |
| 485 | node_id_from_pubkey(&second_last, &path[nhops-2]); |
| 486 | if (!gossmap_find_node(get_gossmap(plugin), &second_last)) |
| 487 | start = nhops - 1; |
| 488 | else |
| 489 | start = nhops - 2; |
| 490 | |
| 491 | /* FIXME: Could create an independent reply path, not just |
| 492 | * reverse existing. */ |
| 493 | ids = tal_arr(tmpctx, struct pubkey, start + 1); |
| 494 | for (int i = start; i >= 0; i--) |
| 495 | ids[start - i] = path[i]; |
| 496 | } |
| 497 | |
| 498 | plugin_log(plugin, LOG_DBG, "Reply path:"); |
| 499 | for (size_t i = 0; i < tal_count(ids); i++) |
| 500 | plugin_log(plugin, LOG_DBG, "...%s", fmt_pubkey(tmpctx, &ids[i])); |
| 501 | |
| 502 | /* Reply path */ |
| 503 | return incoming_message_blinded_path(ctx, ids, NULL, reply_secret); |
| 504 | } |
| 505 | |
| 506 | /* Container while we're establishing paths */ |
| 507 | struct establishing_paths { |
no test coverage detected