mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
sphinx: Add function to add a new v0 hop to a sphinx_path
This is just taking the existing serialization code and repackaging it in a more useful form. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
71cf4e1b39
commit
a0a1a1f752
@@ -3,6 +3,7 @@
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/sphinx.h>
|
||||
#include <common/utils.h>
|
||||
#include <err.h>
|
||||
@@ -19,11 +20,15 @@ static void do_generate(int argc, char **argv,
|
||||
int num_hops = argc - 1;
|
||||
struct pubkey *path = tal_arr(ctx, struct pubkey, num_hops);
|
||||
u8 privkeys[argc - 1][32];
|
||||
u8 sessionkey[32];
|
||||
struct secret session_key;
|
||||
struct hop_data hops_data[num_hops];
|
||||
struct secret *shared_secrets;
|
||||
struct sphinx_path *sp;
|
||||
|
||||
memset(&sessionkey, 'A', sizeof(sessionkey));
|
||||
assocdata = tal_arr(ctx, u8, 32);
|
||||
memset(&session_key, 'A', sizeof(struct secret));
|
||||
|
||||
sp = sphinx_path_new_with_key(ctx, assocdata, &session_key);
|
||||
|
||||
for (int i = 0; i < num_hops; i++) {
|
||||
size_t klen = strcspn(argv[1 + i], "/");
|
||||
@@ -33,8 +38,9 @@ static void do_generate(int argc, char **argv,
|
||||
if (secp256k1_ec_pubkey_create(secp256k1_ctx, &path[i].pubkey,
|
||||
privkeys[i]) != 1)
|
||||
errx(1, "Could not decode pubkey");
|
||||
printf("# Node %d pubkey %s\n",
|
||||
i, secp256k1_pubkey_to_hexstr(ctx, &path[i].pubkey));
|
||||
fprintf(stderr, "Node %d pubkey %s\n", i,
|
||||
secp256k1_pubkey_to_hexstr(ctx, &path[i].pubkey));
|
||||
|
||||
memset(&hops_data[i], 0, sizeof(hops_data[i]));
|
||||
if (argv[1 + i][klen] != '\0') {
|
||||
/* FIXME: Generic realm support, not this hack! */
|
||||
@@ -76,11 +82,12 @@ static void do_generate(int argc, char **argv,
|
||||
hops_data[i].amt_forward.millisatoshis = i; /* Raw: test code */
|
||||
hops_data[i].outgoing_cltv = i;
|
||||
}
|
||||
fprintf(stderr, "Hopdata %d: %s\n", i, tal_hexstr(NULL, &hops_data[i], sizeof(hops_data[i])));
|
||||
sphinx_add_v0_hop(sp, &path[i], &hops_data[i].channel_id, hops_data[i].amt_forward, i);
|
||||
}
|
||||
|
||||
struct onionpacket *res =
|
||||
create_onionpacket(ctx, path, hops_data, sessionkey,
|
||||
assocdata, ASSOC_DATA_SIZE, &shared_secrets);
|
||||
create_onionpacket(ctx, sp, &shared_secrets);
|
||||
|
||||
u8 *serialized = serialize_onionpacket(ctx, res);
|
||||
if (!serialized)
|
||||
|
||||
Reference in New Issue
Block a user