mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-09 08:04:19 +01:00
connectd: do dev_disconnect logic.
As connectd handles more packets itself, or diverts them to/from gossipd, it's the only place we can implement the dev_disconnect logic. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -51,7 +51,7 @@ void dev_disconnect_init(int fd)
|
||||
dev_disconnect_fd = fd;
|
||||
}
|
||||
|
||||
enum dev_disconnect dev_disconnect(int pkt_type)
|
||||
enum dev_disconnect dev_disconnect(const struct node_id *id, int pkt_type)
|
||||
{
|
||||
if (dev_disconnect_fd == -1)
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
@@ -59,7 +59,8 @@ enum dev_disconnect dev_disconnect(int pkt_type)
|
||||
if (!dev_disconnect_count)
|
||||
next_dev_disconnect();
|
||||
|
||||
if (!streq(peer_wire_name(pkt_type), dev_disconnect_line+1))
|
||||
if (!dev_disconnect_line[0]
|
||||
|| !streq(peer_wire_name(pkt_type), dev_disconnect_line+1))
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
|
||||
if (--dev_disconnect_count != 0) {
|
||||
@@ -70,7 +71,8 @@ enum dev_disconnect dev_disconnect(int pkt_type)
|
||||
err(1, "lseek failure");
|
||||
}
|
||||
|
||||
status_debug("dev_disconnect: %s", dev_disconnect_line);
|
||||
status_peer_debug(id, "dev_disconnect: %s (%s)", dev_disconnect_line,
|
||||
peer_wire_name(pkt_type));
|
||||
return dev_disconnect_line[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#if DEVELOPER
|
||||
struct node_id;
|
||||
|
||||
enum dev_disconnect {
|
||||
/* Do nothing. */
|
||||
DEV_DISCONNECT_NORMAL = '=',
|
||||
@@ -18,7 +20,7 @@ enum dev_disconnect {
|
||||
};
|
||||
|
||||
/* Force a close fd before or after a certain packet type */
|
||||
enum dev_disconnect dev_disconnect(int pkt_type);
|
||||
enum dev_disconnect dev_disconnect(const struct node_id *id, int pkt_type);
|
||||
|
||||
/* Make next write on fd fail as if they'd disconnected. */
|
||||
void dev_sabotage_fd(int fd, bool close_fd);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "config.h"
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
#include <common/cryptomsg.h>
|
||||
#include <common/dev_disconnect.h>
|
||||
#include <common/peer_failed.h>
|
||||
#include <common/peer_io.h>
|
||||
#include <common/per_peer_state.h>
|
||||
@@ -17,40 +16,10 @@
|
||||
|
||||
void peer_write(struct per_peer_state *pps, const void *msg TAKES)
|
||||
{
|
||||
#if DEVELOPER
|
||||
bool post_sabotage = false, post_close;
|
||||
int type = fromwire_peektype(msg);
|
||||
#endif
|
||||
|
||||
status_peer_io(LOG_IO_OUT, NULL, msg);
|
||||
|
||||
#if DEVELOPER
|
||||
switch (dev_disconnect(type)) {
|
||||
case DEV_DISCONNECT_BEFORE:
|
||||
dev_sabotage_fd(pps->peer_fd, true);
|
||||
peer_failed_connection_lost();
|
||||
case DEV_DISCONNECT_AFTER:
|
||||
post_sabotage = true;
|
||||
post_close = true;
|
||||
break;
|
||||
case DEV_DISCONNECT_BLACKHOLE:
|
||||
dev_blackhole_fd(pps->peer_fd);
|
||||
break;
|
||||
case DEV_DISCONNECT_NORMAL:
|
||||
break;
|
||||
case DEV_DISCONNECT_DISABLE_AFTER:
|
||||
post_sabotage = true;
|
||||
post_close = false;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (!wire_sync_write(pps->peer_fd, msg))
|
||||
peer_failed_connection_lost();
|
||||
|
||||
#if DEVELOPER
|
||||
if (post_sabotage)
|
||||
dev_sabotage_fd(pps->peer_fd, post_close);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We're happy for the kernel to batch update and gossip messages, but a
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "config.h"
|
||||
#include <common/dev_disconnect.h>
|
||||
#include <common/status.h>
|
||||
#include <common/subdaemon.h>
|
||||
#include <common/version.h>
|
||||
@@ -33,14 +32,5 @@ void subdaemon_setup(int argc, char *argv[])
|
||||
|
||||
daemon_maybe_debug(argv);
|
||||
|
||||
#if DEVELOPER
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strstarts(argv[i], "--dev-disconnect=")) {
|
||||
dev_disconnect_init(atoi(argv[i]
|
||||
+ strlen("--dev-disconnect=")));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
daemon_setup(argv[0], status_backtrace_print, status_backtrace_exit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user