gossipd: remove type from broadcast.

It's not necessary now we only access by index.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-03-14 02:07:55 +10:30
parent 060182fb65
commit 882f9f258f
6 changed files with 6 additions and 26 deletions

View File

@ -11,26 +11,24 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx)
} }
static struct queued_message *new_queued_message(tal_t *ctx, static struct queued_message *new_queued_message(tal_t *ctx,
const int type,
const u8 *tag, const u8 *tag,
const u8 *payload) const u8 *payload)
{ {
struct queued_message *msg = tal(ctx, struct queued_message); struct queued_message *msg = tal(ctx, struct queued_message);
msg->type = type;
msg->tag = tal_dup_arr(msg, u8, tag, tal_len(tag), 0); msg->tag = tal_dup_arr(msg, u8, tag, tal_len(tag), 0);
msg->payload = tal_dup_arr(msg, u8, payload, tal_len(payload), 0); msg->payload = tal_dup_arr(msg, u8, payload, tal_len(payload), 0);
return msg; return msg;
} }
bool replace_broadcast(struct broadcast_state *bstate, u64 *index, bool replace_broadcast(struct broadcast_state *bstate, u64 *index,
const int type, const u8 *tag, const u8 *payload) const u8 *tag, const u8 *payload)
{ {
struct queued_message *msg; struct queued_message *msg;
bool evicted = false; bool evicted = false;
msg = uintmap_get(&bstate->broadcasts, *index); msg = uintmap_get(&bstate->broadcasts, *index);
if (msg && msg->type == type && if (msg) {
memeq(msg->tag, tal_len(msg->tag), tag, tal_len(tag))) { assert(memeq(msg->tag, tal_len(msg->tag), tag, tal_len(tag)));
uintmap_del(&bstate->broadcasts, *index); uintmap_del(&bstate->broadcasts, *index);
tal_free(msg); tal_free(msg);
evicted = true; evicted = true;
@ -38,7 +36,7 @@ bool replace_broadcast(struct broadcast_state *bstate, u64 *index,
*index = bstate->next_index; *index = bstate->next_index;
/* Now add the message to the queue */ /* Now add the message to the queue */
msg = new_queued_message(bstate, type, tag, payload); msg = new_queued_message(bstate, tag, payload);
uintmap_add(&bstate->broadcasts, *index, msg); uintmap_add(&bstate->broadcasts, *index, msg);
bstate->next_index++; bstate->next_index++;
return evicted; return evicted;

View File

@ -10,8 +10,6 @@
/* Common functionality to implement staggered broadcasts with replacement. */ /* Common functionality to implement staggered broadcasts with replacement. */
struct queued_message { struct queued_message {
int type;
/* Unique tag specifying the msg origin */ /* Unique tag specifying the msg origin */
void *tag; void *tag;
@ -32,7 +30,6 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx);
* newly queued message*/ * newly queued message*/
bool replace_broadcast(struct broadcast_state *bstate, bool replace_broadcast(struct broadcast_state *bstate,
u64 *index, u64 *index,
const int type,
const u8 *tag, const u8 *tag,
const u8 *payload); const u8 *payload);

View File

@ -818,7 +818,6 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
if (replace_broadcast(rstate->broadcasts, if (replace_broadcast(rstate->broadcasts,
&chan->channel_announce_msgidx, &chan->channel_announce_msgidx,
WIRE_CHANNEL_ANNOUNCEMENT,
tag, pending->announce)) tag, pending->announce))
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Announcement %s was replaced?", "Announcement %s was replaced?",
@ -1005,9 +1004,8 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
towire_u16(&tag, direction); towire_u16(&tag, direction);
replace_broadcast(rstate->broadcasts, replace_broadcast(rstate->broadcasts,
&chan->half[direction].channel_update_msgidx, &chan->half[direction].channel_update_msgidx,
WIRE_CHANNEL_UPDATE, tag,
tag, serialized);
serialized);
tal_free(c->channel_update); tal_free(c->channel_update);
c->channel_update = tal_steal(chan, serialized); c->channel_update = tal_steal(chan, serialized);
@ -1194,7 +1192,6 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
towire_pubkey(&tag, &node_id); towire_pubkey(&tag, &node_id);
replace_broadcast(rstate->broadcasts, replace_broadcast(rstate->broadcasts,
&node->announcement_idx, &node->announcement_idx,
WIRE_NODE_ANNOUNCEMENT,
tag, tag,
serialized); serialized);
tal_free(node->node_announcement); tal_free(node->node_announcement);

View File

@ -64,9 +64,6 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *
/* Generated stub for fromwire_node_announcement */ /* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED) bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)
{ fprintf(stderr, "fromwire_peektype called!\n"); abort(); }
/* Generated stub for fromwire_u8 */ /* Generated stub for fromwire_u8 */
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } { fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
@ -79,7 +76,6 @@ const char *onion_type_name(int e UNNEEDED)
/* Generated stub for replace_broadcast */ /* Generated stub for replace_broadcast */
bool replace_broadcast(struct broadcast_state *bstate UNNEEDED, bool replace_broadcast(struct broadcast_state *bstate UNNEEDED,
u64 *index UNNEEDED, u64 *index UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED, const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED) const u8 *payload UNNEEDED)
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); } { fprintf(stderr, "replace_broadcast called!\n"); abort(); }

View File

@ -28,9 +28,6 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *
/* Generated stub for fromwire_node_announcement */ /* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED) bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)
{ fprintf(stderr, "fromwire_peektype called!\n"); abort(); }
/* Generated stub for fromwire_u8 */ /* Generated stub for fromwire_u8 */
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } { fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
@ -43,7 +40,6 @@ const char *onion_type_name(int e UNNEEDED)
/* Generated stub for replace_broadcast */ /* Generated stub for replace_broadcast */
bool replace_broadcast(struct broadcast_state *bstate UNNEEDED, bool replace_broadcast(struct broadcast_state *bstate UNNEEDED,
u64 *index UNNEEDED, u64 *index UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED, const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED) const u8 *payload UNNEEDED)
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); } { fprintf(stderr, "replace_broadcast called!\n"); abort(); }

View File

@ -26,9 +26,6 @@ bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *
/* Generated stub for fromwire_node_announcement */ /* Generated stub for fromwire_node_announcement */
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED) bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); } { fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
/* Generated stub for fromwire_peektype */
int fromwire_peektype(const u8 *cursor UNNEEDED)
{ fprintf(stderr, "fromwire_peektype called!\n"); abort(); }
/* Generated stub for fromwire_u8 */ /* Generated stub for fromwire_u8 */
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } { fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
@ -41,7 +38,6 @@ const char *onion_type_name(int e UNNEEDED)
/* Generated stub for replace_broadcast */ /* Generated stub for replace_broadcast */
bool replace_broadcast(struct broadcast_state *bstate UNNEEDED, bool replace_broadcast(struct broadcast_state *bstate UNNEEDED,
u64 *index UNNEEDED, u64 *index UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED, const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED) const u8 *payload UNNEEDED)
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); } { fprintf(stderr, "replace_broadcast called!\n"); abort(); }