From 0ff91e65dc602641461fcb5f76f1bcbc4f8b2c11 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 21 Sep 2023 15:06:26 +0930 Subject: [PATCH] connectd: remove #if DEVELOPER We still refuse to run dev commands if lightningd sends it to us despite us not being in developer mode, but that's mainly paranoia. Signed-off-by: Rusty Russell --- connectd/connectd.c | 42 +++++++++++--------------------- connectd/connectd.h | 7 +----- connectd/multiplex.c | 20 ++++++--------- connectd/peer_exchange_initmsg.c | 19 ++++++--------- 4 files changed, 29 insertions(+), 59 deletions(-) diff --git a/connectd/connectd.c b/connectd/connectd.c index 5484a9f11..e1fe5afa4 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -251,11 +251,8 @@ static struct peer *new_peer(struct daemon *daemon, peer->peer_outq = msg_queue_new(peer, false); peer->last_recv_time = time_now(); peer->is_websocket = is_websocket; - -#if DEVELOPER peer->dev_writes_enabled = NULL; peer->dev_read_enabled = true; -#endif peer->to_peer = conn; @@ -1407,8 +1404,7 @@ static void connect_init(struct daemon *daemon, const u8 *msg) enum addr_listen_announce *proposed_listen_announce; struct wireaddr *announceable; char *tor_password; - bool dev_fast_gossip; - bool dev_disconnect, dev_no_ping_timer; + bool dev_disconnect; char *errstr; /* Fields which require allocation are allocated off daemon */ @@ -1426,21 +1422,14 @@ static void connect_init(struct daemon *daemon, const u8 *msg) &daemon->websocket_helper, &daemon->websocket_port, &daemon->announce_websocket, - &dev_fast_gossip, + &daemon->dev_fast_gossip, &dev_disconnect, - &dev_no_ping_timer)) { + &daemon->dev_no_ping_timer)) { /* This is a helper which prints the type expected and the actual * message, then exits (it should never be called!). */ master_badmsg(WIRE_CONNECTD_INIT, msg); } -#if DEVELOPER - /*~ Clearly mark these as developer-only flags! */ - daemon->dev_fast_gossip = dev_fast_gossip; - daemon->dev_no_ping_timer = dev_no_ping_timer; - daemon->dev_suppress_gossip = false; -#endif - if (!pubkey_from_node_id(&daemon->mykey, &daemon->id)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Invalid id for me %s", @@ -1496,14 +1485,12 @@ static void connect_init(struct daemon *daemon, const u8 *msg) * not always a real problem), and this would (did!) trigger it. */ tal_free(announceable); -#if DEVELOPER if (dev_disconnect) { daemon->dev_disconnect_fd = 5; dev_disconnect_init(5); } else { daemon->dev_disconnect_fd = -1; } -#endif } /* Returning functions in C is ugly! */ @@ -1880,7 +1867,6 @@ static void dev_connect_memleak(struct daemon *daemon, const u8 *msg) found_leak))); } -#if DEVELOPER static void dev_suppress_gossip(struct daemon *daemon, const u8 *msg) { daemon->dev_suppress_gossip = true; @@ -1987,12 +1973,10 @@ static void dev_report_fds(struct daemon *daemon, const u8 *msg) status_info("dev_report_fds: %i -> gossipd fd", fd); continue; } -#if DEVELOPER if (fd == daemon->dev_disconnect_fd) { status_info("dev_report_fds: %i -> dev_disconnect_fd", fd); continue; } -#endif if (fd == daemon->gossip_store_fd) { status_info("dev_report_fds: %i -> gossip_store", fd); continue; @@ -2020,7 +2004,6 @@ static void dev_report_fds(struct daemon *daemon, const u8 *msg) describe_fd(fd); } } -#endif /* DEVELOPER */ static struct io_plan *recv_peer_connect_subd(struct io_conn *conn, const u8 *msg, @@ -2088,15 +2071,17 @@ static struct io_plan *recv_req(struct io_conn *conn, } /* Fall thru */ case WIRE_CONNECTD_DEV_SUPPRESS_GOSSIP: -#if DEVELOPER - dev_suppress_gossip(daemon, msg); - goto out; -#endif + if (daemon->developer) { + dev_suppress_gossip(daemon, msg); + goto out; + } + /* Fall thru */ case WIRE_CONNECTD_DEV_REPORT_FDS: -#if DEVELOPER - dev_report_fds(daemon, msg); - goto out; -#endif + if (daemon->developer) { + dev_report_fds(daemon, msg); + goto out; + } + /* Fall thru */ /* We send these, we don't receive them */ case WIRE_CONNECTD_INIT_REPLY: case WIRE_CONNECTD_ACTIVATE_REPLY: @@ -2187,6 +2172,7 @@ int main(int argc, char *argv[]) timers_init(&daemon->timers, time_mono()); daemon->gossip_store_fd = -1; daemon->shutting_down = false; + daemon->dev_suppress_gossip = false; /* stdin == control */ daemon->master = daemon_conn_new(daemon, STDIN_FILENO, recv_req, NULL, diff --git a/connectd/connectd.h b/connectd/connectd.h index 1161784d0..a6d30bdcb 100644 --- a/connectd/connectd.h +++ b/connectd/connectd.h @@ -90,11 +90,9 @@ struct peer { /* Last time we received traffic */ struct timeabs last_recv_time; -#if DEVELOPER bool dev_read_enabled; /* If non-NULL, this counts down; 0 means disable */ u32 *dev_writes_enabled; -#endif }; /*~ The HTABLE_DEFINE_TYPE() macro needs a keyof() function to extract the key: @@ -155,8 +153,7 @@ struct daemon { /* Any listening sockets we have. */ struct io_listener **listeners; - /* Allow localhost to be considered "public": DEVELOPER-only option, - * but for simplicity we don't #if DEVELOPER-wrap it here. */ + /* Allow localhost to be considered "public", only with --developer */ bool dev_allow_localhost; /* We support use of a SOCKS5 proxy (e.g. Tor) */ @@ -197,7 +194,6 @@ struct daemon { /* Shutting down, don't send new stuff */ bool shutting_down; -#if DEVELOPER /* Hack to speed up gossip timer */ bool dev_fast_gossip; /* Hack to avoid ping timeouts */ @@ -206,7 +202,6 @@ struct daemon { bool dev_suppress_gossip; /* dev_disconnect file */ int dev_disconnect_fd; -#endif }; /* Called by io_tor_connect once it has a connection out. */ diff --git a/connectd/multiplex.c b/connectd/multiplex.c index 5f535f839..2a7a29529 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -273,7 +273,7 @@ void setup_peer_gossip_store(struct peer *peer, } peer->gs.gossip_timer = gossip_stream_timer(peer); - peer->gs.active = IFDEV(!peer->daemon->dev_suppress_gossip, true); + peer->gs.active = !peer->daemon->dev_suppress_gossip; peer->gs.timestamp_min = 0; peer->gs.timestamp_max = UINT32_MAX; @@ -338,7 +338,7 @@ static void set_urgent_flag(struct peer *peer, bool urgent) if (setsockopt(io_conn_fd(peer->to_peer), IPPROTO_TCP, opt, &val, sizeof(val)) != 0 /* This actually happens in testing, where we blackhole the fd */ - && IFDEV(peer->daemon->dev_disconnect_fd == -1, true)) { + && peer->daemon->dev_disconnect_fd == -1) { status_broken("setsockopt %s=1 fd=%u: %s", optname, io_conn_fd(peer->to_peer), strerror(errno)); @@ -421,7 +421,6 @@ static struct io_plan *encrypt_and_send(struct peer *peer, { int type = fromwire_peektype(msg); -#if DEVELOPER switch (dev_disconnect(&peer->id, type)) { case DEV_DISCONNECT_BEFORE: if (taken(msg)) @@ -445,7 +444,7 @@ static struct io_plan *encrypt_and_send(struct peer *peer, *peer->dev_writes_enabled = 1; break; } -#endif + set_urgent_flag(peer, is_urgent(type)); /* We are no longer required to do this, but we do disconnect @@ -471,8 +470,6 @@ static struct io_plan *encrypt_and_send(struct peer *peer, static void wake_gossip(struct peer *peer) { bool flush_gossip_filter = true; - -#if DEVELOPER /* With dev-fast-gossip, we clean every 2 seconds, which is too * fast for our slow tests! So we only call this one time in 5 * actually twice that, as it's not per-peer! */ @@ -480,13 +477,12 @@ static void wake_gossip(struct peer *peer) if (peer->daemon->dev_fast_gossip && gossip_age_count++ % 5 != 0) flush_gossip_filter = false; -#endif /* Don't remember sent per-peer gossip forever. */ if (flush_gossip_filter) gossip_rcvd_filter_age(peer->gs.grf); - peer->gs.active = IFDEV(!peer->daemon->dev_suppress_gossip, true); + peer->gs.active = !peer->daemon->dev_suppress_gossip; io_wake(peer->peer_outq); /* And go again in 60 seconds (from now, now when we finish!) */ @@ -499,7 +495,7 @@ static u8 *maybe_from_gossip_store(const tal_t *ctx, struct peer *peer) u8 *msg; /* dev-mode can suppress all gossip */ - if (IFDEV(peer->daemon->dev_suppress_gossip, false)) + if (peer->daemon->dev_suppress_gossip) return NULL; /* Not streaming right now? */ @@ -535,7 +531,7 @@ static void send_ping(struct peer *peer); static void set_ping_timer(struct peer *peer) { - if (IFDEV(peer->daemon->dev_no_ping_timer, false)) { + if (peer->daemon->dev_no_ping_timer) { peer->ping_timer = NULL; return; } @@ -963,7 +959,6 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn, } /* dev_disconnect can disable writes */ -#if DEVELOPER if (peer->dev_writes_enabled) { if (*peer->dev_writes_enabled == 0) { tal_free(msg); @@ -972,7 +967,6 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn, } (*peer->dev_writes_enabled)--; } -#endif return encrypt_and_send(peer, take(msg), write_to_peer); } @@ -1083,7 +1077,7 @@ static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn, tal_free(peer->peer_in); /* dev_disconnect can disable read */ - if (!IFDEV(peer->dev_read_enabled, true)) + if (!peer->dev_read_enabled) return read_hdr_from_peer(peer_conn, peer); /* We got something! */ diff --git a/connectd/peer_exchange_initmsg.c b/connectd/peer_exchange_initmsg.c index 55f73107b..b87f8a291 100644 --- a/connectd/peer_exchange_initmsg.c +++ b/connectd/peer_exchange_initmsg.c @@ -110,8 +110,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn, case ADDR_TYPE_IPV6: /* Drop non-public addresses when not testing */ if (!address_routable(remote_addr, - IFDEV(peer->daemon->dev_allow_localhost, - false))) + peer->daemon->dev_allow_localhost)) remote_addr = tal_free(remote_addr); break; /* We are only interested in IP addresses */ @@ -172,21 +171,19 @@ static struct io_plan *read_init(struct io_conn *conn, struct early_peer *peer) peer_init_hdr_received, peer); } -#if DEVELOPER -static struct io_plan *peer_write_postclose(struct io_conn *conn, - struct early_peer *peer) +static struct io_plan *dev_peer_write_postclose(struct io_conn *conn, + struct early_peer *peer) { dev_sabotage_fd(io_conn_fd(conn), true); return read_init(conn, peer); } -static struct io_plan *peer_write_post_sabotage(struct io_conn *conn, - struct early_peer *peer) +static struct io_plan *dev_peer_write_post_sabotage(struct io_conn *conn, + struct early_peer *peer) { dev_sabotage_fd(io_conn_fd(conn), false); return read_init(conn, peer); } -#endif struct io_plan *peer_exchange_initmsg(struct io_conn *conn, struct daemon *daemon, @@ -279,13 +276,12 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn, peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg)); next = read_init; -#if DEVELOPER switch (dev_disconnect(&peer->id, WIRE_INIT)) { case DEV_DISCONNECT_BEFORE: dev_sabotage_fd(io_conn_fd(conn), true); break; case DEV_DISCONNECT_AFTER: - next = peer_write_postclose; + next = dev_peer_write_postclose; break; case DEV_DISCONNECT_BLACKHOLE: status_failed(STATUS_FAIL_INTERNAL_ERROR, @@ -294,10 +290,9 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn, case DEV_DISCONNECT_NORMAL: break; case DEV_DISCONNECT_DISABLE_AFTER: - next = peer_write_post_sabotage; + next = dev_peer_write_post_sabotage; break; } -#endif /* DEVELOPER */ return io_write(conn, peer->msg, tal_bytelen(peer->msg), next, peer); }