Skip to content

Commit

Permalink
daemons: remove unused functions or make static.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Dec 5, 2021
1 parent 7867326 commit 484222b
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 544 deletions.
3 changes: 0 additions & 3 deletions gossipd/gossip_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,4 @@ bool gossip_store_compact(struct gossip_store *gs);
*/
int gossip_store_readonly_fd(struct gossip_store *gs);

/* Callback inside gossipd when store is compacted */
void update_peers_broadcast_index(struct list_head *peers, u32 offset);

#endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_H */
6 changes: 0 additions & 6 deletions gossipd/gossipd.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,4 @@ void queue_peer_msg(struct peer *peer, const u8 *msg TAKES);
void queue_peer_from_store(struct peer *peer,
const struct broadcastable *bcast);

/* Reset gossip range for this peer. */
void setup_gossip_range(struct peer *peer);

/* A peer has given us these short channel ids: see if we need to catch up */
void process_scids(struct daemon *daemon, const struct short_channel_id *scids);

#endif /* LIGHTNING_GOSSIPD_GOSSIPD_H */
2 changes: 1 addition & 1 deletion lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ static void handle_error_channel(struct channel *channel,
forget(channel);
}

void forget_channel(struct channel *channel, const char *why)
static void forget_channel(struct channel *channel, const char *why)
{
channel->error = towire_errorfmt(channel, &channel->cid, "%s", why);

Expand Down
3 changes: 0 additions & 3 deletions lightningd/channel_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ bool channel_on_funding_locked(struct channel *channel,

/* Record channel open (coin movement notifications) */
void channel_record_open(struct channel *channel);
/* Forget a channel. Deletes the channel and handles all
* associated waiting commands, if present. Notifies peer if available */
void forget_channel(struct channel *channel, const char *err_msg);

/* A channel has unrecoverably fallen behind */
void channel_fallen_behind(struct channel *channel, const u8 *msg);
Expand Down
1 change: 0 additions & 1 deletion lightningd/connect_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ void delay_then_reconnect(struct channel *channel, u32 seconds_delay,
void connect_succeeded(struct lightningd *ld, const struct peer *peer,
bool incoming,
const struct wireaddr_internal *addr);
void gossip_connect_result(struct lightningd *ld, const u8 *msg);

#endif /* LIGHTNING_LIGHTNINGD_CONNECT_CONTROL_H */
187 changes: 0 additions & 187 deletions lightningd/gossip_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,113 +5,6 @@
#include <lightningd/gossip_msg.h>
#include <wire/peer_wire.h>

struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
const u8 **pptr, size_t *max)
{
u8 numaddresses, i;
struct gossip_getnodes_entry *entry;
u16 flen;
bool has_rates;

entry = tal(ctx, struct gossip_getnodes_entry);
fromwire_node_id(pptr, max, &entry->nodeid);

entry->last_timestamp = fromwire_u64(pptr, max);
if (entry->last_timestamp < 0) {
entry->addresses = NULL;
return entry;
}

flen = fromwire_u16(pptr, max);
entry->features = fromwire_tal_arrn(entry, pptr, max, flen);

numaddresses = fromwire_u8(pptr, max);

entry->addresses = tal_arr(entry, struct wireaddr, numaddresses);
for (i=0; i<numaddresses; i++) {
/* Gossipd doesn't hand us addresses we can't understand. */
if (!fromwire_wireaddr(pptr, max, &entry->addresses[i]))
return fromwire_fail(pptr, max);
}
fromwire(pptr, max, entry->alias, ARRAY_SIZE(entry->alias));
fromwire(pptr, max, entry->color, ARRAY_SIZE(entry->color));

has_rates = fromwire_u8(pptr, max);
if (has_rates) {
entry->rates = tal(entry, struct lease_rates);
fromwire_lease_rates(pptr, max, entry->rates);
} else
entry->rates = NULL;

return entry;
}

void towire_gossip_getnodes_entry(u8 **pptr,
const struct gossip_getnodes_entry *entry)
{
towire_node_id(pptr, &entry->nodeid);
towire_u64(pptr, entry->last_timestamp);

if (entry->last_timestamp < 0)
return;

towire_u16(pptr, tal_count(entry->features));
towire_u8_array(pptr, entry->features, tal_count(entry->features));
towire_u8(pptr, tal_count(entry->addresses));
for (size_t i = 0; i < tal_count(entry->addresses); i++) {
towire_wireaddr(pptr, &entry->addresses[i]);
}
towire(pptr, entry->alias, ARRAY_SIZE(entry->alias));
towire(pptr, entry->color, ARRAY_SIZE(entry->color));

if (entry->rates) {
towire_u8(pptr, 1);
towire_lease_rates(pptr, entry->rates);
} else
towire_u8(pptr, 0);
}

struct route_hop *fromwire_route_hop(const tal_t *ctx,
const u8 **pptr, size_t *max)
{
struct route_hop *entry = tal(ctx, struct route_hop);
size_t enclen;

fromwire_node_id(pptr, max, &entry->node_id);
fromwire_short_channel_id(pptr, max, &entry->scid);
entry->direction = fromwire_u8(pptr, max);
entry->amount = fromwire_amount_msat(pptr, max);
entry->delay = fromwire_u32(pptr, max);
entry->style = fromwire_u8(pptr, max);
if (fromwire_bool(pptr, max)) {
entry->blinding = tal(entry, struct pubkey);
fromwire_pubkey(pptr, max, entry->blinding);
}
enclen = fromwire_u16(pptr, max);
if (enclen)
entry->enctlv = fromwire_tal_arrn(entry, pptr, max, enclen);
else
entry->enctlv = NULL;
return entry;
}

void towire_route_hop(u8 **pptr, const struct route_hop *entry)
{
towire_node_id(pptr, &entry->node_id);
towire_short_channel_id(pptr, &entry->scid);
towire_u8(pptr, entry->direction);
towire_amount_msat(pptr, entry->amount);
towire_u32(pptr, entry->delay);
towire_u8(pptr, entry->style);
if (entry->blinding) {
towire_bool(pptr, true);
towire_pubkey(pptr, entry->blinding);
} else
towire_bool(pptr, false);
towire_u16(pptr, tal_bytelen(entry->enctlv));
towire_u8_array(pptr, entry->enctlv, tal_bytelen(entry->enctlv));
}

void fromwire_route_info(const u8 **pptr, size_t *max, struct route_info *entry)
{
fromwire_node_id(pptr, max, &entry->pubkey);
Expand All @@ -129,83 +22,3 @@ void towire_route_info(u8 **pptr, const struct route_info *entry)
towire_u32(pptr, entry->fee_proportional_millionths);
towire_u16(pptr, entry->cltv_expiry_delta);
}

static void fromwire_gossip_halfchannel_entry(const u8 **pptr, size_t *max,
struct gossip_halfchannel_entry *entry)
{
entry->message_flags = fromwire_u8(pptr, max);
entry->channel_flags = fromwire_u8(pptr, max);
entry->last_update_timestamp = fromwire_u32(pptr, max);
entry->delay = fromwire_u32(pptr, max);
entry->base_fee_msat = fromwire_u32(pptr, max);
entry->fee_per_millionth = fromwire_u32(pptr, max);
entry->min = fromwire_amount_msat(pptr, max);
entry->max = fromwire_amount_msat(pptr, max);
}

struct gossip_getchannels_entry *
fromwire_gossip_getchannels_entry(const tal_t *ctx,
const u8 **pptr, size_t *max)
{
struct gossip_getchannels_entry *entry;

entry= tal(ctx, struct gossip_getchannels_entry);
fromwire_node_id(pptr, max, &entry->node[0]);
fromwire_node_id(pptr, max, &entry->node[1]);
entry->sat = fromwire_amount_sat(pptr, max);
fromwire_short_channel_id(pptr, max, &entry->short_channel_id);
entry->public = fromwire_bool(pptr, max);
entry->local_disabled = fromwire_bool(pptr, max);
entry->features = fromwire_tal_arrn(entry,
pptr, max, fromwire_u16(pptr, max));

if (fromwire_bool(pptr, max)) {
entry->e[0] = tal(entry, struct gossip_halfchannel_entry);
fromwire_gossip_halfchannel_entry(pptr, max, entry->e[0]);
} else
entry->e[0] = NULL;
if (fromwire_bool(pptr, max)) {
entry->e[1] = tal(entry, struct gossip_halfchannel_entry);
fromwire_gossip_halfchannel_entry(pptr, max, entry->e[1]);
} else
entry->e[1] = NULL;

return entry;
}

static void towire_gossip_halfchannel_entry(u8 **pptr,
const struct gossip_halfchannel_entry *entry)
{
towire_u8(pptr, entry->message_flags);
towire_u8(pptr, entry->channel_flags);
towire_u32(pptr, entry->last_update_timestamp);
towire_u32(pptr, entry->delay);
towire_u32(pptr, entry->base_fee_msat);
towire_u32(pptr, entry->fee_per_millionth);
towire_amount_msat(pptr, entry->min);
towire_amount_msat(pptr, entry->max);
}

void towire_gossip_getchannels_entry(u8 **pptr,
const struct gossip_getchannels_entry *entry)
{
towire_node_id(pptr, &entry->node[0]);
towire_node_id(pptr, &entry->node[1]);
towire_amount_sat(pptr, entry->sat);
towire_short_channel_id(pptr, &entry->short_channel_id);
towire_bool(pptr, entry->public);
towire_bool(pptr, entry->local_disabled);
towire_u16(pptr, tal_bytelen(entry->features));
towire_u8_array(pptr, entry->features, tal_bytelen(entry->features));
if (entry->e[0]) {
towire_bool(pptr, true);
towire_gossip_halfchannel_entry(pptr, entry->e[0]);
} else
towire_bool(pptr, false);

if (entry->e[1]) {
towire_bool(pptr, true);
towire_gossip_halfchannel_entry(pptr, entry->e[1]);
} else
towire_bool(pptr, false);
}
15 changes: 0 additions & 15 deletions lightningd/gossip_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,7 @@ struct gossip_getchannels_entry {
u8 *features;
};

struct gossip_getnodes_entry *
fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *max);
void towire_gossip_getnodes_entry(u8 **pptr,
const struct gossip_getnodes_entry *entry);

struct route_hop *fromwire_route_hop(const tal_t *ctx,
const u8 **pptr, size_t *max);
void towire_route_hop(u8 **pprt, const struct route_hop *entry);

void fromwire_route_info(const u8 **pprt, size_t *max, struct route_info *entry);
void towire_route_info(u8 **pprt, const struct route_info *entry);

struct gossip_getchannels_entry *
fromwire_gossip_getchannels_entry(const tal_t *ctx,
const u8 **pptr, size_t *max);
void towire_gossip_getchannels_entry(
u8 **pptr, const struct gossip_getchannels_entry *entry);

#endif /* LIGHTNING_LIGHTNINGD_GOSSIP_MSG_H */
105 changes: 54 additions & 51 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ static void plugin_check_subscriptions(struct plugins *plugins,
}
}

