From 216c52940d37b2aa8dbc5d0b16ec5ce29f0ec02f Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Thu, 15 Feb 2018 13:37:04 +0000 Subject: [PATCH] gossipd: Add fuzz and seed to getroute request. --- gossipd/gossip.c | 10 ++++++++-- gossipd/gossip_wire.csv | 3 +++ lightningd/gossip_control.c | 20 +++++++++++--------- lightningd/payalgo.c | 3 ++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 22fed49d7..6605bd618 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -1047,13 +1047,19 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon, u16 riskfactor; u8 *out; struct route_hop *hops; + double fuzz; + u8 *seed; - fromwire_gossip_getroute_request(msg, &source, &destination, - &msatoshi, &riskfactor, &final_cltv); + fromwire_gossip_getroute_request(tmpctx, msg, + &source, &destination, + &msatoshi, &riskfactor, &final_cltv, + &fuzz, &seed); status_trace("Trying to find a route from %s to %s for %d msatoshi", pubkey_to_hexstr(tmpctx, &source), pubkey_to_hexstr(tmpctx, &destination), msatoshi); + (void) fuzz; + (void) seed; hops = get_route(tmpctx, daemon->rstate, &source, &destination, msatoshi, 1, final_cltv); diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 8f8d6f265..469a041f2 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -107,6 +107,9 @@ gossip_getroute_request,,destination,struct pubkey gossip_getroute_request,,msatoshi,u32 gossip_getroute_request,,riskfactor,u16 gossip_getroute_request,,final_cltv,u32 +gossip_getroute_request,,fuzz,double +gossip_getroute_request,,seedlen,u16 +gossip_getroute_request,,seed,seedlen*u8 gossip_getroute_reply,3106 gossip_getroute_reply,,num_hops,u16 diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c index 337f88c10..1436fb689 100644 --- a/lightningd/gossip_control.c +++ b/lightningd/gossip_control.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -305,7 +308,7 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok unsigned cltv = 9; double riskfactor; double fuzz = 5.0; - const char *seed = "default"; + u8 *seed = tal_arrz(cmd, u8, ISAAC64_SEED_SZ_MAX); if (!json_get_params(cmd, buffer, params, "id", &idtok, @@ -364,15 +367,14 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok /* Convert from percentage */ fuzz = fuzz / 100.0; - if (seedtok) - seed = tal_strndup(cmd, buffer + seedtok->start, - seedtok->end - seedtok->start); + if (seedtok) { + tal_resize(&seed, seedtok->end - seedtok->start); + memcpy(seed, buffer + seedtok->start, + seedtok->end - seedtok->start); + } else + randombytes_buf(seed, tal_len(seed)); - /* TODO: include in getroute request */ - (void) fuzz; - (void) seed; - - u8 *req = towire_gossip_getroute_request(cmd, &source, &destination, msatoshi, riskfactor*1000, cltv); + u8 *req = towire_gossip_getroute_request(cmd, &source, &destination, msatoshi, riskfactor*1000, cltv, &fuzz, seed); subd_req(ld->gossip, ld->gossip, req, -1, 0, json_getroute_reply, cmd); command_still_pending(cmd); } diff --git a/lightningd/payalgo.c b/lightningd/payalgo.c index 852d5bf54..3d76d8b41 100644 --- a/lightningd/payalgo.c +++ b/lightningd/payalgo.c @@ -224,7 +224,8 @@ static bool json_pay_try(struct pay *pay) &pay->receiver_id, pay->msatoshi, pay->riskfactor, - pay->min_final_cltv_expiry); + pay->min_final_cltv_expiry, + 0, tal_arrz(pay, u8, 8)); subd_req(pay, cmd->ld->gossip, req, -1, 0, json_pay_getroute_reply, pay); return true;