From bdc41f00f32c343008420548e81c16b425f13cd8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 20 Mar 2017 07:02:44 +1030 Subject: [PATCH] lightningd/channel: use msg_queue properly for peer. Use msg_enqueue's wake and msg_queue_wait, and don't clone packets since msg_enqueue() respects take. Signed-off-by: Rusty Russell --- lightningd/channel/channel.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lightningd/channel/channel.c b/lightningd/channel/channel.c index 763c31cb3..143b65b64 100644 --- a/lightningd/channel/channel.c +++ b/lightningd/channel/channel.c @@ -68,12 +68,6 @@ struct peer { secp256k1_ecdsa_signature announcement_bitcoin_sigs[NUM_SIDES]; }; -static void queue_pkt(struct peer *peer, const u8 *msg) -{ - msg_enqueue(&peer->peer_out, msg); - io_wake(peer); -} - static struct io_plan *gossip_client_recv(struct io_conn *conn, struct daemon_conn *dc) { @@ -83,7 +77,7 @@ static struct io_plan *gossip_client_recv(struct io_conn *conn, if (type == WIRE_CHANNEL_ANNOUNCEMENT || type == WIRE_CHANNEL_UPDATE || type == WIRE_NODE_ANNOUNCEMENT) - queue_pkt(peer, tal_dup_arr(dc->ctx, u8, msg, tal_len(msg), 0)); + msg_enqueue(&peer->peer_out, msg); return daemon_conn_read_next(conn, dc); } @@ -99,7 +93,7 @@ static void send_announcement_signatures(struct peer *peer) msg = towire_announcement_signatures(tmpctx, &peer->channel_id, &peer->short_channel_ids[LOCAL], sig, sig); - queue_pkt(peer, take(msg)); + msg_enqueue(&peer->peer_out, take(msg)); tal_free(tmpctx); } @@ -142,8 +136,8 @@ static void announce_channel(struct peer *peer) tmpctx, sig, &peer->short_channel_ids[LOCAL], timestamp, flags, 36, 1, 10, peer->channel->view[LOCAL].feerate_per_kw); - queue_pkt(peer, cannounce); - queue_pkt(peer, cupdate); + msg_enqueue(&peer->peer_out, cannounce); + msg_enqueue(&peer->peer_out, cupdate); daemon_conn_send(&peer->gossip_client, take(cannounce)); daemon_conn_send(&peer->gossip_client, take(cupdate)); @@ -155,7 +149,7 @@ static struct io_plan *peer_out(struct io_conn *conn, struct peer *peer) { const u8 *out = msg_dequeue(&peer->peer_out); if (!out) - return io_out_wait(conn, peer, peer_out, peer); + return msg_queue_wait(conn, &peer->peer_out, peer_out, peer); return peer_write_message(conn, &peer->pcs, out, peer_out); } @@ -277,7 +271,7 @@ static struct io_plan *req_in(struct io_conn *conn, struct daemon_conn *master) u8 *msg = towire_funding_locked(peer, &peer->channel_id, &peer->next_per_commit[LOCAL]); - queue_pkt(peer, msg); + msg_enqueue(&peer->peer_out, take(msg)); peer->funding_locked[LOCAL] = true; send_announcement_signatures(peer);