Skip to content

Commit

Permalink
connectd: don't received useless peer fd if we're told to send final …
Browse files Browse the repository at this point in the history
…msg.

We don't need the connection to ourselves!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jan 21, 2022
1 parent 681598a commit d02bc73
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 24 deletions.
11 changes: 0 additions & 11 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion connectd/connectd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lightningd/opening_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 1 addition & 3 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
3 changes: 0 additions & 3 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down

0 comments on commit d02bc73

Please sign in to comment.