| 495 | } |
| 496 | |
| 497 | static struct blinded_path *make_reply_path(const tal_t *ctx, |
| 498 | struct plugin *plugin, |
| 499 | const struct sent *sent, |
| 500 | const struct pubkey *path, |
| 501 | struct secret *reply_secret) |
| 502 | { |
| 503 | struct pubkey *ids; |
| 504 | |
| 505 | assert(tal_count(path) > 0); |
| 506 | |
| 507 | randbytes(reply_secret, sizeof(struct secret)); |
| 508 | |
| 509 | if (sent->dev_reply_path) { |
| 510 | ids = sent->dev_reply_path; |
| 511 | } else if (tal_count(path) == 1) { |
| 512 | /* Talking to ourselves? Reverse is the same */ |
| 513 | ids = tal_dup_talarr(tmpctx, struct pubkey, path); |
| 514 | } else { |
| 515 | size_t nhops = tal_count(path), start; |
| 516 | struct node_id second_last; |
| 517 | |
| 518 | /* Usually we have path A->B->C and we make |
| 519 | * reply B->A. But if B is not public, |
| 520 | * we need to use the full thing. |
| 521 | * |
| 522 | * This happens when we connect directly to the |
| 523 | * head of a blinded path, but we're not a public |
| 524 | * node. |
| 525 | */ |
| 526 | node_id_from_pubkey(&second_last, &path[nhops-2]); |
| 527 | if (!gossmap_find_node(get_gossmap(plugin), &second_last)) |
| 528 | start = nhops - 1; |
| 529 | else |
| 530 | start = nhops - 2; |
| 531 | |
| 532 | /* FIXME: Could create an independent reply path, not just |
| 533 | * reverse existing. */ |
| 534 | ids = tal_arr(tmpctx, struct pubkey, start + 1); |
| 535 | for (int i = start; i >= 0; i--) |
| 536 | ids[start - i] = path[i]; |
| 537 | } |
| 538 | |
| 539 | plugin_log(plugin, LOG_DBG, "Reply path:"); |
| 540 | for (size_t i = 0; i < tal_count(ids); i++) |
| 541 | plugin_log(plugin, LOG_DBG, "...%s", fmt_pubkey(tmpctx, &ids[i])); |
| 542 | |
| 543 | /* Reply path */ |
| 544 | return incoming_message_blinded_path(ctx, ids, NULL, reply_secret); |
| 545 | } |
| 546 | |
| 547 | /* Container while we're establishing paths */ |
| 548 | struct establishing_paths { |
no test coverage detected