diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index cdbe297fe..634073004 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -151,6 +152,11 @@ void peer_fail_transient(struct peer *peer, const char *fmt, ...) logv_add(peer->log, fmt, ap); va_end(ap); + if (dev_disconnect_permanent(peer->ld)) { + peer_internal_error(peer, "dev_disconnect permfail"); + return; + } + peer->owner = NULL; /* If we haven't reached awaiting locked, we don't need to reconnect */ diff --git a/lightningd/subd.c b/lightningd/subd.c index e52a03006..0fe43282e 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -510,3 +511,20 @@ char *opt_subd_dev_disconnect(const char *optarg, struct lightningd *ld) optarg, strerror(errno)); return NULL; } + +/* If test specified that this disconnection should cause permanent failure */ +bool dev_disconnect_permanent(struct lightningd *ld) +{ + char permfail[strlen("PERMFAIL")]; + int r; + + if (ld->dev_disconnect_fd == -1) + return false; + + r = read(ld->dev_disconnect_fd, permfail, sizeof(permfail)); + if (r < 0) + fatal("Reading dev_disconnect file: %s", strerror(errno)); + lseek(ld->dev_disconnect_fd, -r, SEEK_CUR); + + return memeq(permfail, r, "permfail", strlen("permfail")); +} diff --git a/lightningd/subd.h b/lightningd/subd.h index 2f12ce76b..3f6705c43 100644 --- a/lightningd/subd.h +++ b/lightningd/subd.h @@ -135,4 +135,6 @@ void subd_shutdown(struct subd *subd, unsigned int seconds); char *opt_subd_debug(const char *optarg, struct lightningd *ld); char *opt_subd_dev_disconnect(const char *optarg, struct lightningd *ld); + +bool dev_disconnect_permanent(struct lightningd *ld); #endif /* LIGHTNING_LIGHTNINGD_SUBD_H */