gossipd: Add fuzz and seed to getroute request.

This commit is contained in:
ZmnSCPxj 2018-02-15 13:37:04 +00:00 committed by Rusty Russell
parent 2b782ee436
commit 216c52940d
4 changed files with 24 additions and 12 deletions

View File

@ -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);

View File

@ -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

1 #include <common/cryptomsg.h>
107 gossip_ping,3008 gossip_getchannels_reply,,num_channels,u16
108 gossip_ping,,id,struct pubkey gossip_getchannels_reply,,nodes,num_channels*struct gossip_getchannels_entry
109 gossip_ping,,num_pong_bytes,u16 # Ping/pong test. Waits for a reply if it expects one.
110 gossip_ping,3008
111 gossip_ping,,id,struct pubkey
112 gossip_ping,,num_pong_bytes,u16
113 gossip_ping,,len,u16
114 gossip_ping_reply,3108
115 # False if id in gossip_ping was unknown.

View File

@ -7,6 +7,7 @@
#include <ccan/array_size/array_size.h>
#include <ccan/err/err.h>
#include <ccan/fdpass/fdpass.h>
#include <ccan/isaac/isaac64.h>
#include <ccan/take/take.h>
#include <ccan/tal/str/str.h>
#include <common/features.h>
@ -22,6 +23,8 @@
#include <lightningd/hsm_control.h>
#include <lightningd/jsonrpc.h>
#include <lightningd/log.h>
#include <sodium/randombytes.h>
#include <string.h>
#include <wire/gen_peer_wire.h>
#include <wire/wire_sync.h>
@ -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);
}

View File

@ -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;