mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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 <rusty@rustcorp.com.au>
This commit is contained in:
parent
5637564cd4
commit
bdc41f00f3
@ -68,12 +68,6 @@ struct peer {
|
|||||||
secp256k1_ecdsa_signature announcement_bitcoin_sigs[NUM_SIDES];
|
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,
|
static struct io_plan *gossip_client_recv(struct io_conn *conn,
|
||||||
struct daemon_conn *dc)
|
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 ||
|
if (type == WIRE_CHANNEL_ANNOUNCEMENT || type == WIRE_CHANNEL_UPDATE ||
|
||||||
type == WIRE_NODE_ANNOUNCEMENT)
|
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);
|
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,
|
msg = towire_announcement_signatures(tmpctx, &peer->channel_id,
|
||||||
&peer->short_channel_ids[LOCAL],
|
&peer->short_channel_ids[LOCAL],
|
||||||
sig, sig);
|
sig, sig);
|
||||||
queue_pkt(peer, take(msg));
|
msg_enqueue(&peer->peer_out, take(msg));
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +136,8 @@ static void announce_channel(struct peer *peer)
|
|||||||
tmpctx, sig, &peer->short_channel_ids[LOCAL], timestamp, flags, 36,
|
tmpctx, sig, &peer->short_channel_ids[LOCAL], timestamp, flags, 36,
|
||||||
1, 10, peer->channel->view[LOCAL].feerate_per_kw);
|
1, 10, peer->channel->view[LOCAL].feerate_per_kw);
|
||||||
|
|
||||||
queue_pkt(peer, cannounce);
|
msg_enqueue(&peer->peer_out, cannounce);
|
||||||
queue_pkt(peer, cupdate);
|
msg_enqueue(&peer->peer_out, cupdate);
|
||||||
|
|
||||||
daemon_conn_send(&peer->gossip_client, take(cannounce));
|
daemon_conn_send(&peer->gossip_client, take(cannounce));
|
||||||
daemon_conn_send(&peer->gossip_client, take(cupdate));
|
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);
|
const u8 *out = msg_dequeue(&peer->peer_out);
|
||||||
if (!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);
|
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,
|
u8 *msg = towire_funding_locked(peer,
|
||||||
&peer->channel_id,
|
&peer->channel_id,
|
||||||
&peer->next_per_commit[LOCAL]);
|
&peer->next_per_commit[LOCAL]);
|
||||||
queue_pkt(peer, msg);
|
msg_enqueue(&peer->peer_out, take(msg));
|
||||||
peer->funding_locked[LOCAL] = true;
|
peer->funding_locked[LOCAL] = true;
|
||||||
send_announcement_signatures(peer);
|
send_announcement_signatures(peer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user