static bool plugins_any_in_state(const struct plugins *plugins,
enum plugin_state state)
{
const struct plugin *p;

list_for_each(&plugins->plugins, p, list) {
if (p->plugin_state == state)
return true;
}
return false;
}

static bool plugins_all_in_state(const struct plugins *plugins,
enum plugin_state state)
{
const struct plugin *p;

list_for_each(&plugins->plugins, p, list) {
if (p->plugin_state != state)
return false;
}
return true;
}

/* Once they've all replied with their manifests, we can order them. */
static void check_plugins_manifests(struct plugins *plugins)
{
Expand Down Expand Up @@ -493,6 +517,36 @@ static const char *plugin_notification_handle(struct plugin *plugin,
return NULL;
}

struct plugin_destroyed {
const struct plugin *plugin;
};

static void mark_plugin_destroyed(const struct plugin *unused,
struct plugin_destroyed *pd)
{
pd->plugin = NULL;
}

static struct plugin_destroyed *
plugin_detect_destruction(const struct plugin *plugin)
{
struct plugin_destroyed *pd = tal(NULL, struct plugin_destroyed);
pd->plugin = plugin;
tal_add_destructor2(plugin, mark_plugin_destroyed, pd);
return pd;
}

static bool was_plugin_destroyed(struct plugin_destroyed *pd)
{
if (pd->plugin) {
tal_del_destructor2(pd->plugin, mark_plugin_destroyed, pd);
tal_free(pd);
return false;
}
tal_free(pd);
return true;
}

/* Returns the error string, or NULL */
static const char *plugin_response_handle(struct plugin *plugin,
const jsmntok_t *toks,
Expand Down Expand Up @@ -1459,28 +1513,6 @@ static const char *plugin_parse_getmanifest_response(const char *buffer,
return err;
}

bool plugins_any_in_state(const struct plugins *plugins, enum plugin_state state)
{
const struct plugin *p;

list_for_each(&plugins->plugins, p, list) {
if (p->plugin_state == state)
return true;
}
return false;
}

bool plugins_all_in_state(const struct plugins *plugins, enum plugin_state state)
{
const struct plugin *p;

list_for_each(&plugins->plugins, p, list) {
if (p->plugin_state != state)
return false;
}
return true;
}

/**
* Callback for the plugin_manifest request.
*/
Expand Down Expand Up @@ -2056,35 +2088,6 @@ void plugins_set_builtin_plugins_dir(struct plugins *plugins,
NULL, NULL);
}

struct plugin_destroyed {
const struct plugin *plugin;
};

static void mark_plugin_destroyed(const struct plugin *unused,
struct plugin_destroyed *pd)
{
pd->plugin = NULL;
}

struct plugin_destroyed *plugin_detect_destruction(const struct plugin *plugin)
{
struct plugin_destroyed *pd = tal(NULL, struct plugin_destroyed);
pd->plugin = plugin;
tal_add_destructor2(plugin, mark_plugin_destroyed, pd);
return pd;
}

bool was_plugin_destroyed(struct plugin_destroyed *pd)
{
if (pd->plugin) {
tal_del_destructor2(pd->plugin, mark_plugin_destroyed, pd);
tal_free(pd);
return false;
}
tal_free(pd);
return true;
}

static void plugin_shutdown_timeout(struct lightningd *ld)
{
io_break(plugin_shutdown_timeout);
Expand Down
Loading

0 comments on commit 484222b

Please sign in to comment.