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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-09-21 15:06:26 +09:30
parent 91b5a3b323
commit 0ff91e65dc
4 changed files with 29 additions and 59 deletions

View file

@ -251,11 +251,8 @@ static struct peer *new_peer(struct daemon *daemon,
peer->peer_outq = msg_queue_new(peer, false); peer->peer_outq = msg_queue_new(peer, false);
peer->last_recv_time = time_now(); peer->last_recv_time = time_now();
peer->is_websocket = is_websocket; peer->is_websocket = is_websocket;
#if DEVELOPER
peer->dev_writes_enabled = NULL; peer->dev_writes_enabled = NULL;
peer->dev_read_enabled = true; peer->dev_read_enabled = true;
#endif
peer->to_peer = conn; 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; enum addr_listen_announce *proposed_listen_announce;
struct wireaddr *announceable; struct wireaddr *announceable;
char *tor_password; char *tor_password;
bool dev_fast_gossip; bool dev_disconnect;
bool dev_disconnect, dev_no_ping_timer;
char *errstr; char *errstr;
/* Fields which require allocation are allocated off daemon */ /* 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_helper,
&daemon->websocket_port, &daemon->websocket_port,
&daemon->announce_websocket, &daemon->announce_websocket,
&dev_fast_gossip, &daemon->dev_fast_gossip,
&dev_disconnect, &dev_disconnect,
&dev_no_ping_timer)) { &daemon->dev_no_ping_timer)) {
/* This is a helper which prints the type expected and the actual /* This is a helper which prints the type expected and the actual
* message, then exits (it should never be called!). */ * message, then exits (it should never be called!). */
master_badmsg(WIRE_CONNECTD_INIT, msg); 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)) if (!pubkey_from_node_id(&daemon->mykey, &daemon->id))
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Invalid id for me %s", "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. */ * not always a real problem), and this would (did!) trigger it. */
tal_free(announceable); tal_free(announceable);
#if DEVELOPER
if (dev_disconnect) { if (dev_disconnect) {
daemon->dev_disconnect_fd = 5; daemon->dev_disconnect_fd = 5;
dev_disconnect_init(5); dev_disconnect_init(5);
} else { } else {
daemon->dev_disconnect_fd = -1; daemon->dev_disconnect_fd = -1;
} }
#endif
} }
/* Returning functions in C is ugly! */ /* Returning functions in C is ugly! */
@ -1880,7 +1867,6 @@ static void dev_connect_memleak(struct daemon *daemon, const u8 *msg)
found_leak))); found_leak)));
} }
#if DEVELOPER
static void dev_suppress_gossip(struct daemon *daemon, const u8 *msg) static void dev_suppress_gossip(struct daemon *daemon, const u8 *msg)
{ {
daemon->dev_suppress_gossip = true; 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); status_info("dev_report_fds: %i -> gossipd fd", fd);
continue; continue;
} }
#if DEVELOPER
if (fd == daemon->dev_disconnect_fd) { if (fd == daemon->dev_disconnect_fd) {
status_info("dev_report_fds: %i -> dev_disconnect_fd", fd); status_info("dev_report_fds: %i -> dev_disconnect_fd", fd);
continue; continue;
} }
#endif
if (fd == daemon->gossip_store_fd) { if (fd == daemon->gossip_store_fd) {
status_info("dev_report_fds: %i -> gossip_store", fd); status_info("dev_report_fds: %i -> gossip_store", fd);
continue; continue;
@ -2020,7 +2004,6 @@ static void dev_report_fds(struct daemon *daemon, const u8 *msg)
describe_fd(fd); describe_fd(fd);
} }
} }
#endif /* DEVELOPER */
static struct io_plan *recv_peer_connect_subd(struct io_conn *conn, static struct io_plan *recv_peer_connect_subd(struct io_conn *conn,
const u8 *msg, const u8 *msg,
@ -2088,15 +2071,17 @@ static struct io_plan *recv_req(struct io_conn *conn,
} }
/* Fall thru */ /* Fall thru */
case WIRE_CONNECTD_DEV_SUPPRESS_GOSSIP: case WIRE_CONNECTD_DEV_SUPPRESS_GOSSIP:
#if DEVELOPER if (daemon->developer) {
dev_suppress_gossip(daemon, msg); dev_suppress_gossip(daemon, msg);
goto out; goto out;
#endif }
/* Fall thru */
case WIRE_CONNECTD_DEV_REPORT_FDS: case WIRE_CONNECTD_DEV_REPORT_FDS:
#if DEVELOPER if (daemon->developer) {
dev_report_fds(daemon, msg); dev_report_fds(daemon, msg);
goto out; goto out;
#endif }
/* Fall thru */
/* We send these, we don't receive them */ /* We send these, we don't receive them */
case WIRE_CONNECTD_INIT_REPLY: case WIRE_CONNECTD_INIT_REPLY:
case WIRE_CONNECTD_ACTIVATE_REPLY: case WIRE_CONNECTD_ACTIVATE_REPLY:
@ -2187,6 +2172,7 @@ int main(int argc, char *argv[])
timers_init(&daemon->timers, time_mono()); timers_init(&daemon->timers, time_mono());
daemon->gossip_store_fd = -1; daemon->gossip_store_fd = -1;
daemon->shutting_down = false; daemon->shutting_down = false;
daemon->dev_suppress_gossip = false;
/* stdin == control */ /* stdin == control */
daemon->master = daemon_conn_new(daemon, STDIN_FILENO, recv_req, NULL, daemon->master = daemon_conn_new(daemon, STDIN_FILENO, recv_req, NULL,

View file

@ -90,11 +90,9 @@ struct peer {
/* Last time we received traffic */ /* Last time we received traffic */
struct timeabs last_recv_time; struct timeabs last_recv_time;
#if DEVELOPER
bool dev_read_enabled; bool dev_read_enabled;
/* If non-NULL, this counts down; 0 means disable */ /* If non-NULL, this counts down; 0 means disable */
u32 *dev_writes_enabled; u32 *dev_writes_enabled;
#endif
}; };
/*~ The HTABLE_DEFINE_TYPE() macro needs a keyof() function to extract the key: /*~ The HTABLE_DEFINE_TYPE() macro needs a keyof() function to extract the key:
@ -155,8 +153,7 @@ struct daemon {
/* Any listening sockets we have. */ /* Any listening sockets we have. */
struct io_listener **listeners; struct io_listener **listeners;
/* Allow localhost to be considered "public": DEVELOPER-only option, /* Allow localhost to be considered "public", only with --developer */
* but for simplicity we don't #if DEVELOPER-wrap it here. */
bool dev_allow_localhost; bool dev_allow_localhost;
/* We support use of a SOCKS5 proxy (e.g. Tor) */ /* We support use of a SOCKS5 proxy (e.g. Tor) */
@ -197,7 +194,6 @@ struct daemon {
/* Shutting down, don't send new stuff */ /* Shutting down, don't send new stuff */
bool shutting_down; bool shutting_down;
#if DEVELOPER
/* Hack to speed up gossip timer */ /* Hack to speed up gossip timer */
bool dev_fast_gossip; bool dev_fast_gossip;
/* Hack to avoid ping timeouts */ /* Hack to avoid ping timeouts */
@ -206,7 +202,6 @@ struct daemon {
bool dev_suppress_gossip; bool dev_suppress_gossip;
/* dev_disconnect file */ /* dev_disconnect file */
int dev_disconnect_fd; int dev_disconnect_fd;
#endif
}; };
/* Called by io_tor_connect once it has a connection out. */ /* Called by io_tor_connect once it has a connection out. */

View file

@ -273,7 +273,7 @@ void setup_peer_gossip_store(struct peer *peer,
} }
peer->gs.gossip_timer = gossip_stream_timer(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_min = 0;
peer->gs.timestamp_max = UINT32_MAX; 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), if (setsockopt(io_conn_fd(peer->to_peer),
IPPROTO_TCP, opt, &val, sizeof(val)) != 0 IPPROTO_TCP, opt, &val, sizeof(val)) != 0
/* This actually happens in testing, where we blackhole the fd */ /* 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", status_broken("setsockopt %s=1 fd=%u: %s",
optname, io_conn_fd(peer->to_peer), optname, io_conn_fd(peer->to_peer),
strerror(errno)); strerror(errno));
@ -421,7 +421,6 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
{ {
int type = fromwire_peektype(msg); int type = fromwire_peektype(msg);
#if DEVELOPER
switch (dev_disconnect(&peer->id, type)) { switch (dev_disconnect(&peer->id, type)) {
case DEV_DISCONNECT_BEFORE: case DEV_DISCONNECT_BEFORE:
if (taken(msg)) if (taken(msg))
@ -445,7 +444,7 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
*peer->dev_writes_enabled = 1; *peer->dev_writes_enabled = 1;
break; break;
} }
#endif
set_urgent_flag(peer, is_urgent(type)); set_urgent_flag(peer, is_urgent(type));
/* We are no longer required to do this, but we do disconnect /* 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) static void wake_gossip(struct peer *peer)
{ {
bool flush_gossip_filter = true; bool flush_gossip_filter = true;
#if DEVELOPER
/* With dev-fast-gossip, we clean every 2 seconds, which is too /* 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 * fast for our slow tests! So we only call this one time in 5
* actually twice that, as it's not per-peer! */ * 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) if (peer->daemon->dev_fast_gossip && gossip_age_count++ % 5 != 0)
flush_gossip_filter = false; flush_gossip_filter = false;
#endif
/* Don't remember sent per-peer gossip forever. */ /* Don't remember sent per-peer gossip forever. */
if (flush_gossip_filter) if (flush_gossip_filter)
gossip_rcvd_filter_age(peer->gs.grf); 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); io_wake(peer->peer_outq);
/* And go again in 60 seconds (from now, now when we finish!) */ /* 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; u8 *msg;
/* dev-mode can suppress all gossip */ /* dev-mode can suppress all gossip */
if (IFDEV(peer->daemon->dev_suppress_gossip, false)) if (peer->daemon->dev_suppress_gossip)
return NULL; return NULL;
/* Not streaming right now? */ /* Not streaming right now? */
@ -535,7 +531,7 @@ static void send_ping(struct peer *peer);
static void set_ping_timer(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; peer->ping_timer = NULL;
return; return;
} }
@ -963,7 +959,6 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn,
} }
/* dev_disconnect can disable writes */ /* dev_disconnect can disable writes */
#if DEVELOPER
if (peer->dev_writes_enabled) { if (peer->dev_writes_enabled) {
if (*peer->dev_writes_enabled == 0) { if (*peer->dev_writes_enabled == 0) {
tal_free(msg); tal_free(msg);
@ -972,7 +967,6 @@ static struct io_plan *write_to_peer(struct io_conn *peer_conn,
} }
(*peer->dev_writes_enabled)--; (*peer->dev_writes_enabled)--;
} }
#endif
return encrypt_and_send(peer, take(msg), write_to_peer); 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); tal_free(peer->peer_in);
/* dev_disconnect can disable read */ /* 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); return read_hdr_from_peer(peer_conn, peer);
/* We got something! */ /* We got something! */

