lightningd: group crypto_state and fds into a convenient structure.

These are always handed to subdaemons as a set, so group them.  This makes
it easier to add an fd (in the next patch).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-05-04 15:23:12 +09:30
parent 89291b930e
commit eaac0d7105
17 changed files with 122 additions and 90 deletions

View file

@ -83,6 +83,7 @@ LIGHTNINGD_SRC := \
lightningd/pay.c \ lightningd/pay.c \
lightningd/peer_control.c \ lightningd/peer_control.c \
lightningd/peer_htlcs.c \ lightningd/peer_htlcs.c \
lightningd/peer_comms.c \
lightningd/ping.c \ lightningd/ping.c \
lightningd/plugin.c \ lightningd/plugin.c \
lightningd/plugin_hook.c \ lightningd/plugin_hook.c \

View file

@ -14,6 +14,7 @@
#include <lightningd/hsm_control.h> #include <lightningd/hsm_control.h>
#include <lightningd/lightningd.h> #include <lightningd/lightningd.h>
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/peer_comms.h>
#include <lightningd/peer_control.h> #include <lightningd/peer_control.h>
#include <lightningd/subd.h> #include <lightningd/subd.h>
#include <wire/wire_sync.h> #include <wire/wire_sync.h>
@ -182,19 +183,21 @@ static void peer_start_closingd_after_shutdown(struct channel *channel,
const u8 *msg, const u8 *msg,
const int *fds) const int *fds)
{ {
struct crypto_state cs; struct peer_comms *pcomms = new_peer_comms(msg);
/* We expect 2 fds. */ /* We expect 2 fds. */
assert(tal_count(fds) == 2); assert(tal_count(fds) == 2);
if (!fromwire_channel_shutdown_complete(msg, &cs)) { if (!fromwire_channel_shutdown_complete(msg, &pcomms->cs)) {
channel_internal_error(channel, "bad shutdown_complete: %s", channel_internal_error(channel, "bad shutdown_complete: %s",
tal_hex(msg, msg)); tal_hex(msg, msg));
return; return;
} }
pcomms->peer_fd = fds[0];
pcomms->gossip_fd = fds[1];
/* This sets channel->owner, closes down channeld. */ /* This sets channel->owner, closes down channeld. */
peer_start_closingd(channel, &cs, fds[0], fds[1], false, NULL); peer_start_closingd(channel, pcomms, false, NULL);
channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE); channel_set_state(channel, CHANNELD_SHUTTING_DOWN, CLOSINGD_SIGEXCHANGE);
} }
@ -253,8 +256,7 @@ static unsigned channel_msg(struct subd *sd, const u8 *msg, const int *fds)
} }
void peer_start_channeld(struct channel *channel, void peer_start_channeld(struct channel *channel,
const struct crypto_state *cs, struct peer_comms *pcomms,
int peer_fd, int gossip_fd,
const u8 *funding_signed, const u8 *funding_signed,
bool reconnected) bool reconnected)
{ {
@ -288,8 +290,8 @@ void peer_start_channeld(struct channel *channel,
channel_msg, channel_msg,
channel_errmsg, channel_errmsg,
channel_set_billboard, channel_set_billboard,
take(&peer_fd), take(&pcomms->peer_fd),
take(&gossip_fd), take(&pcomms->gossip_fd),
take(&hsmfd), NULL), take(&hsmfd), NULL),
false); false);
@ -356,7 +358,7 @@ void peer_start_channeld(struct channel *channel,
feerate_min(ld, NULL), feerate_min(ld, NULL),
feerate_max(ld, NULL), feerate_max(ld, NULL),
&channel->last_sig, &channel->last_sig,
cs, &pcomms->cs,
&channel->channel_info.remote_fundingkey, &channel->channel_info.remote_fundingkey,
&channel->channel_info.theirbase, &channel->channel_info.theirbase,
&channel->channel_info.remote_per_commit, &channel->channel_info.remote_per_commit,

View file

@ -7,10 +7,10 @@
struct channel; struct channel;
struct crypto_state; struct crypto_state;
struct lightningd; struct lightningd;
struct peer_comms;
void peer_start_channeld(struct channel *channel, void peer_start_channeld(struct channel *channel,
const struct crypto_state *cs, struct peer_comms *pcomms,
int peer_fd, int gossip_fd,
const u8 *funding_signed, const u8 *funding_signed,
bool reconnected); bool reconnected);

View file

@ -14,6 +14,7 @@
#include <lightningd/lightningd.h> #include <lightningd/lightningd.h>
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/options.h> #include <lightningd/options.h>
#include <lightningd/peer_comms.h>
#include <lightningd/peer_control.h> #include <lightningd/peer_control.h>
#include <lightningd/subd.h> #include <lightningd/subd.h>
@ -152,8 +153,7 @@ static unsigned closing_msg(struct subd *sd, const u8 *msg, const int *fds UNUSE
} }
void peer_start_closingd(struct channel *channel, void peer_start_closingd(struct channel *channel,
const struct crypto_state *cs, struct peer_comms *pcomms,
int peer_fd, int gossip_fd,
bool reconnected, bool reconnected,
const u8 *channel_reestablish) const u8 *channel_reestablish)
{ {
@ -183,7 +183,8 @@ void peer_start_closingd(struct channel *channel,
closing_wire_type_name, closing_msg, closing_wire_type_name, closing_msg,
channel_errmsg, channel_errmsg,
channel_set_billboard, channel_set_billboard,
take(&peer_fd), take(&gossip_fd), take(&pcomms->peer_fd),
take(&pcomms->gossip_fd),
take(&hsmfd), take(&hsmfd),
NULL), NULL),
false); false);
@ -263,7 +264,7 @@ void peer_start_closingd(struct channel *channel,
return; return;
} }
initmsg = towire_closing_init(tmpctx, initmsg = towire_closing_init(tmpctx,
cs, &pcomms->cs,
&channel->funding_txid, &channel->funding_txid,
channel->funding_outnum, channel->funding_outnum,
channel->funding, channel->funding,

View file

@ -5,10 +5,10 @@
struct channel_id; struct channel_id;
struct crypto_state; struct crypto_state;
struct peer_comms;
void peer_start_closingd(struct channel *channel, void peer_start_closingd(struct channel *channel,
const struct crypto_state *cs, struct peer_comms *pcomms,
int peer_fd, int gossip_fd,
bool reconnected, bool reconnected,
const u8 *channel_reestablish); const u8 *channel_reestablish);

View file

@ -376,8 +376,7 @@ static bool tell_if_missing(const struct channel *channel,
/* Only error onchaind can get is if it dies. */ /* Only error onchaind can get is if it dies. */
static void onchain_error(struct channel *channel, static void onchain_error(struct channel *channel,
int peer_fd UNUSED, int gossip_fd UNUSED, struct peer_comms *pcomms UNUSED,
const struct crypto_state *cs UNUSED,
const struct channel_id *channel_id UNUSED, const struct channel_id *channel_id UNUSED,
const char *desc, const char *desc,
const u8 *err_for_them UNUSED) const u8 *err_for_them UNUSED)

View file

@ -23,6 +23,7 @@
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/notification.h> #include <lightningd/notification.h>
#include <lightningd/opening_control.h> #include <lightningd/opening_control.h>
#include <lightningd/peer_comms.h>
#include <lightningd/peer_control.h> #include <lightningd/peer_control.h>
#include <lightningd/subd.h> #include <lightningd/subd.h>
#include <openingd/gen_opening_wire.h> #include <openingd/gen_opening_wire.h>
@ -290,7 +291,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
struct bitcoin_tx *fundingtx; struct bitcoin_tx *fundingtx;
struct bitcoin_txid funding_txid, expected_txid; struct bitcoin_txid funding_txid, expected_txid;
struct pubkey changekey; struct pubkey changekey;
struct crypto_state cs;
struct bitcoin_signature remote_commit_sig; struct bitcoin_signature remote_commit_sig;
struct bitcoin_tx *remote_commit; struct bitcoin_tx *remote_commit;
u16 funding_outnum; u16 funding_outnum;
@ -299,8 +299,11 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
struct channel *channel; struct channel *channel;
struct lightningd *ld = openingd->ld; struct lightningd *ld = openingd->ld;
u8 *remote_upfront_shutdown_script; u8 *remote_upfront_shutdown_script;
struct peer_comms *pcomms = new_peer_comms(resp);
assert(tal_count(fds) == 2); assert(tal_count(fds) == 2);
pcomms->peer_fd = fds[0];
pcomms->gossip_fd = fds[1];
/* This is a new channel_info.their_config so set its ID to 0 */ /* This is a new channel_info.their_config so set its ID to 0 */
channel_info.their_config.id = 0; channel_info.their_config.id = 0;
@ -309,7 +312,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
&channel_info.their_config, &channel_info.their_config,
&remote_commit, &remote_commit,
&remote_commit_sig, &remote_commit_sig,
&cs, &pcomms->cs,
&channel_info.theirbase.revocation, &channel_info.theirbase.revocation,
&channel_info.theirbase.payment, &channel_info.theirbase.payment,
&channel_info.theirbase.htlc, &channel_info.theirbase.htlc,
@ -455,7 +458,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
wallet_confirm_utxos(ld->wallet, fc->wtx.utxos); wallet_confirm_utxos(ld->wallet, fc->wtx.utxos);
/* Start normal channel daemon. */ /* Start normal channel daemon. */
peer_start_channeld(channel, &cs, fds[0], fds[1], NULL, false); peer_start_channeld(channel, pcomms, NULL, false);
subd_release_channel(openingd, fc->uc); subd_release_channel(openingd, fc->uc);
fc->uc->openingd = NULL; fc->uc->openingd = NULL;
@ -463,8 +466,6 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
return; return;
failed: failed:
close(fds[0]);
close(fds[1]);
subd_release_channel(openingd, fc->uc); subd_release_channel(openingd, fc->uc);
fc->uc->openingd = NULL; fc->uc->openingd = NULL;
/* Frees fc too, and tmpctx */ /* Frees fc too, and tmpctx */
@ -478,7 +479,6 @@ static void opening_fundee_finished(struct subd *openingd,
{ {
u8 *funding_signed; u8 *funding_signed;
struct channel_info channel_info; struct channel_info channel_info;
struct crypto_state cs;
struct bitcoin_signature remote_commit_sig; struct bitcoin_signature remote_commit_sig;
struct bitcoin_tx *remote_commit; struct bitcoin_tx *remote_commit;
struct lightningd *ld = openingd->ld; struct lightningd *ld = openingd->ld;
@ -490,9 +490,12 @@ static void opening_fundee_finished(struct subd *openingd,
u8 channel_flags; u8 channel_flags;
struct channel *channel; struct channel *channel;
u8 *remote_upfront_shutdown_script; u8 *remote_upfront_shutdown_script;
struct peer_comms *pcomms = new_peer_comms(reply);
log_debug(uc->log, "Got opening_fundee_finish_response"); log_debug(uc->log, "Got opening_fundee_finish_response");
assert(tal_count(fds) == 2); assert(tal_count(fds) == 2);
pcomms->peer_fd = fds[0];
pcomms->gossip_fd = fds[1];
/* This is a new channel_info.their_config, set its ID to 0 */ /* This is a new channel_info.their_config, set its ID to 0 */
channel_info.their_config.id = 0; channel_info.their_config.id = 0;
@ -501,7 +504,7 @@ static void opening_fundee_finished(struct subd *openingd,
&channel_info.their_config, &channel_info.their_config,
&remote_commit, &remote_commit,
&remote_commit_sig, &remote_commit_sig,
&cs, &pcomms->cs,
&channel_info.theirbase.revocation, &channel_info.theirbase.revocation,
&channel_info.theirbase.payment, &channel_info.theirbase.payment,
&channel_info.theirbase.htlc, &channel_info.theirbase.htlc,
@ -554,8 +557,7 @@ static void opening_fundee_finished(struct subd *openingd,
channel_watch_funding(ld, channel); channel_watch_funding(ld, channel);
/* On to normal operation! */ /* On to normal operation! */
peer_start_channeld(channel, &cs, peer_start_channeld(channel, pcomms, funding_signed, false);
fds[0], fds[1], funding_signed, false);
subd_release_channel(openingd, uc); subd_release_channel(openingd, uc);
uc->openingd = NULL; uc->openingd = NULL;
@ -592,16 +594,13 @@ static void opening_funder_failed(struct subd *openingd, const u8 *msg,
} }
static void opening_channel_errmsg(struct uncommitted_channel *uc, static void opening_channel_errmsg(struct uncommitted_channel *uc,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id UNUSED, const struct channel_id *channel_id UNUSED,
const char *desc, const char *desc,
const u8 *err_for_them UNUSED) const u8 *err_for_them UNUSED)
{ {
if (peer_fd != -1) { /* Close fds, if any. */
close(peer_fd); tal_free(pcomms);
close(gossip_fd);
}
uncommitted_channel_disconnect(uc, desc); uncommitted_channel_disconnect(uc, desc);
tal_free(uc); tal_free(uc);
} }
@ -774,8 +773,7 @@ static unsigned int openingd_msg(struct subd *openingd,
} }
void peer_start_openingd(struct peer *peer, void peer_start_openingd(struct peer *peer,
const struct crypto_state *cs, struct peer_comms *pcomms,
int peer_fd, int gossip_fd,
const u8 *send_msg) const u8 *send_msg)
{ {
int hsmfd; int hsmfd;
@ -799,7 +797,8 @@ void peer_start_openingd(struct peer *peer,
openingd_msg, openingd_msg,
opening_channel_errmsg, opening_channel_errmsg,
opening_channel_set_billboard, opening_channel_set_billboard,
take(&peer_fd), take(&gossip_fd), take(&pcomms->peer_fd),
take(&pcomms->gossip_fd),
take(&hsmfd), NULL); take(&hsmfd), NULL);
if (!uc->openingd) { if (!uc->openingd) {
uncommitted_channel_disconnect(uc, uncommitted_channel_disconnect(uc,
@ -826,7 +825,7 @@ void peer_start_openingd(struct peer *peer,
&uc->our_config, &uc->our_config,
max_to_self_delay, max_to_self_delay,
min_effective_htlc_capacity, min_effective_htlc_capacity,
cs, &uc->local_basepoints, &pcomms->cs, &uc->local_basepoints,
&uc->local_funding_pubkey, &uc->local_funding_pubkey,
uc->minimum_depth, uc->minimum_depth,
feerate_min(peer->ld, NULL), feerate_min(peer->ld, NULL),

View file

@ -7,14 +7,14 @@ struct channel_id;
struct crypto_state; struct crypto_state;
struct json_stream; struct json_stream;
struct lightningd; struct lightningd;
struct peer_comms;
struct uncommitted_channel; struct uncommitted_channel;
void json_add_uncommitted_channel(struct json_stream *response, void json_add_uncommitted_channel(struct json_stream *response,
const struct uncommitted_channel *uc); const struct uncommitted_channel *uc);
void peer_start_openingd(struct peer *peer, void peer_start_openingd(struct peer *peer,
const struct crypto_state *cs, struct peer_comms *pcomms,
int peer_fd, int gossip_fd,
const u8 *msg); const u8 *msg);
void opening_peer_no_active_channels(struct peer *peer); void opening_peer_no_active_channels(struct peer *peer);

18
lightningd/peer_comms.c Normal file
View file

@ -0,0 +1,18 @@
#include <lightningd/peer_comms.h>
#include <unistd.h>
static void destroy_peer_comms(struct peer_comms *pcomms)
{
if (pcomms->peer_fd != -1)
close(pcomms->peer_fd);
if (pcomms->gossip_fd != -1)
close(pcomms->gossip_fd);
}
struct peer_comms *new_peer_comms(const tal_t *ctx)
{
struct peer_comms *pcomms = tal(ctx, struct peer_comms);
tal_add_destructor(pcomms, destroy_peer_comms);
return pcomms;
}

16
lightningd/peer_comms.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef LIGHTNING_LIGHTNINGD_PEER_COMMS_H
#define LIGHTNING_LIGHTNINGD_PEER_COMMS_H
#include "config.h"
#include <ccan/tal/tal.h>
#include <common/crypto_state.h>
/* Things we hand between daemons to talk to peers. */
struct peer_comms {
struct crypto_state cs;
/* If not -1, closed on freeing */
int peer_fd, gossip_fd;
};
struct peer_comms *new_peer_comms(const tal_t *ctx);
#endif /* LIGHTNING_LIGHTNINGD_PEER_COMMS_H */

View file

@ -43,6 +43,7 @@
#include <lightningd/onchain_control.h> #include <lightningd/onchain_control.h>
#include <lightningd/opening_control.h> #include <lightningd/opening_control.h>
#include <lightningd/options.h> #include <lightningd/options.h>
#include <lightningd/peer_comms.h>
#include <lightningd/peer_htlcs.h> #include <lightningd/peer_htlcs.h>
#include <lightningd/plugin_hook.h> #include <lightningd/plugin_hook.h>
#include <unistd.h> #include <unistd.h>
@ -369,14 +370,13 @@ void drop_to_chain(struct lightningd *ld, struct channel *channel,
} }
void channel_errmsg(struct channel *channel, void channel_errmsg(struct channel *channel,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id UNUSED, const struct channel_id *channel_id UNUSED,
const char *desc, const char *desc,
const u8 *err_for_them) const u8 *err_for_them)
{ {
/* No peer fd means a subd crash or disconnection. */ /* No peer_comms means a subd crash or disconnection. */
if (peer_fd == -1) { if (!pcomms) {
channel_fail_transient(channel, "%s: %s", channel_fail_transient(channel, "%s: %s",
channel->owner->name, desc); channel->owner->name, desc);
return; return;
@ -418,12 +418,10 @@ void channel_errmsg(struct channel *channel,
struct peer_connected_hook_payload { struct peer_connected_hook_payload {
struct lightningd *ld; struct lightningd *ld;
struct crypto_state crypto_state;
struct channel *channel; struct channel *channel;
struct wireaddr_internal addr; struct wireaddr_internal addr;
struct peer *peer; struct peer *peer;
int peer_fd; struct peer_comms *pcomms;
int gossip_fd;
}; };
static void json_add_htlcs(struct lightningd *ld, static void json_add_htlcs(struct lightningd *ld,
@ -685,12 +683,9 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
const jsmntok_t *toks) const jsmntok_t *toks)
{ {
struct lightningd *ld = payload->ld; struct lightningd *ld = payload->ld;
struct crypto_state *cs = &payload->crypto_state;
struct channel *channel = payload->channel; struct channel *channel = payload->channel;
struct wireaddr_internal addr = payload->addr; struct wireaddr_internal addr = payload->addr;
struct peer *peer = payload->peer; struct peer *peer = payload->peer;
int gossip_fd = payload->gossip_fd;
int peer_fd = payload->peer_fd;
u8 *error; u8 *error;
/* If we had a hook, interpret result. */ /* If we had a hook, interpret result. */
@ -713,7 +708,6 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
buffer + m->start); buffer + m->start);
goto send_error; goto send_error;
} }
close(peer_fd);
tal_free(payload); tal_free(payload);
return; return;
} else if (!json_tok_streq(buffer, resulttok, "continue")) } else if (!json_tok_streq(buffer, resulttok, "continue"))
@ -766,8 +760,7 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
assert(!channel->owner); assert(!channel->owner);
channel->peer->addr = addr; channel->peer->addr = addr;
peer_start_channeld(channel, cs, peer_start_channeld(channel, payload->pcomms, NULL,
peer_fd, gossip_fd, NULL,
true); true);
tal_free(payload); tal_free(payload);
return; return;
@ -776,8 +769,7 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
assert(!channel->owner); assert(!channel->owner);
channel->peer->addr = addr; channel->peer->addr = addr;
peer_start_closingd(channel, cs, peer_start_closingd(channel, payload->pcomms,
peer_fd, gossip_fd,
true, NULL); true, NULL);
tal_free(payload); tal_free(payload);
return; return;
@ -791,7 +783,7 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
error = NULL; error = NULL;
send_error: send_error:
peer_start_openingd(peer, cs, peer_fd, gossip_fd, error); peer_start_openingd(peer, payload->pcomms, error);
tal_free(payload); tal_free(payload);
} }
@ -812,11 +804,13 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
hook_payload = tal(NULL, struct peer_connected_hook_payload); hook_payload = tal(NULL, struct peer_connected_hook_payload);
hook_payload->ld = ld; hook_payload->ld = ld;
hook_payload->gossip_fd = gossip_fd; hook_payload->pcomms = new_peer_comms(hook_payload);
hook_payload->peer_fd = peer_fd; hook_payload->pcomms->peer_fd = peer_fd;
hook_payload->pcomms->gossip_fd = gossip_fd;
if (!fromwire_connect_peer_connected(msg, msg, if (!fromwire_connect_peer_connected(msg, msg,
&id, &hook_payload->addr, &hook_payload->crypto_state, &id, &hook_payload->addr,
&hook_payload->pcomms->cs,
&globalfeatures, &localfeatures)) &globalfeatures, &localfeatures))
fatal("Connectd gave bad CONNECT_PEER_CONNECTED message %s", fatal("Connectd gave bad CONNECT_PEER_CONNECTED message %s",
tal_hex(msg, msg)); tal_hex(msg, msg));

View file

@ -15,7 +15,7 @@
#include <wallet/wallet.h> #include <wallet/wallet.h>
#include <wire/peer_wire.h> #include <wire/peer_wire.h>
struct crypto_state; struct peer_comms;
struct peer { struct peer {
/* Inside ld->peers. */ /* Inside ld->peers. */
@ -75,8 +75,7 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
#define OUR_CHANNEL_FLAGS CHANNEL_FLAGS_ANNOUNCE_CHANNEL #define OUR_CHANNEL_FLAGS CHANNEL_FLAGS_ANNOUNCE_CHANNEL
void channel_errmsg(struct channel *channel, void channel_errmsg(struct channel *channel,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const char *desc, const char *desc,
const u8 *err_for_them); const u8 *err_for_them);

View file

@ -16,6 +16,7 @@
#include <lightningd/lightningd.h> #include <lightningd/lightningd.h>
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/log_status.h> #include <lightningd/log_status.h>
#include <lightningd/peer_comms.h>
#include <lightningd/peer_control.h> #include <lightningd/peer_control.h>
#include <lightningd/subd.h> #include <lightningd/subd.h>
#include <signal.h> #include <signal.h>
@ -367,18 +368,20 @@ static bool handle_peer_error(struct subd *sd, const u8 *msg, int fds[2])
void *channel = sd->channel; void *channel = sd->channel;
struct channel_id channel_id; struct channel_id channel_id;
char *desc; char *desc;
struct crypto_state cs; struct peer_comms *pcomms = new_peer_comms(msg);
u8 *err_for_them; u8 *err_for_them;
if (!fromwire_status_peer_error(msg, msg, if (!fromwire_status_peer_error(msg, msg,
&channel_id, &desc, &channel_id, &desc,
&cs, &err_for_them)) &pcomms->cs, &err_for_them))
return false; return false;
/* Don't free sd; we're may be about to free channel. */ pcomms->peer_fd = fds[0];
pcomms->gossip_fd = fds[1];
/* Don't free sd; we may be about to free channel. */
sd->channel = NULL; sd->channel = NULL;
sd->errcb(channel, fds[0], fds[1], &cs, sd->errcb(channel, pcomms, &channel_id, desc, err_for_them);
&channel_id, desc, err_for_them);
return true; return true;
} }
@ -558,7 +561,7 @@ static void destroy_subd(struct subd *sd)
if (!outer_transaction) if (!outer_transaction)
db_begin_transaction(db); db_begin_transaction(db);
if (sd->errcb) if (sd->errcb)
sd->errcb(channel, -1, -1, NULL, NULL, sd->errcb(channel, NULL, NULL,
tal_fmt(sd, "Owning subdaemon %s died (%i)", tal_fmt(sd, "Owning subdaemon %s died (%i)",
sd->name, status), sd->name, status),
NULL); NULL);
@ -608,8 +611,7 @@ static struct subd *new_subd(struct lightningd *ld,
unsigned int (*msgcb)(struct subd *, unsigned int (*msgcb)(struct subd *,
const u8 *, const int *fds), const u8 *, const int *fds),
void (*errcb)(void *channel, void (*errcb)(void *channel,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const char *desc, const char *desc,
const u8 *err_for_them), const u8 *err_for_them),
@ -699,8 +701,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
unsigned int (*msgcb)(struct subd *, const u8 *, unsigned int (*msgcb)(struct subd *, const u8 *,
const int *fds), const int *fds),
void (*errcb)(void *channel, void (*errcb)(void *channel,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const char *desc, const char *desc,
const u8 *err_for_them), const u8 *err_for_them),

View file

@ -11,6 +11,7 @@
struct crypto_state; struct crypto_state;
struct io_conn; struct io_conn;
struct peer_comms;
/* By convention, replies are requests + 100 */ /* By convention, replies are requests + 100 */
#define SUBD_REPLY_OFFSET 100 #define SUBD_REPLY_OFFSET 100
@ -38,12 +39,11 @@ struct subd {
unsigned (*msgcb)(struct subd *, const u8 *, const int *); unsigned (*msgcb)(struct subd *, const u8 *, const int *);
const char *(*msgname)(int msgtype); const char *(*msgname)(int msgtype);
/* If peer_fd == -1, it was a disconnect/crash. Otherwise, /* If peer_comms == NULL, it was a disconnect/crash. Otherwise,
* sufficient information to hand back to gossipd, including the * sufficient information to hand back to gossipd, including the
* error message we sent them if any. */ * error message we sent them if any. */
void (*errcb)(void *channel, void (*errcb)(void *channel,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const char *desc, const char *desc,
const u8 *err_for_them); const u8 *err_for_them);
@ -117,8 +117,7 @@ struct subd *new_channel_subd_(struct lightningd *ld,
unsigned int (*msgcb)(struct subd *, const u8 *, unsigned int (*msgcb)(struct subd *, const u8 *,
const int *fds), const int *fds),
void (*errcb)(void *channel, void (*errcb)(void *channel,
int peer_fd, int gossip_fd, struct peer_comms *pcomms,
const struct crypto_state *cs,
const struct channel_id *channel_id, const struct channel_id *channel_id,
const char *desc, const char *desc,
const u8 *err_for_them), const u8 *err_for_them),
@ -131,8 +130,8 @@ struct subd *new_channel_subd_(struct lightningd *ld,
new_channel_subd_((ld), (name), (channel), (log), (talks_to_peer), \ new_channel_subd_((ld), (name), (channel), (log), (talks_to_peer), \
(msgname), (msgcb), \ (msgname), (msgcb), \
typesafe_cb_postargs(void, void *, (errcb), \ typesafe_cb_postargs(void, void *, (errcb), \
(channel), int, int, \ (channel), \
const struct crypto_state *, \ struct peer_comms *, \
const struct channel_id *, \ const struct channel_id *, \
const char *, const u8 *), \ const char *, const u8 *), \
typesafe_cb_postargs(void, void *, (billboardcb), \ typesafe_cb_postargs(void, void *, (billboardcb), \

View file

@ -124,6 +124,9 @@ struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
struct log_book *new_log_book(size_t max_mem UNNEEDED, struct log_book *new_log_book(size_t max_mem UNNEEDED,
enum log_level printlevel UNNEEDED) enum log_level printlevel UNNEEDED)
{ fprintf(stderr, "new_log_book called!\n"); abort(); } { fprintf(stderr, "new_log_book called!\n"); abort(); }
/* Generated stub for new_peer_comms */
struct peer_comms *new_peer_comms(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "new_peer_comms called!\n"); abort(); }
/* Generated stub for new_topology */ /* Generated stub for new_topology */
struct chain_topology *new_topology(struct lightningd *ld UNNEEDED, struct log *log UNNEEDED) struct chain_topology *new_topology(struct lightningd *ld UNNEEDED, struct log *log UNNEEDED)
{ fprintf(stderr, "new_topology called!\n"); abort(); } { fprintf(stderr, "new_topology called!\n"); abort(); }

View file

@ -260,6 +260,9 @@ struct log *new_log(const tal_t *ctx UNNEEDED, struct log_book *record UNNEEDED,
struct log_book *new_log_book(size_t max_mem UNNEEDED, struct log_book *new_log_book(size_t max_mem UNNEEDED,
enum log_level printlevel UNNEEDED) enum log_level printlevel UNNEEDED)
{ fprintf(stderr, "new_log_book called!\n"); abort(); } { fprintf(stderr, "new_log_book called!\n"); abort(); }
/* Generated stub for new_peer_comms */
struct peer_comms *new_peer_comms(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "new_peer_comms called!\n"); abort(); }
/* Generated stub for new_reltimer_ */ /* Generated stub for new_reltimer_ */
struct oneshot *new_reltimer_(struct timers *timers UNNEEDED, struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
const tal_t *ctx UNNEEDED, const tal_t *ctx UNNEEDED,
@ -367,22 +370,19 @@ void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDE
{ fprintf(stderr, "peer_memleak_done called!\n"); abort(); } { fprintf(stderr, "peer_memleak_done called!\n"); abort(); }
/* Generated stub for peer_start_channeld */ /* Generated stub for peer_start_channeld */
void peer_start_channeld(struct channel *channel UNNEEDED, void peer_start_channeld(struct channel *channel UNNEEDED,
const struct crypto_state *cs UNNEEDED, struct peer_comms *pcomms UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
const u8 *funding_signed UNNEEDED, const u8 *funding_signed UNNEEDED,
bool reconnected UNNEEDED) bool reconnected UNNEEDED)
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); } { fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
/* Generated stub for peer_start_closingd */ /* Generated stub for peer_start_closingd */
void peer_start_closingd(struct channel *channel UNNEEDED, void peer_start_closingd(struct channel *channel UNNEEDED,
const struct crypto_state *cs UNNEEDED, struct peer_comms *pcomms UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
bool reconnected UNNEEDED, bool reconnected UNNEEDED,
const u8 *channel_reestablish UNNEEDED) const u8 *channel_reestablish UNNEEDED)
{ fprintf(stderr, "peer_start_closingd called!\n"); abort(); } { fprintf(stderr, "peer_start_closingd called!\n"); abort(); }
/* Generated stub for peer_start_openingd */ /* Generated stub for peer_start_openingd */
void peer_start_openingd(struct peer *peer UNNEEDED, void peer_start_openingd(struct peer *peer UNNEEDED,
const struct crypto_state *cs UNNEEDED, struct peer_comms *pcomms UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
const u8 *msg UNNEEDED) const u8 *msg UNNEEDED)
{ fprintf(stderr, "peer_start_openingd called!\n"); abort(); } { fprintf(stderr, "peer_start_openingd called!\n"); abort(); }
/* Generated stub for plugin_hook_call_ */ /* Generated stub for plugin_hook_call_ */

View file

@ -329,6 +329,9 @@ void log_add(struct log *log UNNEEDED, const char *fmt UNNEEDED, ...)
void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED, const char *comment UNNEEDED, void log_io(struct log *log UNNEEDED, enum log_level dir UNNEEDED, const char *comment UNNEEDED,
const void *data UNNEEDED, size_t len UNNEEDED) const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "log_io called!\n"); abort(); } { fprintf(stderr, "log_io called!\n"); abort(); }
/* Generated stub for new_peer_comms */
struct peer_comms *new_peer_comms(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "new_peer_comms called!\n"); abort(); }
/* Generated stub for notify_connect */ /* Generated stub for notify_connect */
void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED, void notify_connect(struct lightningd *ld UNNEEDED, struct node_id *nodeid UNNEEDED,
struct wireaddr_internal *addr UNNEEDED) struct wireaddr_internal *addr UNNEEDED)
@ -432,22 +435,19 @@ void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDE
{ fprintf(stderr, "peer_memleak_done called!\n"); abort(); } { fprintf(stderr, "peer_memleak_done called!\n"); abort(); }
/* Generated stub for peer_start_channeld */ /* Generated stub for peer_start_channeld */
void peer_start_channeld(struct channel *channel UNNEEDED, void peer_start_channeld(struct channel *channel UNNEEDED,
const struct crypto_state *cs UNNEEDED, struct peer_comms *pcomms UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
const u8 *funding_signed UNNEEDED, const u8 *funding_signed UNNEEDED,
bool reconnected UNNEEDED) bool reconnected UNNEEDED)
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); } { fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
/* Generated stub for peer_start_closingd */ /* Generated stub for peer_start_closingd */
void peer_start_closingd(struct channel *channel UNNEEDED, void peer_start_closingd(struct channel *channel UNNEEDED,
const struct crypto_state *cs UNNEEDED, struct peer_comms *pcomms UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
bool reconnected UNNEEDED, bool reconnected UNNEEDED,
const u8 *channel_reestablish UNNEEDED) const u8 *channel_reestablish UNNEEDED)
{ fprintf(stderr, "peer_start_closingd called!\n"); abort(); } { fprintf(stderr, "peer_start_closingd called!\n"); abort(); }
/* Generated stub for peer_start_openingd */ /* Generated stub for peer_start_openingd */
void peer_start_openingd(struct peer *peer UNNEEDED, void peer_start_openingd(struct peer *peer UNNEEDED,
const struct crypto_state *cs UNNEEDED, struct peer_comms *pcomms UNNEEDED,
int peer_fd UNNEEDED, int gossip_fd UNNEEDED,
const u8 *msg UNNEEDED) const u8 *msg UNNEEDED)
{ fprintf(stderr, "peer_start_openingd called!\n"); abort(); } { fprintf(stderr, "peer_start_openingd called!\n"); abort(); }
/* Generated stub for plugin_hook_call_ */ /* Generated stub for plugin_hook_call_ */