mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
gossip: formalize passing of siphash_seed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1049,25 +1049,16 @@ static struct io_plan *getroute_req(struct io_conn *conn, struct daemon *daemon,
|
|||||||
u8 *out;
|
u8 *out;
|
||||||
struct route_hop *hops;
|
struct route_hop *hops;
|
||||||
double fuzz;
|
double fuzz;
|
||||||
u8 *rawseed;
|
|
||||||
struct siphash_seed seed;
|
struct siphash_seed seed;
|
||||||
size_t seedbytes;
|
|
||||||
|
|
||||||
fromwire_gossip_getroute_request(tmpctx, msg,
|
fromwire_gossip_getroute_request(msg,
|
||||||
&source, &destination,
|
&source, &destination,
|
||||||
&msatoshi, &riskfactor, &final_cltv,
|
&msatoshi, &riskfactor, &final_cltv,
|
||||||
&fuzz, &rawseed);
|
&fuzz, &seed);
|
||||||
status_trace("Trying to find a route from %s to %s for %d msatoshi",
|
status_trace("Trying to find a route from %s to %s for %d msatoshi",
|
||||||
pubkey_to_hexstr(tmpctx, &source),
|
pubkey_to_hexstr(tmpctx, &source),
|
||||||
pubkey_to_hexstr(tmpctx, &destination), msatoshi);
|
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,
|
hops = get_route(tmpctx, daemon->rstate, &source, &destination,
|
||||||
msatoshi, 1, final_cltv,
|
msatoshi, 1, final_cltv,
|
||||||
fuzz, &seed);
|
fuzz, &seed);
|
||||||
|
|||||||
@@ -108,8 +108,7 @@ gossip_getroute_request,,msatoshi,u32
|
|||||||
gossip_getroute_request,,riskfactor,u16
|
gossip_getroute_request,,riskfactor,u16
|
||||||
gossip_getroute_request,,final_cltv,u32
|
gossip_getroute_request,,final_cltv,u32
|
||||||
gossip_getroute_request,,fuzz,double
|
gossip_getroute_request,,fuzz,double
|
||||||
gossip_getroute_request,,seedlen,u16
|
gossip_getroute_request,,seed,struct siphash_seed
|
||||||
gossip_getroute_request,,seed,seedlen*u8
|
|
||||||
|
|
||||||
gossip_getroute_reply,3106
|
gossip_getroute_reply,3106
|
||||||
gossip_getroute_reply,,num_hops,u16
|
gossip_getroute_reply,,num_hops,u16
|
||||||
|
|||||||
|
@@ -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
|
* be selected) at the cost of increasing the probability of
|
||||||
* selecting the higher-fee paths. */
|
* selecting the higher-fee paths. */
|
||||||
double fuzz = 75.0;
|
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,
|
if (!json_get_params(cmd, buffer, params,
|
||||||
"id", &idtok,
|
"id", &idtok,
|
||||||
@@ -373,13 +373,17 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
|||||||
fuzz = fuzz / 100.0;
|
fuzz = fuzz / 100.0;
|
||||||
|
|
||||||
if (seedtok) {
|
if (seedtok) {
|
||||||
tal_resize(&seed, seedtok->end - seedtok->start);
|
if (seedtok->end - seedtok->start > sizeof(seed))
|
||||||
memcpy(seed, buffer + seedtok->start,
|
command_fail(cmd,
|
||||||
|
"seed must be < %zu bytes", sizeof(seed));
|
||||||
|
|
||||||
|
memset(&seed, 0, sizeof(seed));
|
||||||
|
memcpy(&seed, buffer + seedtok->start,
|
||||||
seedtok->end - seedtok->start);
|
seedtok->end - seedtok->start);
|
||||||
} else
|
} 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);
|
subd_req(ld->gossip, ld->gossip, req, -1, 0, json_getroute_reply, cmd);
|
||||||
command_still_pending(cmd);
|
command_still_pending(cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,11 +220,11 @@ static void json_pay_getroute_reply(struct subd *gossip UNUSED,
|
|||||||
* false if resolved now. */
|
* false if resolved now. */
|
||||||
static bool json_pay_try(struct pay *pay)
|
static bool json_pay_try(struct pay *pay)
|
||||||
{
|
{
|
||||||
u8 *seed;
|
|
||||||
u8 *req;
|
u8 *req;
|
||||||
struct command *cmd = pay->cmd;
|
struct command *cmd = pay->cmd;
|
||||||
struct timeabs now = time_now();
|
struct timeabs now = time_now();
|
||||||
struct json_result *data;
|
struct json_result *data;
|
||||||
|
struct siphash_seed seed;
|
||||||
|
|
||||||
/* If too late anyway, fail now. */
|
/* If too late anyway, fail now. */
|
||||||
if (time_after(now, pay->expiry)) {
|
if (time_after(now, pay->expiry)) {
|
||||||
@@ -243,8 +243,7 @@ static bool json_pay_try(struct pay *pay)
|
|||||||
pay->try_parent = tal(pay, char);
|
pay->try_parent = tal(pay, char);
|
||||||
|
|
||||||
/* Generate random seed */
|
/* Generate random seed */
|
||||||
seed = tal_arr(pay->try_parent, u8, sizeof(struct siphash_seed));
|
randombytes_buf(&seed, sizeof(seed));
|
||||||
randombytes_buf(seed, tal_len(seed));
|
|
||||||
|
|
||||||
++pay->getroute_tries;
|
++pay->getroute_tries;
|
||||||
|
|
||||||
@@ -256,7 +255,7 @@ static bool json_pay_try(struct pay *pay)
|
|||||||
pay->riskfactor,
|
pay->riskfactor,
|
||||||
pay->min_final_cltv_expiry,
|
pay->min_final_cltv_expiry,
|
||||||
&pay->fuzz,
|
&pay->fuzz,
|
||||||
seed);
|
&seed);
|
||||||
subd_req(pay->try_parent, cmd->ld->gossip, req, -1, 0, json_pay_getroute_reply, pay);
|
subd_req(pay->try_parent, cmd->ld->gossip, req, -1, 0, json_pay_getroute_reply, pay);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <bitcoin/shadouble.h>
|
#include <bitcoin/shadouble.h>
|
||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
#include <ccan/build_assert/build_assert.h>
|
#include <ccan/build_assert/build_assert.h>
|
||||||
|
#include <ccan/crypto/siphash24/siphash24.h>
|
||||||
#include <ccan/endian/endian.h>
|
#include <ccan/endian/endian.h>
|
||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
#include <ccan/tal/str/str.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);
|
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));
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <bitcoin/shadouble.h>
|
#include <bitcoin/shadouble.h>
|
||||||
#include <bitcoin/tx.h>
|
#include <bitcoin/tx.h>
|
||||||
#include <ccan/crypto/ripemd160/ripemd160.h>
|
#include <ccan/crypto/ripemd160/ripemd160.h>
|
||||||
|
#include <ccan/crypto/siphash24/siphash24.h>
|
||||||
#include <ccan/endian/endian.h>
|
#include <ccan/endian/endian.h>
|
||||||
#include <ccan/mem/mem.h>
|
#include <ccan/mem/mem.h>
|
||||||
#include <ccan/tal/tal.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));
|
towire_u8_array(pptr, lin, tal_len(lin));
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)
|
||||||
|
{
|
||||||
|
towire(pptr, seed, sizeof(*seed));
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ struct bitcoin_blkid;
|
|||||||
struct bitcoin_txid;
|
struct bitcoin_txid;
|
||||||
struct preimage;
|
struct preimage;
|
||||||
struct ripemd160;
|
struct ripemd160;
|
||||||
|
struct siphash_seed;
|
||||||
|
|
||||||
/* Makes generate-wire.py work */
|
/* Makes generate-wire.py work */
|
||||||
typedef char wirestring;
|
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_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx);
|
||||||
void towire_wirestring(u8 **pptr, const char *str);
|
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);
|
const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n);
|
||||||
u8 fromwire_u8(const u8 **cursor, size_t *max);
|
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);
|
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);
|
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max);
|
||||||
|
|
||||||
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
||||||
const u8 **cursor, size_t *max);
|
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 */
|
#endif /* LIGHTNING_WIRE_WIRE_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user