Browse Source

gossip: formalize passing of siphash_seed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
cf3f19524e
  1. 13
      gossipd/gossip.c
  2. 3
      gossipd/gossip_wire.csv
  3. 14
      lightningd/gossip_control.c
  4. 7
      lightningd/payalgo.c
  5. 7
      wire/fromwire.c
  6. 6
      wire/towire.c
  7. 5
      wire/wire.h

13
gossipd/gossip.c

@ -1049,25 +1049,16 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
u8 *out;
struct route_hop *hops;
double fuzz;
u8 *rawseed;
struct siphash_seed seed;
size_t seedbytes;
fromwire_gossip_getroute_request(tmpctx, msg,
fromwire_gossip_getroute_request(msg,
&source, &destination,
&msatoshi, &riskfactor, &final_cltv,
&fuzz, &rawseed);
&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);
/* Initialize siphash */
memset(&seed, 0, sizeof(seed));
seedbytes =
(tal_len(rawseed) > sizeof(seed)) ? sizeof(seed) :
/*otherwise*/ tal_len(rawseed) ;
memcpy(&seed, rawseed, seedbytes);
hops = get_route(tmpctx, daemon->rstate, &source, &destination,
msatoshi, 1, final_cltv,
fuzz, &seed);

3
gossipd/gossip_wire.csv

@ -108,8 +108,7 @@ 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_request,,seed,struct siphash_seed
gossip_getroute_reply,3106
gossip_getroute_reply,,num_hops,u16

Can't render this file because it has a wrong number of fields in line 6.

14
lightningd/gossip_control.c

@ -313,7 +313,7 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
* be selected) at the cost of increasing the probability of
* selecting the higher-fee paths. */
double fuzz = 75.0;
u8 *seed = tal_arrz(cmd, u8, sizeof(struct siphash_seed));
struct siphash_seed seed;
if (!json_get_params(cmd, buffer, params,
"id", &idtok,
@ -373,13 +373,17 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
fuzz = fuzz / 100.0;
if (seedtok) {
tal_resize(&seed, seedtok->end - seedtok->start);
memcpy(seed, buffer + seedtok->start,
if (seedtok->end - seedtok->start > sizeof(seed))
command_fail(cmd,
"seed must be < %zu bytes", sizeof(seed));
memset(&seed, 0, sizeof(seed));
memcpy(&seed, buffer + seedtok->start,
seedtok->end - seedtok->start);
} else
randombytes_buf(seed, tal_len(seed));
randombytes_buf(&seed, sizeof(seed));
u8 *req = towire_gossip_getroute_request(cmd, &source, &destination, msatoshi, riskfactor*1000, cltv, &fuzz, seed);
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);
}

7
lightningd/payalgo.c

@ -220,11 +220,11 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
* false if resolved now. */
static bool json_pay_try(struct pay *pay)
{
u8 *seed;
u8 *req;
struct command *cmd = pay->cmd;
struct timeabs now = time_now();
struct json_result *data;
struct siphash_seed seed;
/* If too late anyway, fail now. */
if (time_after(now, pay->expiry)) {
@ -243,8 +243,7 @@ static bool json_pay_try(struct pay *pay)
pay->try_parent = tal(pay, char);
/* Generate random seed */
seed = tal_arr(pay->try_parent, u8, sizeof(struct siphash_seed));
randombytes_buf(seed, tal_len(seed));
randombytes_buf(&seed, sizeof(seed));
++pay->getroute_tries;
@ -256,7 +255,7 @@ static bool json_pay_try(struct pay *pay)
pay->riskfactor,
pay->min_final_cltv_expiry,
&pay->fuzz,
seed);
&seed);
subd_req(pay->try_parent, cmd->ld->gossip, req, -1, 0, json_pay_getroute_reply, pay);
return true;

7
wire/fromwire.c

@ -4,6 +4,7 @@
#include <bitcoin/shadouble.h>
#include <bitcoin/tx.h>
#include <ccan/build_assert/build_assert.h>
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
@ -256,3 +257,9 @@ struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
{
return pull_bitcoin_tx(ctx, cursor, max);
}
void fromwire_siphash_seed(const u8 **cursor, size_t *max,
struct siphash_seed *seed)
{
fromwire(cursor, max, seed, sizeof(*seed));
}

6
wire/towire.c

@ -3,6 +3,7 @@
#include <bitcoin/shadouble.h>
#include <bitcoin/tx.h>
#include <ccan/crypto/ripemd160/ripemd160.h>
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
#include <ccan/tal/tal.h>
@ -168,3 +169,8 @@ void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
towire_u8_array(pptr, lin, tal_len(lin));
tal_free(tmpctx);
}
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)
{
towire(pptr, seed, sizeof(*seed));
}

5
wire/wire.h

@ -20,6 +20,7 @@ struct bitcoin_blkid;
struct bitcoin_txid;
struct preimage;
struct ripemd160;
struct siphash_seed;
/* Makes generate-wire.py work */
typedef char wirestring;
@ -60,6 +61,7 @@ void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx);
void towire_wirestring(u8 **pptr, const char *str);
void towire_siphash_seed(u8 **cursor, const struct siphash_seed *seed);
const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n);
u8 fromwire_u8(const u8 **cursor, size_t *max);
@ -93,7 +95,8 @@ void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num);
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max);
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
const u8 **cursor, size_t *max);
void fromwire_siphash_seed(const u8 **cursor, size_t *max,
struct siphash_seed *seed);
#endif /* LIGHTNING_WIRE_WIRE_H */

Loading…
Cancel
Save