Browse Source
Moved the broadcast functionality to broadcast.[ch]. So far this includes only the enqueuing side of broadcasts, the dequeuing and actual push to the peer is daemon dependent. This also adds the broadcast_state to the routing_state and the last broadcast index to the peer for the legacy daemon.ppa-0.6.1
Christian Decker
8 years ago
committed by
Rusty Russell
10 changed files with 121 additions and 70 deletions
@ -0,0 +1,39 @@ |
|||
#include "daemon/broadcast.h" |
|||
|
|||
struct broadcast_state *new_broadcast_state(tal_t *ctx) |
|||
{ |
|||
struct broadcast_state *bstate = tal(ctx, struct broadcast_state); |
|||
uintmap_init(&bstate->broadcasts); |
|||
/* Skip 0 because we initialize peers with 0 */ |
|||
bstate->next_index = 1; |
|||
return bstate; |
|||
} |
|||
|
|||
static struct queued_message *new_queued_message(tal_t *ctx, |
|||
const int type, |
|||
const u8 *tag, |
|||
const u8 *payload) |
|||
{ |
|||
struct queued_message *msg = tal(ctx, struct queued_message); |
|||
msg->type = type; |
|||
msg->tag = tal_dup_arr(msg, u8, tag, tal_count(tag), 0); |
|||
msg->payload = tal_dup_arr(msg, u8, payload, tal_count(payload), 0); |
|||
return msg; |
|||
} |
|||
|
|||
void queue_broadcast(struct broadcast_state *bstate, |
|||
const int type, |
|||
const u8 *tag, |
|||
const u8 *payload) |
|||
{ |
|||
struct queued_message *msg = new_queued_message(bstate, type, tag, payload); |
|||
|
|||
/*FIXME(cdecker) Walk through old messages and purge collisions */ |
|||
uintmap_add(&bstate->broadcasts, bstate->next_index, msg); |
|||
bstate->next_index += 1; |
|||
} |
|||
|
|||
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 *last_index) |
|||
{ |
|||
return uintmap_after(&bstate->broadcasts, last_index); |
|||
} |
@ -0,0 +1,43 @@ |
|||
#ifndef LIGHTNING_DAEMON_BROADCAST_H |
|||
#define LIGHTNING_DAEMON_BROADCAST_H |
|||
#include "config.h" |
|||
|
|||
#include <ccan/intmap/intmap.h> |
|||
#include <ccan/list/list.h> |
|||
#include <ccan/short_types/short_types.h> |
|||
#include <ccan/tal/tal.h> |
|||
|
|||
/* Common functionality to implement staggered broadcasts with replacement. */ |
|||
|
|||
struct queued_message { |
|||
int type; |
|||
|
|||
/* Unique tag specifying the msg origin */ |
|||
void *tag; |
|||
|
|||
/* Timestamp for `channel_update`s and `node_announcement`s, 0
|
|||
* for `channel_announcement`s */ |
|||
/*u32 timestamp;*/ |
|||
|
|||
/* Serialized payload */ |
|||
u8 *payload; |
|||
|
|||
//FIXME(cdecker) Remove after migrating to intmap
|
|||
struct list_node list; |
|||
}; |
|||
|
|||
struct broadcast_state { |
|||
u32 next_index; |
|||
UINTMAP(struct queued_message *) broadcasts; |
|||
}; |
|||
|
|||
struct broadcast_state *new_broadcast_state(tal_t *ctx); |
|||
|
|||
void queue_broadcast(struct broadcast_state *bstate, |
|||
const int type, |
|||
const u8 *tag, |
|||
const u8 *payload); |
|||
|
|||
struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 *last_index); |
|||
|
|||
#endif /* LIGHTNING_DAEMON_BROADCAST_H */ |
Loading…
Reference in new issue