Skip to content

Commit

Permalink
devtools/onion: change defile assocdata to empty.
Browse files Browse the repository at this point in the history
This is in preparation for messages, which want this as their assocdata.

Plus, it's a bit cleaner rather than creating a tmp tal array.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Mar 17, 2020
1 parent 43a46e2 commit f541044
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions devtools/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#include <string.h>
#include <unistd.h>

#define ASSOC_DATA_SIZE 32

static void do_generate(int argc, char **argv,
const u8 assocdata[ASSOC_DATA_SIZE],
const u8 *assocdata,
const struct node_id *rvnode_id)
{
const tal_t *ctx = talz(NULL, tal_t);
Expand All @@ -35,11 +33,10 @@ static void do_generate(int argc, char **argv,
struct sphinx_compressed_onion *comp;
u8 *serialized;
struct onionpacket *packet;
const u8* tmp_assocdata =tal_dup_arr(ctx, u8, assocdata,
ASSOC_DATA_SIZE, 0);

memset(&session_key, 'A', sizeof(struct secret));

sp = sphinx_path_new_with_key(ctx, tmp_assocdata, &session_key);
sp = sphinx_path_new_with_key(ctx, assocdata, &session_key);
sphinx_path_set_rendezvous(sp, rvnode_id);

for (int i = 0; i < num_hops; i++) {
Expand Down Expand Up @@ -136,7 +133,7 @@ static struct route_step *decode_with_privkey(const tal_t *ctx, const u8 *onion,

}

static void do_decode(int argc, char **argv, const u8 assocdata[ASSOC_DATA_SIZE])
static void do_decode(int argc, char **argv, const u8 *assocdata)
{
const tal_t *ctx = talz(NULL, tal_t);
u8 serialized[TOTAL_PACKET_SIZE];
Expand All @@ -157,9 +154,7 @@ static void do_decode(int argc, char **argv, const u8 assocdata[ASSOC_DATA_SIZE]
errx(1, "Invalid onion hex '%s'", hextemp);
}

const u8* tmp_assocdata =tal_dup_arr(ctx, u8, assocdata,
ASSOC_DATA_SIZE, 0);
step = decode_with_privkey(ctx, serialized, tal_strdup(ctx, argv[3]), tmp_assocdata);
step = decode_with_privkey(ctx, serialized, tal_strdup(ctx, argv[3]), assocdata);

if (!step || !step->next)
errx(1, "Error processing message.");
Expand All @@ -174,16 +169,17 @@ static void do_decode(int argc, char **argv, const u8 assocdata[ASSOC_DATA_SIZE]
tal_free(ctx);
}

static char *opt_set_ad(const char *arg, u8 *assocdata)
static char *opt_set_ad(const char *arg, u8 **assocdata)
{
if (!hex_decode(arg, strlen(arg), assocdata, ASSOC_DATA_SIZE))
*assocdata = tal_hexdata(NULL, arg, strlen(arg));
if (!*assocdata)
return "Bad hex string";
return NULL;
}

static void opt_show_ad(char buf[OPT_SHOW_LEN], const u8 *assocdata)
static void opt_show_ad(char buf[OPT_SHOW_LEN], u8 *const *assocdata)
{
hex_encode(assocdata, ASSOC_DATA_SIZE, buf, OPT_SHOW_LEN);
hex_encode(*assocdata, tal_bytelen(*assocdata), buf, OPT_SHOW_LEN);
}

static char *opt_set_node_id(const char *arg, struct node_id *node_id)
Expand Down Expand Up @@ -361,16 +357,15 @@ int main(int argc, char **argv)
{
setup_locale();
const char *method;
u8 assocdata[ASSOC_DATA_SIZE];
u8 *assocdata = NULL;
struct node_id rendezvous_id;
memset(&assocdata, 'B', sizeof(assocdata));
memset(&rendezvous_id, 0, sizeof(struct node_id));

secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY |
SECP256K1_CONTEXT_SIGN);

opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn);
opt_register_arg("--assoc-data", opt_set_ad, opt_show_ad, assocdata,
opt_register_arg("--assoc-data", opt_set_ad, opt_show_ad, &assocdata,
"Associated data (usu. payment_hash of payment)");
opt_register_arg("--rendezvous-id", opt_set_node_id, NULL,
&rendezvous_id, "Node ID of the rendez-vous node");
Expand Down

0 comments on commit f541044

Please sign in to comment.