View file

@ -110,8 +110,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
case ADDR_TYPE_IPV6: case ADDR_TYPE_IPV6:
/* Drop non-public addresses when not testing */ /* Drop non-public addresses when not testing */
if (!address_routable(remote_addr, if (!address_routable(remote_addr,
IFDEV(peer->daemon->dev_allow_localhost, peer->daemon->dev_allow_localhost))
false)))
remote_addr = tal_free(remote_addr); remote_addr = tal_free(remote_addr);
break; break;
/* We are only interested in IP addresses */ /* 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); peer_init_hdr_received, peer);
} }
#if DEVELOPER static struct io_plan *dev_peer_write_postclose(struct io_conn *conn,
static struct io_plan *peer_write_postclose(struct io_conn *conn, struct early_peer *peer)
struct early_peer *peer)
{ {
dev_sabotage_fd(io_conn_fd(conn), true); dev_sabotage_fd(io_conn_fd(conn), true);
return read_init(conn, peer); return read_init(conn, peer);
} }
static struct io_plan *peer_write_post_sabotage(struct io_conn *conn, static struct io_plan *dev_peer_write_post_sabotage(struct io_conn *conn,
struct early_peer *peer) struct early_peer *peer)
{ {
dev_sabotage_fd(io_conn_fd(conn), false); dev_sabotage_fd(io_conn_fd(conn), false);
return read_init(conn, peer); return read_init(conn, peer);
} }
#endif
struct io_plan *peer_exchange_initmsg(struct io_conn *conn, struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
struct daemon *daemon, 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)); peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));
next = read_init; next = read_init;
#if DEVELOPER
switch (dev_disconnect(&peer->id, WIRE_INIT)) { switch (dev_disconnect(&peer->id, WIRE_INIT)) {
case DEV_DISCONNECT_BEFORE: case DEV_DISCONNECT_BEFORE:
dev_sabotage_fd(io_conn_fd(conn), true); dev_sabotage_fd(io_conn_fd(conn), true);
break; break;
case DEV_DISCONNECT_AFTER: case DEV_DISCONNECT_AFTER:
next = peer_write_postclose; next = dev_peer_write_postclose;
break; break;
case DEV_DISCONNECT_BLACKHOLE: case DEV_DISCONNECT_BLACKHOLE:
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
@ -294,10 +290,9 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
case DEV_DISCONNECT_NORMAL: case DEV_DISCONNECT_NORMAL:
break; break;
case DEV_DISCONNECT_DISABLE_AFTER: case DEV_DISCONNECT_DISABLE_AFTER:
next = peer_write_post_sabotage; next = dev_peer_write_post_sabotage;
break; break;
} }
#endif /* DEVELOPER */
return io_write(conn, peer->msg, tal_bytelen(peer->msg), next, peer); return io_write(conn, peer->msg, tal_bytelen(peer->msg), next, peer);
} }