diff --git a/daemon/packets.c b/daemon/packets.c index 48067e144..66b080df9 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -72,7 +72,9 @@ static void queue_raw_pkt(struct peer *peer, Pkt *pkt) { size_t n = tal_count(peer->outpkt); tal_resize(&peer->outpkt, n+1); - peer->outpkt[n] = pkt; + peer->outpkt[n].pkt = pkt; + peer->outpkt[n].ack_cb = NULL; + peer->outpkt[n].ack_arg = NULL; /* In case it was waiting for output. */ io_wake(peer); diff --git a/daemon/peer.c b/daemon/peer.c index 07b35ad3f..3cae60fca 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -136,7 +136,7 @@ static void state_single(struct peer *peer, } if (tal_count(peer->outpkt) > old_outpkts) { - Pkt *outpkt = peer->outpkt[old_outpkts]; + Pkt *outpkt = peer->outpkt[old_outpkts].pkt; log_add(peer->log, " (out %s)", input_name(outpkt->pkt_case)); } if (broadcast) { @@ -224,7 +224,7 @@ static void state_event(struct peer *peer, static struct io_plan *pkt_out(struct io_conn *conn, struct peer *peer) { - Pkt *out; + struct out_pkt out; size_t n = tal_count(peer->outpkt); if (n == 0) { @@ -237,7 +237,8 @@ static struct io_plan *pkt_out(struct io_conn *conn, struct peer *peer) out = peer->outpkt[0]; memmove(peer->outpkt, peer->outpkt + 1, (sizeof(*peer->outpkt)*(n-1))); tal_resize(&peer->outpkt, n-1); - return peer_write_packet(conn, peer, out, NULL, NULL, pkt_out); + return peer_write_packet(conn, peer, out.pkt, out.ack_cb, out.ack_arg, + pkt_out); } static struct io_plan *pkt_in(struct io_conn *conn, struct peer *peer) @@ -341,7 +342,7 @@ static struct peer *new_peer(struct lightningd_state *dstate, peer->io_data = NULL; peer->secrets = NULL; list_head_init(&peer->watches); - peer->outpkt = tal_arr(peer, Pkt *, 0); + peer->outpkt = tal_arr(peer, struct out_pkt, 0); peer->curr_cmd.cmd = INPUT_NONE; list_head_init(&peer->pending_cmd); peer->current_htlc = NULL; diff --git a/daemon/peer.h b/daemon/peer.h index b0ae5c9eb..c3d60355a 100644 --- a/daemon/peer.h +++ b/daemon/peer.h @@ -73,6 +73,12 @@ struct htlc_progress { struct bitcoin_signature their_sig; }; +struct out_pkt { + Pkt *pkt; + void (*ack_cb)(struct peer *peer, void *arg); + void *ack_arg; +}; + struct peer { /* dstate->peers list */ struct list_node list; @@ -112,7 +118,7 @@ struct peer { Pkt *inpkt; /* Queue of output packets. */ - Pkt **outpkt; + struct out_pkt *outpkt; /* Anchor tx output */ struct {