From 3826518bd6f182ff727c94d9e0a7c862b60f1f59 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 25 Mar 2018 18:23:10 +0200 Subject: [PATCH] gossip: Wrap node_announcements in gossip_store messages Signed-off-by: Christian Decker --- gossipd/gossip_store.c | 13 ++++++++++++- gossipd/gossip_store.h | 6 ++++++ gossipd/routing.c | 2 +- gossipd/test/run-bench-find_route.c | 6 ++++++ gossipd/test/run-find_route-specific.c | 6 ++++++ gossipd/test/run-find_route.c | 6 ++++++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index cb3a10cac..a57cd9be6 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -74,6 +74,14 @@ void gossip_store_add_channel_update(struct gossip_store *gs, tal_free(msg); } +void gossip_store_add_node_announcement(struct gossip_store *gs, + const u8 *gossip_msg) +{ + u8 *msg = towire_gossip_store_node_announcement(NULL, gossip_msg); + gossip_store_append(gs, msg); + tal_free(msg); +} + const u8 *gossip_store_read_next(const tal_t *ctx, struct routing_state *rstate, struct gossip_store *gs) { @@ -121,7 +129,10 @@ const u8 *gossip_store_read_next(const tal_t *ctx, struct routing_state *rstate, fromwire_gossip_store_channel_update(msg, msg, &gossip_msg); routing_add_channel_update(rstate, gossip_msg); return gossip_msg; + } else if(type == WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT) { + fromwire_gossip_store_node_announcement(msg, msg, &gossip_msg); + routing_add_node_announcement(rstate, gossip_msg); + return gossip_msg; } - return msg; } diff --git a/gossipd/gossip_store.h b/gossipd/gossip_store.h index 7cda17320..40a785c3f 100644 --- a/gossipd/gossip_store.h +++ b/gossipd/gossip_store.h @@ -47,4 +47,10 @@ void gossip_store_add_channel_announcement(struct gossip_store *gs, void gossip_store_add_channel_update(struct gossip_store *gs, const u8 *gossip_msg); +/** + * Store a node_announcement with its associated data in the gossip_store + */ +void gossip_store_add_node_announcement(struct gossip_store *gs, + const u8 *gossip_msg); + #endif /* GOSSIPD_GOSSIP_STORE_H */ diff --git a/gossipd/routing.c b/gossipd/routing.c index 7621121ed..c2c6e0a94 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1227,7 +1227,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann, /* FIXME: remove store guard */ if (store) - gossip_store_append(rstate->store, serialized); + gossip_store_add_node_announcement(rstate->store, serialized); routing_add_node_announcement(rstate, serialized); return NULL; } diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 67414ce9f..397e7565c 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -68,6 +68,9 @@ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const /* Generated stub for fromwire_gossip_store_channel_update */ bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); } +/* Generated stub for fromwire_gossip_store_node_announcement */ +bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED) +{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); } /* 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) { fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); } @@ -108,6 +111,9 @@ u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 /* Generated stub for towire_gossip_store_channel_update */ u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); } +/* Generated stub for towire_gossip_store_node_announcement */ +u8 *towire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED) +{ fprintf(stderr, "towire_gossip_store_node_announcement called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* Updates existing route if required. */ diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index ccabf1e7e..372f5e7bb 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -32,6 +32,9 @@ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const /* Generated stub for fromwire_gossip_store_channel_update */ bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); } +/* Generated stub for fromwire_gossip_store_node_announcement */ +bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED) +{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); } /* 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) { fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); } @@ -72,6 +75,9 @@ u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 /* Generated stub for towire_gossip_store_channel_update */ u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); } +/* Generated stub for towire_gossip_store_node_announcement */ +u8 *towire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED) +{ fprintf(stderr, "towire_gossip_store_node_announcement called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ const void *trc; diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 8ef289e7a..9e34ac899 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -30,6 +30,9 @@ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const /* Generated stub for fromwire_gossip_store_channel_update */ bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED) { fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); } +/* Generated stub for fromwire_gossip_store_node_announcement */ +bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED) +{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); } /* 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) { fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); } @@ -70,6 +73,9 @@ u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 /* Generated stub for towire_gossip_store_channel_update */ u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED) { fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); } +/* Generated stub for towire_gossip_store_node_announcement */ +u8 *towire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED) +{ fprintf(stderr, "towire_gossip_store_node_announcement called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* Updates existing route if required. */