core-lightning/lightningd/htlc_end.c
Rusty Russell 798c4b73c4 lightningd/htlc_end: fix key for stricter compiler.
We *should* split the struct into key and data, rather than only comparing
the key parts in the htlc_end_eq function.  But meanwhile, this fixes
the code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-02 09:36:29 +09:30

40 lines
1.0 KiB
C

#include <ccan/cast/cast.h>
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/tal/tal.h>
#include <daemon/pseudorand.h>
#include <lightningd/htlc_end.h>
size_t hash_htlc_end(const struct htlc_end *e)
{
struct siphash24_ctx ctx;
siphash24_init(&ctx, siphash_seed());
/* peer doesn't move while in this hash, so we just hash pointer. */
siphash24_update(&ctx, &e->peer, sizeof(e->peer));
siphash24_u64(&ctx, e->htlc_id);
siphash24_u8(&ctx, e->which_end);
return siphash24_done(&ctx);
}
struct htlc_end *find_htlc_end(const struct htlc_end_map *map,
const struct peer *peer,
u64 htlc_id,
enum htlc_end_type which_end)
{
const struct htlc_end key = { which_end, (struct peer *)peer, htlc_id,
0, NULL, NULL };
return htlc_end_map_get(map, &key);
}
static void remove_htlc_end(struct htlc_end *hend, struct htlc_end_map *map)
{
htlc_end_map_del(map, hend);
}
void connect_htlc_end(struct htlc_end_map *map, struct htlc_end *hend)
{
tal_add_destructor2(hend, remove_htlc_end, map);
htlc_end_map_add(map, hend);
}