From d02bc736e6023f940530153f28b194c7689fc864 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 21 Jan 2022 15:27:02 +1030 Subject: [PATCH] connectd: don't received useless peer fd if we're told to send final msg. We don't need the connection to ourselves! Signed-off-by: Rusty Russell --- connectd/connectd.c | 11 ----------- connectd/connectd_wire.csv | 2 +- lightningd/opening_common.c | 4 +--- lightningd/peer_control.c | 4 +--- lightningd/test/run-invoice-select-inchan.c | 3 --- wallet/test/run-wallet.c | 3 --- 6 files changed, 3 insertions(+), 24 deletions(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index 136add063f65..3c55b613b3c3 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -1846,21 +1846,10 @@ static void peer_final_msg(struct io_conn *conn, struct peer *peer; struct node_id id; u8 *finalmsg; - int peer_fd; if (!fromwire_connectd_peer_final_msg(tmpctx, msg, &id, &finalmsg)) master_badmsg(WIRE_CONNECTD_PEER_FINAL_MSG, msg); - /* Get the peer_fd for this peer: we don't need it though! */ - io_fd_block(io_conn_fd(conn), true); - peer_fd = fdpass_recv(io_conn_fd(conn)); - if (peer_fd == -1) - status_failed(STATUS_FAIL_MASTER_IO, - "Getting peer fd after peer_final_msg: %s", - strerror(errno)); - close(peer_fd); - io_fd_block(io_conn_fd(conn), false); - /* This can happen if peer hung up on us. */ peer = peer_htable_get(&daemon->peers, &id); if (peer) { diff --git a/connectd/connectd_wire.csv b/connectd/connectd_wire.csv index c735f3c93173..7632a2840e43 100644 --- a/connectd/connectd_wire.csv +++ b/connectd/connectd_wire.csv @@ -72,7 +72,7 @@ msgdata,connectd_peer_connected,features,u8,flen msgtype,connectd_peer_disconnected,2015 msgdata,connectd_peer_disconnected,id,node_id, -# master -> connectd: give message to peer and disconnect. Plus fd for peer +# master -> connectd: give message to peer and disconnect. msgtype,connectd_peer_final_msg,2003 msgdata,connectd_peer_final_msg,id,node_id, msgdata,connectd_peer_final_msg,len,u16, diff --git a/lightningd/opening_common.c b/lightningd/opening_common.c index 7afc8b4b4996..46087c13819e 100644 --- a/lightningd/opening_common.c +++ b/lightningd/opening_common.c @@ -194,9 +194,7 @@ void handle_reestablish(struct lightningd *ld, subd_send_msg(ld->connectd, take(towire_connectd_peer_final_msg(NULL, peer_id, err))); - subd_send_fd(ld->connectd, peer_fd->fd); - /* Don't close this fd! */ - peer_fd->fd = -1; + tal_free(peer_fd); } } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index ec594fad6d36..5d7627011ba4 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1052,9 +1052,7 @@ static void peer_connected_hook_final(struct peer_connected_hook_payload *payloa subd_send_msg(ld->connectd, take(towire_connectd_peer_final_msg(NULL, &peer->id, error))); - subd_send_fd(ld->connectd, payload->peer_fd->fd); - /* Don't close the fd! */ - payload->peer_fd->fd = -1; + tal_free(payload->peer_fd); } static bool diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 8d787bbdca2c..d55ec8384eb7 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -603,9 +603,6 @@ void subd_req_(const tal_t *ctx UNNEEDED, void (*replycb)(struct subd * UNNEEDED, const u8 * UNNEEDED, const int * UNNEEDED, void *) UNNEEDED, void *replycb_data UNNEEDED) { fprintf(stderr, "subd_req_ called!\n"); abort(); } -/* Generated stub for subd_send_fd */ -void subd_send_fd(struct subd *sd UNNEEDED, int fd UNNEEDED) -{ fprintf(stderr, "subd_send_fd called!\n"); abort(); } /* Generated stub for subd_send_msg */ void subd_send_msg(struct subd *sd UNNEEDED, const u8 *msg_out UNNEEDED) { fprintf(stderr, "subd_send_msg called!\n"); abort(); } diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index eac5f34d5a49..a6605b25af3f 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -642,9 +642,6 @@ void subd_req_(const tal_t *ctx UNNEEDED, void (*replycb)(struct subd * UNNEEDED, const u8 * UNNEEDED, const int * UNNEEDED, void *) UNNEEDED, void *replycb_data UNNEEDED) { fprintf(stderr, "subd_req_ called!\n"); abort(); } -/* Generated stub for subd_send_fd */ -void subd_send_fd(struct subd *sd UNNEEDED, int fd UNNEEDED) -{ fprintf(stderr, "subd_send_fd called!\n"); abort(); } /* Generated stub for subd_send_msg */ void subd_send_msg(struct subd *sd UNNEEDED, const u8 *msg_out UNNEEDED) { fprintf(stderr, "subd_send_msg called!\n"); abort(); }